简单的数字控制问题.解决就给分!在线等

karykwan 2004-12-28 04:20:42
要求:

1、textbox组只能录入1-100之问的数字,如果大于100则光标在原位
2、如果是录入是100(只有这个是三位),光标自动跳到下一个textbox,如是是0-99之间的数。则按回车后自动跳到下一个textbox

本人现在急着用VB写个东西,由于VB没有搞过,所以请教各位,解决后就给分。
...全文
149 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
maskdata 2004-12-28
  • 打赏
  • 举报
回复
顶一下有分吗?
lxjlz 2004-12-28
  • 打赏
  • 举报
回复
來晚了.
  • 打赏
  • 举报
回复
Private Sub Text1_Change()
Dim x As String, y As Integer
x = Text1
If Len(x) > 3 Then MsgBox "长度不能超过3"
If Not IsNumeric(x) Or Left(x, 1) = "-" Then
Text1 = ""
MsgBox "请输入1~100数字"
End If
y = x
If y = 100 Then SendKeys vbTab
if y>100 then text1 = Left(Text1 , 2)
End Sub
jjjjjjjj2046 2004-12-28
  • 打赏
  • 举报
回复
要求:

1、textbox组只能录入1-100之问的数字,如果大于100则光标在原位
2、如果是录入是100(只有这个是三位),光标自动跳到下一个textbox,如是是0-99之间的数。则按回车后自动跳到下一个textbox

--------------------------------------------------------------------------------------
Option Explicit
Dim i As Integer '记录文本中的字符宽度
Dim intTextvalue As Integer '记录文本中的值

Private Sub Form_Load()
Me.Text1.Text = "" '初始化控件内容
Me.Text2.Text = ""
End Sub

Private Sub Text1_Change()
On Error Resume Next '如果出错执行下一句
i = Len(Text1.Text) '得到文本控件中的内容宽度
intTextvalue = CInt(Text1.Text) '把文本内容转为数值
If Err.Number = 13 Then '如果不是整数
Text1.Text = Left(Text1.Text, i - 1) '删除出现错误的字符
End If
If intTextvalue <= 9 Then '不让数值形如01,09等
If i > 1 Then
Text1.Text = intTextvalue
End If
End If
Text1.SelStart = i '光标在最后一个字符后
If intTextvalue > 100 Then '如果内容大于100,光标停留在第3个字符位置
Text1.SelStart = 3
End If

If intTextvalue = 100 Then '如果内容等于100,下一个控件得到焦点
Text2.SetFocus
End If
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If intTextvalue >= 0 And intTextvalue < 100 Then '如果内容等于0-99,
If KeyCode = vbKeyReturn Then '如果输入了回车符
Text2.SetFocus '下个控件得到焦点
End If
End If
End Sub
marckle 2004-12-28
  • 打赏
  • 举报
回复
isnumberic判断是否是数字.
将每个textbox的taborder设定好.如果输入100,sendkeys "tab"
如果是回车,sendkeys "tab",当然你还需要判断是否是0-99的数字.
ff8001 2004-12-28
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim pStatus As String
Dim a As String
a = Trim(Text1.Text)
Dim b As String
b = Trim(Text2.Text)
Dim c As String
c = Trim(Text3.Text)
Dim padoConnection As New ADODB.Connection
With padoConnection
.ConnectionString = "provider=microsoft.jet.oledb.4.0;persist security info=false;data source=" & App.Path & "\物品领用登记表.mdb"
.Open
If .State = adStateOpen Then
pStatus = "Connection is OK!"
Else
pStatus = "Connection is Failed!"
End If
End With
With Adodc1
.ConnectionString = padoConnection
.RecordSource = "select * from 物品领用登记表 where 领用人姓名 LIKE '%" + a + "%' and 物品名称 LIKE '%" + b + "%' and 数量 like '%" + c + "%'" + " and 领用日期 between '" + Text4.Text + "' and '" + Text5.Text + "'"
.LockType = adLockOptimistic
End With
Adodc1.Refresh
DoEvents
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
我是初学者,在做个报表查询时遇见这样的一个问题.
运行提示:对象"refresh" 的方法" IAdodc"失败,请问是什么原因?该

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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