Dealing with Split() function: how to adjust for either return/tab input

允我心安 提交于 2020-01-07 02:59:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!