vb.net中如何判断在textbox里面的东东是整数 ps:长度为5到10之间

wenjunsu 2009-03-30 04:50:30
RT
经过我的测试 如果通过 就立即给分
...全文
377 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
迈克揉索芙特 2009-03-30
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/6cd3f6w1.aspx

Visual Basic 语言参考
IsNumeric 函数 (Visual Basic)
更新:2007 年 11 月
返回一个 Boolean 值,表示表达式是否可以计算为数字类型。
liudeqing2008 2009-03-30
  • 打赏
  • 举报
回复
这个问题在我初学C#时也是闷了好久,不过后来在学javascript时想明白了!你倒不如这样去实现,定义变量接收文本框中输入的值,然后将其逐个截取其中的字符然后写方法来比较,我的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnCkeck_Click(object sender, EventArgs e)
{
bool noNumber = false;//该变量主要用来方便下边的判断
string num = this.txtInput.Text;
for (int i = 1; i < num.Length;i++ )//下标的循环累加
{
char num1 =Convert.ToChar(num.Substring(i, 1));//循环截取字符串
if ((num1 > 'a' && num1 < 'z'))//判断该文本框中输入的值的每个字符是不是字母
{
noNumber = true;//如果是将Bool赋值为真
break;//同时让其跳出本次循环执行下一次循环
}
else
{
noNumber = false ;//如果不是将Bool赋值为假(当前的验证字符不是字母)
continue;//继续循环
}
}
if (noNumber)//根据bool值来判断该输入文本框中的字符是不是包含字母
{
MessageBox.Show("输入的值包含字母,请删除输入值中的字母!");
}
else {
MessageBox.Show("输入格式正确!谢谢使用!");
}
}
}
}
这样就可以实现判断输入的是不是数字了!
我姓区不姓区 2009-03-30
  • 打赏
  • 举报
回复

Dim i As Int32
If (Int32.TryParse(textBox1.Text, i)) Then
MsgBox("是整数")
End If

FrankyChan 2009-03-30
  • 打赏
  • 举报
回复




Public Function IsInteger(ByVal Value As String) As Boolean

If Value Is Nothing OrElse _
Value.Length < 1 OrElse _
Value.Length > 11 OrElse _
Value.IndexOf("-") > 0 _
Then Return False

Dim iASC As Integer
For Each c As Char In Value
iASC = Asc(c)
If (iASC < 48 OrElse iASC > 57) AndAlso iASC <> 45 Then Return False
Next
Return True
End Function

'调用示范:
IsInteger("01234") '返回True
IsInteger("-1234") '返回True
IsInteger("3.14") '返回False
IsInteger("12-4") '返回False
IsInteger(Nothing) '返回False
IsInteger(String.Empty)'返回False
IsInteger("") '返回False



REF:
http://topic.csdn.net/t/20041023/18/3484683.html

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧