vb.net - IsNumeric 语句和范围
问题描述
大家好,我正在执行一项任务,我必须验证用户输入数据。当问我的导师我是否可以使用 IsNumeric 来验证两个数字之间的范围时,他只是说可以,并没有告诉我如何。现在我知道您可以使用 if statements 进行验证,并且我有几个使用基本的方法:
if hours < 0 then
Messagebox("Please enter a value greater than 0" "Input Value to
low" messagebox.buttons retry/cancel) ''something like that
Elseif hours > 23 then
Messagebox( "please enter a value less than 23" "Input Value to
high" messagebox.buttons retry/cancel)
End if
我什至问他是否可以在 if 语句中使用 AND 来确定数据范围。再次是的,没有例子
我想到的例子
If hours < 0 AND hours > 23 then
'' continue processing
Else
Messagebox("Please enter a Value between 0 and 23" "Input
value
out of range" messagebox.buttons retry/cancel)
End if
解决方案
针对您的示例,您可以尝试以下操作:
If isnumeric(hours) then
If hours < 0 AND hours > 23 then
'' continue processing
Else
MessageBox.Show("Input value out of range",
"Please enter a Value between 0 and 23",
MessageBoxButtons.RetryCancel)
End if
End if
推荐阅读
- r - 我想计算密度的最大似然估计,但是当数学上我的方程正确时,我的输出会产生 NaN
- css - 如何在具有多个项目的弹性框中将单个项目居中?
- node.js - API错误代码Nodejs
- java - 我如何让 textarea 返回一个字符串数组列表,而不仅仅是一个字符串
- android - 如何在 kotlin 上自定义 toggleButton
- c# - Application.exe + 000000 读取内存
- php - Laravel - 根据单词数组的出现对查询进行排序
- apache-spark - AnalysisException:必须使用 writeStream.start() 执行带有流源的查询
- c# - 在 UWP 应用程序中使用 TextBox 时是否可以重新编程 Tab 键的功能?
- javascript - GitHub 页面:加载 .csv 文件时出现 404 错误