问题
I currently have a serial number inventory database I am working on. I was using the split() function with a space delimiter to separate the data into individual data points, however the scanner I use uses delimiters of either 'return' or 'tab'
Is there any way to use either of those functions in the split() function??
I don't believe tab is possible because tab jumps to the 'next' button... so when the scanner inputs for example (data1 [tab] data2 [tab] data3 [tab]) into the textbox, my output is simply "data1"... I believe because then access utilizes the 'tab' button and just moves from my textbox to the next item. Effectively, it won't even display any data past the first set because it sees tab and moves on. Any way to change this?
Secondly, I can change the scanner to input return or the enter key as scanners delimiters, creating:
data1 data2 data3
in my text box.
Is there any way I can alter the provided code to analyze the lines of the text box and store the information that way (maybe... set each line to i and then run the below code.
I hope this makes sense! My current code that worked for space delimiter data was:
Dim InputString() As String
Dim i As Integer
InputString = Split(InputName, " ")
For i = 0 To UBound(InputString)
CurrentDb.Execute "INSERT INTO InventoryInputT(InputID) VALUES ('" & InputString(i) & "')"
Next i
回答1:
I couldn't understand your question's comments about tabs moving to the next button, because a tab within a string is just the same as any other character.
However, if what you are asking is how to split a string containing tabs (i.e. Chr(9)
s) as delimiters, you can use
InputString = Split(InputName, vbTab) ' to split on Chr(9)
For "return" characters, you can use one of the following, depending on what sort of "return" character it is
InputString = Split(InputName, vbCr) ' to split on Chr(13)
InputString = Split(InputName, vbLf) ' to split on Chr(10)
InputString = Split(InputName, vbCrLf) ' to split on Chr(13)&Chr(10)
Obviously, you could also use the actual Chr(x)
instead of the various constants if you wanted to.
来源:https://stackoverflow.com/questions/44008609/dealing-with-split-function-how-to-adjust-for-either-return-tab-input