在vb中检测字母和间距的问题 [英] problem in detecting letters and spacing in vb

查看:79
本文介绍了在vb中检测字母和间距的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是新手,我的编程代码有问题...

i想确保我只能检测正数,而不是字母......检查:abc,ab100,-100,100ab

所有这些都会显示一个消息框无效值

但是在这里我在检测负数-100时遇到问题。以及除数字100ab之外的字母或字符后面的数字。 (这种情况发生在用户意外键入键盘上的字符时)。


同时,如果我键入空格键。一个数字之后的keyborad,例如:100反之亦然,它将允许传递到文本框100。 (没有空间)


我试过修剪功能...


value = trim(text1.text)''to修剪我键入的内容,并显示

''字母和数字

但是这会解决我的间距问题吗?我想更多地了解这个修剪功能,请告诉我更多..(真的很热衷于学习......))


代码如下...

hi everyone, i am a newbie here, and i have a problem in my programming code...
i wanted to make sure that i can only detect positive numbers, and not letters... examles: "abc", "ab100", "-100", "100ab"
all these will display a message box "invalid values"
however here i have a problem in detecting negative numbers "-100" and also a number followed by letters or characters other than numbers "100ab" (this happens when user accidentally keyed a char on keyboard).

at the same time, if i key a "space" of the keyborad after a number, example: "100 " or vice versa, it will allow to be pass to a textbox as "100" (without the space)

i''ve tried trim function...

value = trim(text1.text) ''to trim what i have keyed and jus display the
''letters and numbers
but will this solve my spacing problem??? i wish to know more about this trim function too please do tell me more.. (really keen in learning... :) )

the code is below...

展开 | 选择 | Wrap | 行号

推荐答案

我不知道这是不是你真正想要的......


你可以锁定文本框按键事件,只允许数字解决输入字母的问题,以及 - 否定符号只是纯数字。


我不确定这个尝试搜索i的确切代码t ..

我将在稍后尝试提供代码。

希望这有助于:P
i dont know if this is what you really want..

you could just lock the textbox keypress event to allow only numbers that way it solves the problem of letters being inputted and also the - negative symbol just pure numbers.

im not sure on the exact code of this try searching on it..
i''ll try to provide a code later on.
hope this helped :P


您需要处理文本框的按键事件并捕获keyascii值。
You need to handle the keypress event of the textbox and capture the keyascii values .



i不知道这是不是你真正想要的......


你可以锁定文本框按键事件,只允许这样的数字它解决了输入字母的问题以及 - 负数符号只是纯数字。


我不确定这个尝试搜索它的确切代码..

我稍后会尝试提供代码。

希望这有帮助:P
i dont know if this is what you really want..

you could just lock the textbox keypress event to allow only numbers that way it solves the problem of letters being inputted and also the - negative symbol just pure numbers.

im not sure on the exact code of this try searching on it..
i''ll try to provide a code later on.
hope this helped :P



我想出了这些只允许数字的代码


试试这个:

I came up with these codes that allows only numbers

Try this:

展开 | 选择 | Wrap | 行号


这篇关于在vb中检测字母和间距的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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