Home > Software engineering >  Excuse me each expert how to use VB, the make and model of the automatic classification list for the
Excuse me each expert how to use VB, the make and model of the automatic classification list for the

Time:10-05

ID name of spare parts model data code
1 PC xx1 407001
2 computer xx1 407001
Three computer xx1 407001
4 computer xx2 407002
5 computer xx2 407002
6 PCS xx3 407003
7 XXX computer 407004
8 computer XXX 407004

Hello, I want to use the VB, these same type automatic plus "data code", the rules of the code as shown in the table above,
Computer belongs to the generation of terminal compose is: 407 (this is the same), and then use the VB automatic classification, the [type] the same suffix, suffix since 001, the same type additive, meet different models, from 002 to start automatically as additive. Please look at the specific effect of the above-mentioned "data code"
The program implementation can use? Please help the expert, I don't know where to start. Thank you very much

CodePudding user response:

Please refer to:
 Sub test () 
The Debug. Print GetDataNumber (" xx1, xx2, xx1, xx2, xx3, xx4, xx1, xx4, xx5 ")
End Sub
The Function GetDataNumber (ByVal bStr As String) As String
'because the data do not know from where, for a moment think from string, such as: xx1, xx2, xx2 xx3, xx4...
' 'reference Microsoft Scripting Runtime
"' bStr can be sort good, also can be a messy
, iDic Dim w1 As String, I As Long As the New Dictionary, ww
Ww=Split (bStr, ", ")
For I=0 To UBound (ww)
W1=LCase $(ww) (I)
Then If Not iDic. The Exists (w1)
"' if the models in the dictionary does not, an extra, and use a dictionary in the number of + 1 as a corresponding number
IDic (w1)="407" & amp; The Format $(iDic. Count + 1, "000")
End the If
Next
'in the order of the incoming string output corresponding coding
W1=""
For I=0 To UBound (ww)
W1=w1 & amp; The IIf (w1 & lt;> "",", ", "") & amp; IDic (LCase $(ww) (I))
Next
GetDataNumber=w1 'returns the corresponding encoded string
IDic. RemoveAll
The Set iDic=Nothing
End the Function

CodePudding user response:

Can use the ListBox control (can be set to Visibal=False),

Assume that your data is in the recordset object rs,
 Private Declare Function SendMessagebyString Lib _ 
"User32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long As String)

Private Const LB_FINDSTRINGEXACT=& amp; H1A2 'precise search in the ListBox

Private Sub Command1_Click ()
Dim n As Long
List1. Clear
EOF
Do Until the rs.N=SendMessagebyString (List1. HWnd LB_FINDSTRINGEXACT, 1, rs. The Fields (" type "))
If n=1 Then
List1. AddItem rs. Fields (" type ")
N=List1. NewIndex
List1. ItemData (n)=407001 + n
End the If
Rs. The Fields (" data code ")=List1. ItemData (n)
Rs. Update
Rs. MoveNext
Loop
End Sub
  • Related