比较具有相似数值的字符串值(重新发布) [英] Comparing a string value with similar numeric values (repost)

查看:60
本文介绍了比较具有相似数值的字符串值(重新发布)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在这里有一个代码:

OK, I have a code here:

If TextBox1.Text = Label1.Text Then
            MsgBox("Congrats")
        End If



并假设label1.text为87,如果textbox1中的文本为86或88,我如何将其弹出到仍弹出消息的地方?



And lets say label1.text says 87, how would I make it to where the message would still pop up if the text in textbox1 said 86 or 88?

推荐答案

您已经问了好几天了.我知道我已经告诉过你答案了.为什么要再问一次?
You have been asking this for days. I know I told you the answer already. Why are you asking it again ?


要重申我的回答:

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

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

因为您已经开始比较int,所以需要int.TryParse,但其余部分完全相同.将您的文本转换为整数,比较运算符将为您工作,以检查值是否在范围内
To reiterate my answer:

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.

Because you''ve moved to comparing an int, you want int.TryParse, but the rest is exactly the same. Turn your text into an int and the comparison operators will work for you to check if a value is within a range


这篇关于比较具有相似数值的字符串值(重新发布)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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