Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
OK, I am making a game, pretty much you need to guess the time.
Sounds easy, and boring, but I am making it fun. This is the code I have so far.



If TextBox1.Text = TimeOfDay Then
MsgBox("Correct!", 0 + 0, "You Win!")
End If


*(Read my comment to find question)*
Posted
Updated 25-Aug-10 1:36am
v3
Comments
Dalek Dave 25-Aug-10 6:56am    
Minor Edit for Code Block and to remove about three of the PRETTY MUCHes :)
Richard MacCutchan 25-Aug-10 7:04am    
So what is your question?
jerryg225 25-Aug-10 7:34am    
Oh, thanks, the best way to ask the question is in an example.

OK, say the time is 3:34:56 AM

What your goal is to type in 3:34:56 AM (sounds easy, but not as easy as it sounds)
but if you say 3:34:55 or 3:34:57 AM then the message still pops up...
Richard MacCutchan 25-Aug-10 7:55am    
Well that sounds easy enough, just compare the guess to the current time and if the difference is less than 2 or 3 seconds the message pops up.
Dylan Morley 25-Aug-10 9:48am    
Dunno if this game would drag me away from Call of Duty

What you want to do, is to store your time as a DateTime, then try to convert the text in the textbox to a datetime. Then you can use comparison operators to see how close the user was, and decide your margin for letting them win, and tell them if they are higher than lower. I'm not sure how this is going to be great fun, but it's certainly a valid exercise if you're teaching yourself VB.

I am not sure if there's a DateTime.TryParse, or a Convert.ToDateTime. Be sure to make sure your code handles if the person has typed in a non datetime. Worse case, you can use the methods on the string class, or a regex, to split your string into numbers, and then use int.Parse to get numbers you can pass to a DateTime constructor.
 
Share this answer
 
Comments
jerryg225 25-Aug-10 18:10pm    
Hey, yes, I am am teaching myself VB. lol

Also, you have the right idea at what I am trying to do. I want the margin to be one above and one below the actual number. Any help on that?
jerryg225 25-Aug-10 18:10pm    
Reason for my vote of 3
Has the right idea on track.
Yusuf 25-Aug-10 19:07pm    
Give me a break A**Hole. You asked a question CG gave you detailed answer and you give him 3 because he is in the right idea on track? Why don't you do it yourself then instead of asking for help.
Yusuf 25-Aug-10 19:08pm    
Reason for my vote of 5
Countering a**hole's 3 point. The answer is legitimate and does not deserve that
jerryg225 25-Aug-10 22:21pm    
Well I dont understand him...lol, I dont know much...
Can you just do that small part. that means nothing to me, when I see it, I can interperate it.
 
Share this answer
 
Comments
Christian Graus 25-Aug-10 23:08pm    
PLEASE don't push answer, to ask questions. Perhaps you should sign up for a course or buy a book, if you're really this confused by this task ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900