这是一个程序中的一个页面,以下的程序的目的是在输入商品代码的过程中如果输入"*"号,则自动跳到数量的格子中输入数量,现在的问题是,当我按下*以后,还没有输入数量,等待输入的那段程序就已经运行完了,为什么会这样呢?
我在中间如果加一句msgbox显示一条消息话,却又可以正常输入数量,为什么会这样呢?应该怎么改呢?主要代码如下,用的是mshfgrid和一个textPublic col As Integer
Private Sub zytext(ByVal r As Integer, ByVal c As Integer) '专业表的移动文本框
On Error GoTo nexterror
'row = r
col = c
mshfGridOrderList.row = r
mshfGridOrderList.col = c
Text1.Width = mshfGridOrderList.CellWidth
Text1.Height = mshfGridOrderList.CellHeight
Text1.Left = mshfGridOrderList.Left + mshfGridOrderList.ColPos(c)
Text1.Top = mshfGridOrderList.Top + mshfGridOrderList.RowPos(r)
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.Visible = True
Text1.SetFocus
Exit Sub
nexterror:
MsgBox "文本框错误", vbOKOnly, ""
Exit Sub
End SubPrivate Sub mshfGridOrderList_KeyPress(KeyAscii As Integer)
'On Error Resume Next Dim strTotalPay As String '总计金额
Dim lngTotalpay As Long '总计金额
'如果在输入过程中输入回车,则转到下一行输入
'如果输入*,则转入数量输入
'一条商品信息和数量输入完毕自动计算总价
If KeyAscii = 13 Then
If mshfGridOrderList.TextMatrix(mshfGridOrderList.row, mshfGridOrderList.col) <> "" Then
lngTotalpay = CLng(mshfGridOrderList.TextMatrix(mshfGridOrderList.row, 6)) * CLng(mshfGridOrderList.TextMatrix(mshfGridOrderList.row, 5))
lblTotalPay.Caption = Format(CLng(lblTotalPay.Caption) + lngTotalpay, "¥#######0.00")
mshfGridOrderList.Rows = mshfGridOrderList.Rows + 1
zytext mshfGridOrderList.row + 1, 1
Else
End If
zytext mshfGridOrderList.row, 1
End If
KeyAscii = 0
End If
End SubPrivate Sub mshfGridOrderList_LeaveCell() Dim row As String
Dim oldstr As String
Dim strGoodsInfoSql As String
Dim rsGoodsInfo As New ADODB.Recordset
row = mshfGridOrderList.row
If row > 0 And col > 0 Then
oldstr = mshfGridOrderList.TextMatrix(row, col)
If col = 1 Then
mshfGridOrderList.TextMatrix(row, col) = Text1.Text
strGoodsInfoSql = "select GoodsID,GoodsName,Standard,GoodsUnit,OriginalPrice,PresentPrice,VIPFlag from CltGoodsInfo where GoodsID='" & mshfGridOrderList.TextMatrix(row, col) & "'"
Set rsGoodsInfo = RunSQLRetRS(strGoodsInfoSql)
If rsGoodsInfo.EOF And rsGoodsInfo.BOF Then
MsgBox "没有找到货品代码,请重新输入", vbExclamation + vbOKOnly, "出错"
mshfGridOrderList.TextMatrix(row, col) = ""
Text1.Text = ""
zytext row, 1
Else
'将商品信息填入表格
mshfGridOrderList.TextMatrix(row, 2) = rsGoodsInfo.Fields(1)
mshfGridOrderList.TextMatrix(row, 3) = rsGoodsInfo.Fields(2)
mshfGridOrderList.TextMatrix(row, 4) = rsGoodsInfo.Fields(3)
mshfGridOrderList.TextMatrix(row, 5) = Format(rsGoodsInfo.Fields(5), "¥##,###,##0.00")
mshfGridOrderList.TextMatrix(row, 6) = 1
mshfGridOrderList.TextMatrix(row, 7) = Format(mshfGridOrderList.TextMatrix(row, 6) * mshfGridOrderList.TextMatrix(row, 5), "¥#######0.00")
End If
ElseIf col = 6 Then
mshfGridOrderList.TextMatrix(row, col) = Text1.Text
mshfGridOrderList.TextMatrix(row, 7) = Format(mshfGridOrderList.TextMatrix(row, 6) * mshfGridOrderList.TextMatrix(row, 5), "¥#######0.00")
End If row = 0
col = 0
End If
Text1.Visible = False
'mshfGridOrderList.SetFocus
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Dim intRow As Integer
intRow = mshfGridOrderList.row If KeyAscii = 13 Then
mshfGridOrderList_LeaveCell
KeyAscii = 0
End If
If KeyAscii = 42 Then
mshfGridOrderList_LeaveCell
KeyAscii = 0
'MsgBox "here" 《-------------如果这里加上msgbox就可以正常输入
如果没有,就一下子跳过了
zytext intRow, 6
End If
End SubPrivate Sub Text1_LostFocus()
If Text1.Visible = True Then mshfGridOrderList_LeaveCell
End Sub
我在中间如果加一句msgbox显示一条消息话,却又可以正常输入数量,为什么会这样呢?应该怎么改呢?主要代码如下,用的是mshfgrid和一个textPublic col As Integer
Private Sub zytext(ByVal r As Integer, ByVal c As Integer) '专业表的移动文本框
On Error GoTo nexterror
'row = r
col = c
mshfGridOrderList.row = r
mshfGridOrderList.col = c
Text1.Width = mshfGridOrderList.CellWidth
Text1.Height = mshfGridOrderList.CellHeight
Text1.Left = mshfGridOrderList.Left + mshfGridOrderList.ColPos(c)
Text1.Top = mshfGridOrderList.Top + mshfGridOrderList.RowPos(r)
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.Visible = True
Text1.SetFocus
Exit Sub
nexterror:
MsgBox "文本框错误", vbOKOnly, ""
Exit Sub
End SubPrivate Sub mshfGridOrderList_KeyPress(KeyAscii As Integer)
'On Error Resume Next Dim strTotalPay As String '总计金额
Dim lngTotalpay As Long '总计金额
'如果在输入过程中输入回车,则转到下一行输入
'如果输入*,则转入数量输入
'一条商品信息和数量输入完毕自动计算总价
If KeyAscii = 13 Then
If mshfGridOrderList.TextMatrix(mshfGridOrderList.row, mshfGridOrderList.col) <> "" Then
lngTotalpay = CLng(mshfGridOrderList.TextMatrix(mshfGridOrderList.row, 6)) * CLng(mshfGridOrderList.TextMatrix(mshfGridOrderList.row, 5))
lblTotalPay.Caption = Format(CLng(lblTotalPay.Caption) + lngTotalpay, "¥#######0.00")
mshfGridOrderList.Rows = mshfGridOrderList.Rows + 1
zytext mshfGridOrderList.row + 1, 1
Else
End If
zytext mshfGridOrderList.row, 1
End If
KeyAscii = 0
End If
End SubPrivate Sub mshfGridOrderList_LeaveCell() Dim row As String
Dim oldstr As String
Dim strGoodsInfoSql As String
Dim rsGoodsInfo As New ADODB.Recordset
row = mshfGridOrderList.row
If row > 0 And col > 0 Then
oldstr = mshfGridOrderList.TextMatrix(row, col)
If col = 1 Then
mshfGridOrderList.TextMatrix(row, col) = Text1.Text
strGoodsInfoSql = "select GoodsID,GoodsName,Standard,GoodsUnit,OriginalPrice,PresentPrice,VIPFlag from CltGoodsInfo where GoodsID='" & mshfGridOrderList.TextMatrix(row, col) & "'"
Set rsGoodsInfo = RunSQLRetRS(strGoodsInfoSql)
If rsGoodsInfo.EOF And rsGoodsInfo.BOF Then
MsgBox "没有找到货品代码,请重新输入", vbExclamation + vbOKOnly, "出错"
mshfGridOrderList.TextMatrix(row, col) = ""
Text1.Text = ""
zytext row, 1
Else
'将商品信息填入表格
mshfGridOrderList.TextMatrix(row, 2) = rsGoodsInfo.Fields(1)
mshfGridOrderList.TextMatrix(row, 3) = rsGoodsInfo.Fields(2)
mshfGridOrderList.TextMatrix(row, 4) = rsGoodsInfo.Fields(3)
mshfGridOrderList.TextMatrix(row, 5) = Format(rsGoodsInfo.Fields(5), "¥##,###,##0.00")
mshfGridOrderList.TextMatrix(row, 6) = 1
mshfGridOrderList.TextMatrix(row, 7) = Format(mshfGridOrderList.TextMatrix(row, 6) * mshfGridOrderList.TextMatrix(row, 5), "¥#######0.00")
End If
ElseIf col = 6 Then
mshfGridOrderList.TextMatrix(row, col) = Text1.Text
mshfGridOrderList.TextMatrix(row, 7) = Format(mshfGridOrderList.TextMatrix(row, 6) * mshfGridOrderList.TextMatrix(row, 5), "¥#######0.00")
End If row = 0
col = 0
End If
Text1.Visible = False
'mshfGridOrderList.SetFocus
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Dim intRow As Integer
intRow = mshfGridOrderList.row If KeyAscii = 13 Then
mshfGridOrderList_LeaveCell
KeyAscii = 0
End If
If KeyAscii = 42 Then
mshfGridOrderList_LeaveCell
KeyAscii = 0
'MsgBox "here" 《-------------如果这里加上msgbox就可以正常输入
如果没有,就一下子跳过了
zytext intRow, 6
End If
End SubPrivate Sub Text1_LostFocus()
If Text1.Visible = True Then mshfGridOrderList_LeaveCell
End Sub
解决方案 »
- 会者不难难者不会---1个vb的小问题,请路过的高手进来看下
- 为什么VB6.0+SP5经常出现错误
- 各位帮忙,有一问题百思不得其解!很急!!!!!
- ListView 里面的ITEM怎么删除啊?
- VB查询语句!急!急!
- DataGrid控件怎样不让它在界面上直接修改值呢!!
- 如何解码web页面post/send过来的数据?
- 请问在ListView控件中,怎样实现每个ListItem的双击事件!
- 我通过高程,进来签个名留个记录吧!
- 谁能告诉我 VB 中adodc控件的data link 文件怎么建立? 具体格式怎么写.谢谢了
- 关于sql server数据库的备份
- 问一个弱问题:vb按钮上的字怎么改颜色啊?
'On Error Resume Next
'**************
running = true
'**************
'......
Text1.Visible = False
'mshfGridOrderList.SetFocus
'**************
running = false
'**************
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Dim intRow As Integer
intRow = mshfGridOrderList.row If KeyAscii = 13 Then
mshfGridOrderList_LeaveCell
KeyAscii = 0
End If
If KeyAscii = 42 Then
mshfGridOrderList_LeaveCell
KeyAscii = 0
'***************
do while running
loop
'***************
'MsgBox "here" 《-------------如果这里加上msgbox就可以正常输入
如果没有,就一下子跳过了
zytext intRow, 6
End If
End Sub