有关VB代码的帮助 [英] Help with a VB code

查看:80
本文介绍了有关VB代码的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在做游戏,几乎你需要猜测时间.
听起来很简单,很无聊,但是我正在使它变得有趣.这是我到目前为止的代码.



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)*

推荐答案

您想要做的是将您的时间存储为DateTime,然后尝试将文本框中的文本转换为日期时间.然后,您可以使用比较运算符查看用户的亲密程度,并确定让他们获胜的保证金,并告诉他们是否高于或低于.我不确定这会是多么有趣,但是如果您要自学VB,那肯定是一个有效的练习.

我不确定是否有DateTime.TryParse或Convert.ToDateTime.如果此人输入的是非日期时间,请确保确保您的代码能够处理.更糟糕的情况是,您可以使用字符串类或正则表达式上的方法将字符串拆分为数字,然后使用int.Parse获取可以传递给DateTime构造函数的数字.
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.


您能做那一小部分吗?这对我来说没有任何意义,当我看到它时,我就可以对其进行解释.
Can you just do that small part. that means nothing to me, when I see it, I can interperate it.


这篇关于有关VB代码的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆