Private Sub del_Click( )
Form2.Show
End Sub
Private Sub edit_Click( )
Form7.Show
End Sub 
Private Sub f_Click( )
DataReport3.Show
End Sub
Private Sub find_Click( )
Form2.Show
End Sub
Private Sub h_Click( )
Form3.Show
End Sub
Private SubMDIForm_Load( )
Me.Left=GetSetting(App.Title,”Settings”,”MainLeft”,1000)
Me.Top=GetSetting(App.Title,”Settings”,”MainTop”,1000)
Me.Width=GetSetting(App.Title,”Settings”,”MainWidth”,6500)
Me.Height=GetSetting(App.Title,”Settings”,”MainHeight”,6500)
 ‘frmLogin1.Show
Form1.Show
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
If Me.Window State< >vbMinimized Then
SaveSetting App.Title,”Settings”,”MainLeft”,Me.Left
SaveSetting App.Title,”Settings”,”MainTop”,Me.Top
SaveSetting App.Title,”Settings”,”MainWidth”,Me.Width
SaveSetting App.Title,”Settings”,”MainHeight”,Me.Height
  End If
End Sub
Private Sub n_Click( )
Dim h1 As Integer
Dim m1 As Integer
Dim s1 As Integer
Dim h2 As Integer
Dim m2 As Integer
Dim s2 As IntegerEnd Sub
Private Sub Combo1_Change( )
Dim msg2 As String
Msg2=Combo1.Text
Data1.Recordset.FindFirst”id=” & msg2
End Sub
Private Sub Command1_Click( )
Dim My Query As Integer 
h1=Hour(Time)
m1=Minute(Time)
s1=Second(Time)
MyQuery=DBCombo1.BoundText
   Data1.RecordSource=”SELECT * FROM wo WHEREid=” & MyQuery
   Data1.Refresh
   Data1.Recordset.MoveLast
   Data1.Recordset.MoveFirst
   Data1.Recordset.edit
   Data1.Recordset.Fields(“ 上机时间”)=Time
   Data1.Recordset.Fields(“金额”)=0
Data1.Recordset.Update
‘Data1.RecordSource=”wo”
‘Data1.Refresh
‘Command2.Visible=True
‘Command1.Visible=False
End Sub
Private Sub Command2_Click( )
h2=Hour(time)
m2=Minute(tim)
s2=Second(time)
c=Abs((h2-h1)*60)+Abs*(m2-m1)
Private Sub Command3_Click( )   ‘查询语句
Dim hno As String
hno=InputBox$(“请输入会员号”, “查询窗”)
Data1.Recordset.FindFirst “会员号=’”& hno &”’”
If Data1.Recordset.NoMatch Then MsgBox “无此会员号!”, , “提示”
End Sub
Private Sub Command4_Click( )
On Error Resume Next
Command1.Enabled=Not Command1.Enabled
Command2.Enabled=Not Command2.Enabled
Command3.Enabled=Not Command3.Enabled
Command5.Enabled=Not Command5.Enabled
If Command4.Caption= “添加” Then 
   Command4.Caption= “确定”
   Data1.Recordset.AddNew
Else
   Command4.Caption= “添加”
   Data1.Recordset.Update
Data1.Recordset.MoveLast
End If
End Sub
    Private Sub Command5_Click( )  ’删除
On Error Resume Next
Data1.Recordset.Delete
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then Data1.Recordset.MoveLast
    End Sub下面对一段程序进行说明:
Private Sub Text6_KeyPress(KeyAscii As Integer)
Static x As Boolean
Dim zfc As String
zfc=” ”
Select Case KeyAscii
Case Asc(“0”)To(“9”)
zfc=zfc+Chr(KeyAscii)
Case Asc(“.”)
If x Then 
KeyAscii=0
MsgBox”已经输入过小数点!”,64,“提示”
Else
x=True
zfc=zfc+Chr(KeyAscii)
End If
Case Else 
    KeyAscii=0
MsgBox“输入错误!”,48,”警告”
End Select
End Sub
它通过判定所按键的ASCII码值区分开按的是数字键、小数点键还是其他字符键。如果按得是数字键,那么通过chr(KeyAscii),把它接到zfc变量的右边即执行语句:zfc=zfc+Chr(KeyAscii)。如果按得是小数点键,这是就要判定时第一次还是第二次按下此键。如果是第一次按此键则应该把小数点拼接到zfc的右边,如果是第二次按的则不接受。为了区分按的是第一次还是第二次,代码中设置了一个布尔型的静态变量:x,初始值是:Flase。在第一次引发Text6的KeyPress事件过程时,由于x的值为Flase,所以做两件事:(1)将x设置为True;(2)把小数点拼接到zfc中,即执行语句:zfc=zfc+Chr(KeyAscii)。由于x是静态变量,因此再一次引发Text6的KeyPress事件过程时它就取值True,所以这时若又按下小数点键,就会一方面执行语句KeyAscii=0另一方面通过标准对话框MsgBox给出“已经输入过小数点!”的提示信息。如果按的是其它字符键,那么一律不被接到zfc中,而且通过提示信息对话框给出“  输入错误!”的警告信息。 
###########################################################################################
以上代码是我的毕业设计“网吧收费管理系统”里面的,因为代码不全所以没办法运行,哪位高手帮我看看,还需要添加哪些代码,我自己去找。

解决方案 »

  1.   

    粗略看了一下你的說明,似乎與在一文本框中只能輸入數字有點相似
    給你一點代碼參考
    Private Sub Text1_KeyPress(KeyAscii As Integer)
     On Error Resume Next
     Dim i As Integer
     Dim j As Integer
       If KeyAscii > 57 Or KeyAscii < 48 And KeyAscii <> 46 And KeyAscii <> 8 And KeyAscii <> 13 Then
        Text1.Locked = True
       ElseIf KeyAscii = 46 Then
        i = InStr(Text1.Text, ".")
        j = Len(Trim(Text1.Text))
        If j = 0 Then
         Text1.Locked = True
        ElseIf i = 0 Then
         Text1.Locked = False
        Else
         Text1.Locked = True
        End If
       Else
        Text1.Locked = False
       End If
    End Sub
      

  2.   

    通过这个函数也可以实现.不过我也看不清你所要表达的什么问题.
    Private Function ChkNum(Optional IKeyAscii) As Long
        Dim strTmp As String
    On Error GoTo ErrH
        If IKeyAscii < 45 Or IKeyAscii > 57 Then
            Select Case IKeyAscii
                Case 8, 13, 16, 37 To 40
                    IKeyAscii = IKeyAscii
                Case 43, 45 '+,-
                    strTmp = Trim(TxtNum.Text)
                    If InStr(strTmp, "+") > 0 Or InStr(strTmp, "-") > 0 Then
                        IKeyAscii = 0
                    Else
                        If IKeyAscii = 43 Then TxtNum.Text = "+" & strTmp
                        If IKeyAscii = 45 Then TxtNum.Text = "-" & strTmp
                        IKeyAscii = 0
                    End If
                Case Else
                    IKeyAscii = 0
            End Select
        Else
            If IKeyAscii = 47 Then IKeyAscii = 0
            If IKeyAscii = 46 Then '.
                strTmp = Trim(TxtNum.Text)
                If InStr(strTmp, ".") > 0 Then
                    IKeyAscii = 0
                Else
                    IKeyAscii = IKeyAscii
                End If
            ElseIf IKeyAscii = 43 Or IKeyAscii = 45 Then
                strTmp = Trim(TxtNum.Text)
                If InStr(strTmp, "+") > 0 Or InStr(strTmp, "-") > 0 Then
                    IKeyAscii = 0
                Else
                    If IKeyAscii = 43 Then TxtNum.Text = "+" & strTmp
                    If IKeyAscii = 45 Then TxtNum.Text = "-" & strTmp
                    IKeyAscii = 0
                End If
            Else
                '===
            End If
        End If
        ChkNum = IKeyAscii
        Exit Function
    ErrH:
        ChkNum = 0
        Exit Function
    End Function