Use VB script to extract separate words from a string
Dear all,
I am trying to make a label from scanning a 2D code.
This 2D code contains a string of words that are separated with a semicolon.
In my label i have defined several fields for each word in the string.
Can I Use VB to extract each individual word from the scanned string?
I have made some code that works in Excel. Can I use the same code in Bartender?
Public Function ExtractWord(strWord, strSepChar As String, iWordNr As Integer) As String
Dim strWords() As String
Dim nWords As Integer
strWords = Split(strWord, strSepChar)
nWords = UBound(strWords, 1)
If nWords >= iWordNr Then
ExtractWord = Trim(strWords(iWordNr))
Else
ExtractWord = strWord
End If
End Function
-
Hello Ton,
Welcome to the BarTender Community Forums!
Yes, you can definitely use VB Script to extract each individual word from the scanned string. VB provides various string manipulation functions that can help you achieve this. Here's an example of how you can extract individual words from a scanned string in VB, assuming the scanned string is stored in a variable called scannedString:Dim words As String() = scannedString.Split(";"c)
For Each word As String In words
' Process each individual word here
Console.WriteLine(word)
Next
In this example, the Split() function is used to split the scannedString into an array of words based on the semicolon delimiter. The resulting array, words, will contain each individual word from the scanned string. You can then iterate over the words array using a loop (such as a For Each loop) and perform further processing on each individual word as needed.If you have further questions related to VB scripting, we would recommend reaching our Professional Services team, who in exchange for a quote, can help you with all your scripting needs.
0 -
Ton van de Vorst
★ BarTender Hero ★
Thanks Xabier,
I implemented the following function in the script library. This works fine.
If you have a long string with a separation character between the substrings, then the field in a label can extract its value with that function:
In the code below the substring "serial" is assigned the first substring from the string "scancode". The different substrings are separated by a semicolon ";".
Format.NamedSubStrings("Serial").Value=ExtractWord(Format.NamedSubStrings("Scancode").Value, ";",0)
'Shared subroutines, functions, and variables are placed here for reference by all documents.
Public Function ExtractWord(strWord, strSepChar, iWordNr )
Dim strWords, nWordsstrWords = Split(strWord, strSepChar, -1,1)
nWords = UBound(strWords, 1)
If nWords >= iWordNr Then
ExtractWord = Trim(strWords(iWordNr))
Else
ExtractWord = strWord
End If
End Function0
Please sign in to leave a comment.
Comments
2 comments