新手又来问个问题了
要求: 从数据库已有的一串数字 并在给定的范围内反选出最小的 在textbox输入框中判定
Dim b() As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim d As Long
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\u0778\Documents\201310280824.mdb;Persist Security Info=False"
rs.Open "select 流水代号 from cp_dxdl where 特性代号='" & DataCombo1.Text & "'and 参数代号='" & DataCombo2.Text & "' ", cnn, 1, 3
d = 0
While Not rs.EOF
ReDim Preserve b(0 To d) As String
b(d) = rs("流水代号")
d = d + 1
rs.MoveNext
Wend
rs.Close
cnn.Close
Set cnn = Nothing
Set rs = Nothing
Dim bin As Boolean
Dim i As Integer
Dim e As Integer
For i = 0 To 9
bin = False
For e = 0 To UBound(b)
If i = b(e) Then
bin = True
Exit For
End If
Next e
If bin = False Then Combo1.AddItem (CStr(i))
Next
我是这么做的 取出数据后 再循环判定 然后添加到combo1中去。。。但是现在客户要求用的textbox作为输入框,也就是要求在textbox中输入判定是不是最小不是就认为输入错误。
然后我就自然的把代码粘过去 发觉各类不能用 要么标准数据类型不符合 要么就是达不到预期的效果
求教 如何改良
[解决办法]
理解错了。你是要确认 0 - 9 不在记录中。
Private Declare Function SendMessagebyString Lib _
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Const CB_FINDSTRINGEXACT = &H158 '在 ComboBox 中精确查找
rs.Open "select 流水代号 from cp_dxdl where 特性代号='" & DataCombo1.Text & "'and 参数代号='" & DataCombo2.Text & "' WHERE 流水代号 < 10", cnn, 1, 3
For i = 0 To 9
Combo1.AddItem i
Next i
Do Until rs.EOF
i = SendMessagebyString(Combo1.hWnd, CB_FINDSTRINGEXACT, -1, rs!流水代号)
If i > -1 Then Combo1.RemoveItem i
rs.Movenext
Loop
If Text1 > Text2 Then
Text1.Tag = Text2
Text2 = Text1
Text1 = Text1.Tag
End If
rs.Open "select 流水代号 from cp_dxdl where 特性代号='" & DataCombo1.Text & "'and 参数代号='" & DataCombo2.Text & "' WHERE 流水代号 >=" & Text1 & " AND 流水代号 <=" & Text2, cnn, 1, 3
......