vb6.0 中的小技巧

1.数据库中null字段的处理
1)如果要处理成字符型则通过 &"" 即可
2)如果要处理成数值型则通过 CCur(IIF(isNull(字段值),0或其它默认值,字段值))
2.用代码展开combobox,而不用鼠标点击才展开
方法1:
Private   Sub   Command1_Click()  
          Combo1.SetFocus  
          SendKeys   "{f4}"  
          '如果再次发送f4的话,则收起  
          '也可以发送alt-down  
          'SendKeys   "%{down}"  
          '发送alt-up则为收起,即  
          'SendKeys   "%{up}"  
  End   Sub
方法2:
使用API来实现.   
'Declare   in   Module   
Public   Declare   Function   SendMessage   Lib   "user32"   Alias   "SendMessageA"   (ByVal   hwnd   As   Long,   ByVal   wMsg   As   Long,   ByVal   wParam   As   Long,   lParam   As   Any)   As   Long   
Public   Const   CB_SHOWDROPDOWN   =   &H14F   
    
'Send   message   
SendMessage   Combo1.hwnd,   CB_SHOWDROPDOWN,   True,   0
3.选择Combo值但不激活单击事件
'选择Combo值但不激活单击事件函数:
'参数:lst对应的combo的值 NewIndex选中的索引
Public Function SetCombo(ByVal lst As Control, ByVal NewIndex As Long) As Long
On Error GoTo Errc
    Dim SetListIndex As Long
    If TypeOf lst Is ListBox Then
        Call SendMessage(lst.hwnd, _
            LB_SETCURSEL, NewIndex, 0&)
        SetListIndex = SendMessage(lst.hwnd, _
            LB_GETCURSEL, NewIndex, 0&)
    ElseIf TypeOf lst Is ComboBox Then
        Call SendMessage(lst.hwnd, _
            CB_SETCURSEL, NewIndex, 0&)
        SetListIndex = SendMessage(lst.hwnd, _
            CB_GETCURSEL, NewIndex, 0&)
    End If
Exit Function
Errc:
  MsgBox "SetCombo():" & Error(Err.Number), vbOKOnly + vbInformation, MSGTITLE
End Function
4.

你可能感兴趣的:(小技巧)