timer IBOutlet disappears. probably very simple
When I run this code, the difference between the datePicker selection and
the current real time is displayed through an IBOutlet in the form
"dd:hh:mm:ss". I have set up an IBAction button to initiate a timer
countdown from the displayed time in the IBOutlet label but when I tap on
the button to start the timer, the label that displays the timer
disappears. thanks!
@synthesize picker; @synthesize label;
-(IBAction)startTimer:(id)sender{
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(refreshLabel)
userInfo:nil
repeats:YES];
}
-(IBAction)displayDate:(id)sender {
NSDate *todaysDate = [NSDate date];
NSDate *selected = [picker date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSDayCalendarUnit |NSMinuteCalendarUnit |
NSHourCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *dateComparisonComponents = [gregorian
components:unitFlags
fromDate:todaysDate
toDate:selected
options:NSWrapCalendarComponents];
NSInteger days = [dateComparisonComponents day];
NSInteger hours = [dateComparisonComponents hour];
NSInteger minutes = [dateComparisonComponents minute];
NSInteger seconds = [dateComparisonComponents second];
self.label.text = [NSString
stringWithFormat:@"%ld:%02ld:%02ld:%02ld",
(long)days,
(long)hours,
(long)minutes,
(long)seconds];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSDate *now = [NSDate date];
[picker setDate:now animated:YES];
self.label.text = [now description];
self.now = [NSDate date];
self.label.text = [self.formatter stringFromDate:self.now];
}
-(void)refreshLabel
{
NSDate *selected = [NSDate dateWithTimeIntervalSince1970:[[picker
date] timeIntervalSince1970] - 1];
[picker setDate:selected animated:YES];
self.label.text = [self.formatter stringFromDate:selected];
}
@end
Bustillo
Sunday, 1 September 2013
Saturday, 31 August 2013
get surface width in angle game engine
get surface width in angle game engine
how can i get width of surface (mGLSurfaceView) in angle android game engine?
i tried mGLSurfaceView.getWidth() but it return 0!!!
what should i use?
any help appreciated !
how can i get width of surface (mGLSurfaceView) in angle android game engine?
i tried mGLSurfaceView.getWidth() but it return 0!!!
what should i use?
any help appreciated !
How do I set values inside a global, fixed-size array, in C (in Visual Studio)?
How do I set values inside a global, fixed-size array, in C (in Visual
Studio)?
A part of my VS2012 Windows Phone project is in C. I've been struggling
during one day trying to initialize an array to put stuff inside it.
Whenever I try to initialize it as global (outside any function), then I
get a message telling me that I can't initialize it with a value that
isn't a const.
const char* myArray = (const char*)malloc(256);
// Bad code: this isn't initialized with a const
If I don't initialize it with a value, then I'll have a message telling me
to give it a value. So I assign a NULL value to the array.
const char* myArray = NULL;
Then I need to set a size somewhere, so I set the size within my main, or
first function:
int myFirstFunctionInTheCode()
{
myArray = (char*)malloc(256);
}
Then I get something like: ';' expected before type
So I'm searching on forum and read that C in Visual Studio is C89, thus, I
need to declare then to assign on two separate line, which isn't true
elsewhere in my code, so I'm completely mixed-up about -real- standards.
But I still get the same error when doing it on two lines.
I then decide to use some other tools from the available VS libraries to
find out that in C, I can't include sstream, streambuf, etc, otherwise my
whole project fails with thousands of bugs. So I could use boost to get a
real stream libraries, but it's not compatible with Windows Phone because
of some thread usage.
How do I set values inside a global, fixed-size array, in C (in Visual
Studio)?
What I want to achieve is similar to something in C# like it:
static byte[] gentleCSharpArray = new byte[256];
private void easyShotCSharpFunction()
{
gentleCSharpArray[0] = 0x57;
gentleCSharpArray[1] = 0x54;
gentleCSharpArray[2] = 0x46;
}
I never spent so much time trying to assign a value to an array, so I
guess I'm totally wrong with my global char* arrays?
Studio)?
A part of my VS2012 Windows Phone project is in C. I've been struggling
during one day trying to initialize an array to put stuff inside it.
Whenever I try to initialize it as global (outside any function), then I
get a message telling me that I can't initialize it with a value that
isn't a const.
const char* myArray = (const char*)malloc(256);
// Bad code: this isn't initialized with a const
If I don't initialize it with a value, then I'll have a message telling me
to give it a value. So I assign a NULL value to the array.
const char* myArray = NULL;
Then I need to set a size somewhere, so I set the size within my main, or
first function:
int myFirstFunctionInTheCode()
{
myArray = (char*)malloc(256);
}
Then I get something like: ';' expected before type
So I'm searching on forum and read that C in Visual Studio is C89, thus, I
need to declare then to assign on two separate line, which isn't true
elsewhere in my code, so I'm completely mixed-up about -real- standards.
But I still get the same error when doing it on two lines.
I then decide to use some other tools from the available VS libraries to
find out that in C, I can't include sstream, streambuf, etc, otherwise my
whole project fails with thousands of bugs. So I could use boost to get a
real stream libraries, but it's not compatible with Windows Phone because
of some thread usage.
How do I set values inside a global, fixed-size array, in C (in Visual
Studio)?
What I want to achieve is similar to something in C# like it:
static byte[] gentleCSharpArray = new byte[256];
private void easyShotCSharpFunction()
{
gentleCSharpArray[0] = 0x57;
gentleCSharpArray[1] = 0x54;
gentleCSharpArray[2] = 0x46;
}
I never spent so much time trying to assign a value to an array, so I
guess I'm totally wrong with my global char* arrays?
Can mysql import a csv or other txt file into one column?
Can mysql import a csv or other txt file into one column?
In mysql we can import data files -
load data infile 'file.txt'
into table `text`
fields terminated ' '
lines terminated '\n'
My question is can we import a file with unknown columns all into one
column? Or possibly can we create columns that we need on the fly?
In mysql we can import data files -
load data infile 'file.txt'
into table `text`
fields terminated ' '
lines terminated '\n'
My question is can we import a file with unknown columns all into one
column? Or possibly can we create columns that we need on the fly?
Delete Function from List
Delete Function from List
I'm having trouble implementing the delete function, any help would be
appreciated. I have a list called memberlist that stores the persons name
and number. I have everything working except the delete function. Any help
would be appreciated.
public class Person
{
private string name;
private string phoneNumber;
public string Name
{
set { name = value; }
get { return name; }
}
public string PhoneNumber
{
set { phoneNumber = value; }
get { return phoneNumber; }
}
public void PrintInfo()
{
Console.WriteLine();
Console.WriteLine(" Name: {0}", name);
Console.WriteLine(" Phone Number: {0}", phoneNumber);
Console.WriteLine();
}
public void SaveASCII(ref StreamWriter output)
{
output.WriteLine(name);
output.WriteLine(phoneNumber);
}
public void LoadASCII(ref StreamReader input)
{
name = input.ReadLine();
phoneNumber = input.ReadLine();
}
}
public class membershipList
{
public Person[] ML = null;
public void AddMember(Person p)
{
if (ML == null)
{
ML = new Person[1];
ML[0] = p;
}
else
{
Person[] temp = ML;
ML = new Person[temp.Length + 1];
for (int i = 0; i < temp.Length; ++i)
{
ML[i] = new Person();
ML[i] = temp[i];
}
ML[temp.Length] = new Person();
ML[temp.Length] = p;
temp = null;
}
}
public void DeleteMember(string name)
{
if (ML == null)
{
Console.WriteLine(name + " had not been added before.");
}
else
{
int memberIndex = ML.MembershipList().FindIndex(p => p.Name ==
name);
if (memberIndex = -1)
{
Console.WriteLine(name + " had not been added before.");
return;
}
List<Person> tmp = new List<Person>(ML);
tmp.RemoveAt(memberIndex);
ML = tmp.ToArray();
}
}
public void PrintAll()
{
if (ML != null)
foreach (Person pers in ML)
pers.PrintInfo();
else Console.WriteLine("Then list is empty");
}
public void Search(string p)
{
if (ML != null)
{
foreach (Person pers in ML)
{
if (pers.Name.ToLower().CompareTo(p.ToLower()) == 0)
{
Console.WriteLine("1 Record Found:");
pers.PrintInfo();
break;
}
}
Console.WriteLine("Record not found.");
}
else Console.WriteLine("Then list is empty.");
}
public void ReadASCIIFile()
{
StreamReader input = new StreamReader("memberlist.dat"); ;
try
{
int num = Convert.ToInt32(input.ReadLine());
ML = new Person[num];
for (int i = 0; i < num; ++i)
{
ML[i] = new Person();
ML[i].LoadASCII(ref input);
}
input.Close();
}
catch (FormatException e)
{
Console.WriteLine(e.Message);
input.Close();
}
}
public void SaveASCIIFile()
{
StreamWriter output = new StreamWriter("memberlist.dat");
output.WriteLine(ML.Length);
foreach (Person pers in ML)
{
pers.SaveASCII(ref output);
}
output.Close();
}
}
class Program
{
static void Main(string[] args)
{
membershipList ML = new membershipList();
ML.ReadASCIIFile();
string option;
do
{
// Console.Clear();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("MemberShip List MENU");
Console.WriteLine();
Console.WriteLine(" a. Add");
Console.WriteLine(" b. Seach");
Console.WriteLine(" c. Delete");
Console.WriteLine(" d. Print All");
Console.WriteLine(" e. Exit");
Console.WriteLine();
Console.Write("option: ");
option = Console.ReadLine().ToLower();
switch (option)
{
case "a":
Person np = new Person();
Console.Write("Enter Name: ");
np.Name = Console.ReadLine();
Console.Write("Enter PhoneNumber: ");
np.PhoneNumber = Console.ReadLine();
ML.AddMember(np);
break;
case "b":
Console.Write("Enter Name: ");
string name = Console.ReadLine();
ML.Search(name);
break;
case "c":
Console.Write("Enter Name to be Deleted:");
ML.DeleteMember(name);
break;
case "d":
ML.PrintAll();
break;
case "e":
ML.SaveASCIIFile();
Console.WriteLine("BYE...... ");
break;
default:
Console.WriteLine("Invalid Option");
break;
}
} while (option.ToLower() != "d");
}
}
I'm having trouble implementing the delete function, any help would be
appreciated. I have a list called memberlist that stores the persons name
and number. I have everything working except the delete function. Any help
would be appreciated.
public class Person
{
private string name;
private string phoneNumber;
public string Name
{
set { name = value; }
get { return name; }
}
public string PhoneNumber
{
set { phoneNumber = value; }
get { return phoneNumber; }
}
public void PrintInfo()
{
Console.WriteLine();
Console.WriteLine(" Name: {0}", name);
Console.WriteLine(" Phone Number: {0}", phoneNumber);
Console.WriteLine();
}
public void SaveASCII(ref StreamWriter output)
{
output.WriteLine(name);
output.WriteLine(phoneNumber);
}
public void LoadASCII(ref StreamReader input)
{
name = input.ReadLine();
phoneNumber = input.ReadLine();
}
}
public class membershipList
{
public Person[] ML = null;
public void AddMember(Person p)
{
if (ML == null)
{
ML = new Person[1];
ML[0] = p;
}
else
{
Person[] temp = ML;
ML = new Person[temp.Length + 1];
for (int i = 0; i < temp.Length; ++i)
{
ML[i] = new Person();
ML[i] = temp[i];
}
ML[temp.Length] = new Person();
ML[temp.Length] = p;
temp = null;
}
}
public void DeleteMember(string name)
{
if (ML == null)
{
Console.WriteLine(name + " had not been added before.");
}
else
{
int memberIndex = ML.MembershipList().FindIndex(p => p.Name ==
name);
if (memberIndex = -1)
{
Console.WriteLine(name + " had not been added before.");
return;
}
List<Person> tmp = new List<Person>(ML);
tmp.RemoveAt(memberIndex);
ML = tmp.ToArray();
}
}
public void PrintAll()
{
if (ML != null)
foreach (Person pers in ML)
pers.PrintInfo();
else Console.WriteLine("Then list is empty");
}
public void Search(string p)
{
if (ML != null)
{
foreach (Person pers in ML)
{
if (pers.Name.ToLower().CompareTo(p.ToLower()) == 0)
{
Console.WriteLine("1 Record Found:");
pers.PrintInfo();
break;
}
}
Console.WriteLine("Record not found.");
}
else Console.WriteLine("Then list is empty.");
}
public void ReadASCIIFile()
{
StreamReader input = new StreamReader("memberlist.dat"); ;
try
{
int num = Convert.ToInt32(input.ReadLine());
ML = new Person[num];
for (int i = 0; i < num; ++i)
{
ML[i] = new Person();
ML[i].LoadASCII(ref input);
}
input.Close();
}
catch (FormatException e)
{
Console.WriteLine(e.Message);
input.Close();
}
}
public void SaveASCIIFile()
{
StreamWriter output = new StreamWriter("memberlist.dat");
output.WriteLine(ML.Length);
foreach (Person pers in ML)
{
pers.SaveASCII(ref output);
}
output.Close();
}
}
class Program
{
static void Main(string[] args)
{
membershipList ML = new membershipList();
ML.ReadASCIIFile();
string option;
do
{
// Console.Clear();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("MemberShip List MENU");
Console.WriteLine();
Console.WriteLine(" a. Add");
Console.WriteLine(" b. Seach");
Console.WriteLine(" c. Delete");
Console.WriteLine(" d. Print All");
Console.WriteLine(" e. Exit");
Console.WriteLine();
Console.Write("option: ");
option = Console.ReadLine().ToLower();
switch (option)
{
case "a":
Person np = new Person();
Console.Write("Enter Name: ");
np.Name = Console.ReadLine();
Console.Write("Enter PhoneNumber: ");
np.PhoneNumber = Console.ReadLine();
ML.AddMember(np);
break;
case "b":
Console.Write("Enter Name: ");
string name = Console.ReadLine();
ML.Search(name);
break;
case "c":
Console.Write("Enter Name to be Deleted:");
ML.DeleteMember(name);
break;
case "d":
ML.PrintAll();
break;
case "e":
ML.SaveASCIIFile();
Console.WriteLine("BYE...... ");
break;
default:
Console.WriteLine("Invalid Option");
break;
}
} while (option.ToLower() != "d");
}
}
Accessing data from an Arraylist stored in an Arraylist - Java
Accessing data from an Arraylist stored in an Arraylist - Java
I'm trying to access data from an Arraylist that is stored in an
Arraylist. I'm sure there is a really easy way to do this and I don't want
to waste anyone's time but I've tried lots of ways and can't seem to find
the answer anywhere. Any help would be really appreciated.
This is my code for creating the Arrays.
public ArrayList SGenresMaster = new ArrayList(new ArrayList());
public ArrayList S1Genres = new ArrayList();
public ArrayList S2Genres = new ArrayList();
public ArrayList S3Genres = new ArrayList();
public void accessArrays(){
SGenresMaster.add(S1Genres);
SGenresMaster.add(S2Genres);
SGenresMaster.add(S3Genres);
}
Basically i need to be able to access any index of S1Genres using
SgenresMaster.
So far I've only managed to get the data out as a long string so I thought
I'd post my current method for getting the data I need, as i thought it
would probably make the pro's here cringe/laugh.
createarray(SGenresMaster.get(i).toString());
public ArrayList createarray(String string){
String sentence = string;
String[] words = sentence.split(", ");
ArrayList temp = new ArrayList();
int b = 0;
for (String word : words)
{
if (b == 0){
//Delete First bracket
temp.add(word.substring(1,word.length()));
System.out.println("First Word: " + temp);
}
else{
temp.add(word.substring(0,word.length()));
System.out.println("Middle Word: " + temp);
}
b++;
}
//Delete last bracket
String h = String.valueOf(temp.get(temp.size() - 1));
temp.add(h.substring(0,h.length() - 1));
temp.remove(temp.size() - 2);
System.out.println("final:" + temp);
return temp;
}
I'm trying to access data from an Arraylist that is stored in an
Arraylist. I'm sure there is a really easy way to do this and I don't want
to waste anyone's time but I've tried lots of ways and can't seem to find
the answer anywhere. Any help would be really appreciated.
This is my code for creating the Arrays.
public ArrayList SGenresMaster = new ArrayList(new ArrayList());
public ArrayList S1Genres = new ArrayList();
public ArrayList S2Genres = new ArrayList();
public ArrayList S3Genres = new ArrayList();
public void accessArrays(){
SGenresMaster.add(S1Genres);
SGenresMaster.add(S2Genres);
SGenresMaster.add(S3Genres);
}
Basically i need to be able to access any index of S1Genres using
SgenresMaster.
So far I've only managed to get the data out as a long string so I thought
I'd post my current method for getting the data I need, as i thought it
would probably make the pro's here cringe/laugh.
createarray(SGenresMaster.get(i).toString());
public ArrayList createarray(String string){
String sentence = string;
String[] words = sentence.split(", ");
ArrayList temp = new ArrayList();
int b = 0;
for (String word : words)
{
if (b == 0){
//Delete First bracket
temp.add(word.substring(1,word.length()));
System.out.println("First Word: " + temp);
}
else{
temp.add(word.substring(0,word.length()));
System.out.println("Middle Word: " + temp);
}
b++;
}
//Delete last bracket
String h = String.valueOf(temp.get(temp.size() - 1));
temp.add(h.substring(0,h.length() - 1));
temp.remove(temp.size() - 2);
System.out.println("final:" + temp);
return temp;
}
Select the first N *groups* using mysql
Select the first N *groups* using mysql
To make it simple, let say I have a table with 2 fields - PERSON_NAME and
COMPANY_ID with those pairs: ('a',1) ('b',1) ('c',2) ('d',2) ('e',3)
PERSON_NAME a and b are working in COMPANY_ID 1 and so on.
I would like to select all rows for the first 2 (or N) COMPANIES - ('a',1)
('b',1) ('c',2) ('d',2)
I don't know how many rows there are for each COMPANY_ID.
Group by won't work here as I need all rows within each COMPANY_ID.
This one works -
SELECT * FROM T
WHERE COMPANY_ID in (SELECT DISTINCT COMPANY_ID
FROM T
ORDER BY 1 DESC
LIMIT N)
But since performance is an issue, it won't suffice (there are about 25k
companies and about 5-15 persons in each company). N is usually 500.
To make it simple, let say I have a table with 2 fields - PERSON_NAME and
COMPANY_ID with those pairs: ('a',1) ('b',1) ('c',2) ('d',2) ('e',3)
PERSON_NAME a and b are working in COMPANY_ID 1 and so on.
I would like to select all rows for the first 2 (or N) COMPANIES - ('a',1)
('b',1) ('c',2) ('d',2)
I don't know how many rows there are for each COMPANY_ID.
Group by won't work here as I need all rows within each COMPANY_ID.
This one works -
SELECT * FROM T
WHERE COMPANY_ID in (SELECT DISTINCT COMPANY_ID
FROM T
ORDER BY 1 DESC
LIMIT N)
But since performance is an issue, it won't suffice (there are about 25k
companies and about 5-15 persons in each company). N is usually 500.
Subscribe to:
Comments (Atom)