Skip to main content



Use VB script to extract separate words from a string



  • Avatar
    Xabier Clemente

    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

    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.

  • Avatar
    Ton van de Vorst

    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, nWords

     strWords = Split(strWord, strSepChar, -1,1)
     nWords = UBound(strWords, 1)
     If nWords >= iWordNr Then
      ExtractWord = Trim(strWords(iWordNr))
      ExtractWord = strWord
     End If
    End Function


Please sign in to leave a comment.