只允许文本框中的数值 [英] Only allow numeric values in the textbox

查看:19
本文介绍了只允许文本框中的数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个只接受数值的TextBox控件.

I want to make a TextBox control that only accepts numerical values.

如何在 VB6 中做到这一点?

How can I do this in VB6?

推荐答案

在文本框文本Change事件中,检查输入的值是否为数字.如果不是数字,则重新设置旧值.

In the text box text Change event, check if the entered value is a number. If it's not a number then set the old value back again.

Dim textval As String
Dim numval As String

Private Sub TextBox1_Change()
  textval = TextBox1.Text
  If IsNumeric(textval) Then
    numval = textval
  Else
    TextBox1.Text = CStr(numval)
  End If
End Sub

这篇关于只允许文本框中的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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