机房收费系统之(模块使用)

一、调用模块中的一段代码,批量清空文本框中的内容

1.模块中写,一定注意把参数加上

<span style="font-size:24px;">Public Function da(frm)
    Dim ctrl As Control
        For Each ctrl In frm.Controls
            If TypeOf ctrl Is TextBox Then   '是否为文本框TextBox
                ctrl.Text = ""
            End If
            If TypeOf ctrl Is ComboBox Then
                ctrl.Text = ""
            End If
        Next
End Function</span>
2.窗体中写 
<span style="font-size:24px;">Call da(Me)</span>
3、text也可以换成combo

二、调用模块里的一段代码,批量调整myflexgrid为合适的列宽

<span style="font-size:24px;">Public Sub AdjustColWidth(frmCur As Form, gridCur As Object, Optional bNullRow As Boolean = True, Optional dblIncWidth As Double = 0)
'--------------------------------------------------------------------
'功能:
'       自动调整Grid各列列宽为最合适的宽度
'参数:
'       [frmCur].........................................当前工作窗体
'       [gridCur]........................................当前要调整的Grid
'--------------------------------------------------------------------
Dim i, j As Integer
Dim dblWidth As Double
    With gridCur
        For i = 0 To .Cols - 1
            dblWidth = 0
            If .ColWidth(i) <> 0 Then
                For j = 0 To .Rows - 1
                    If frmCur.TextWidth(.TextMatrix(j, i)) > dblWidth Then
                        dblWidth = frmCur.TextWidth(.TextMatrix(j, i))
                    End If
                Next
                .ColWidth(i) = dblWidth + dblIncWidth + 1500 '注意这里的1500,可以自己改数字。
            End If
        Next
    End With
    End Sub</span>
2.窗体中写
<span style="font-size:24px;">Call AdjustColWidth(frmaduser, MyFlexGrid)  '后面为窗体名字,和窗体中myflexgrid的名字</span>

三、问题是:如下图

当输入查询内容小于2时,卡号查出来的是1、130、115

机房收费系统之(模块使用)_第1张图片

解决方法:将数据库中cardno由char改为int,但是新的问题出现了,就是文本框不能输入字母,只能输入汉字

解决方法:

1、模块中添加

<span style="font-size:24px;">Public Function chkkey(t As String, k As Integer) As Integer
    chkkey = k
    If k = 46 And InStr(t, ".") = 0 Then
        Exit Function
    End If
    If k = 8 Then
        Exit Function
    End If
    If k < 48 Or k > 57 Then
        chkkey = 0
    End If
End Function</span>
2、窗体调用

<span style="font-size:24px;">Private Sub txtcontent_KeyPress(Index As Integer, KeyAscii As Integer)
    If (Cmbfield1.Text) = "卡号" Then
    KeyAscii = chkkey(txtcontent(0), KeyAscii)
    Else
    If (Cmbfield1.Text) = "学号" Then
    KeyAscii = chkkey(txtcontent(0), KeyAscii)
    End If
    End If
    If (Cmbfield2.Text) = "卡号" Then
    KeyAscii = chkkey(txtcontent(1), KeyAscii)
    Else
    If (Cmbfield2.Text) = "学号" Then
    KeyAscii = chkkey(txtcontent(1), KeyAscii)
    End If
    End If
    If (Cmbfield3.Text) = "卡号" Then
    KeyAscii = chkkey(txtcontent(2), KeyAscii)
    Else
    If (Cmbfield3.Text) = "学号" Then
    KeyAscii = chkkey(txtcontent(2), KeyAscii)
    End If
    End If
End Sub</span>
四、未解决问题

combo的限制输入,虽然在它的keypress事件中输入一行KeyAscii = 0就可以解决,但是我想在模块中输入,然后整个工程中所有的combo限制输入。没有实现。谁有好的办法一块交流哦!






你可能感兴趣的:(机房收费系统之(模块使用))