Example VBScripts for Capture and Index Manipulation

EXAMPLE VBScripts for Capture and Index Manipulation

Here’s a good VBScript reference site:

https://www.w3schools.com/asp/asp_ref_vbscript_functions.asp

Some example VBScripts and their usage are given below:

This script replaces the digits '88' with '99', assuming '88' is the value 
fetched
by the indexing process.

Replace(Value,"88","99")
This script reverses the value fetched by the indexing process.

StrReverse(Value)
This script converts to uppercase the value fetched by the indexing process.

UCase(Value)


This script picks the first five characters, including numbers, from the value
fetched by the indexing process.

Left(Value,5)

This script picks the characters to the left of a “/”

Left(Value, InStr(Value, "/")-1)

Example: Changes 6170160/1 to 6170160


This script captures the 5 characters starting from the right.

Right(Value,5)

Example: Changes 123456 to 23456
  1. Replace(Value," ","")
    1. This script removes spaces “ “ from a string
      1. Example: Changes this VIN #: 5TDD G RFHXH S02 7889 to  5TDDGRFHXHS027889
    2. Replace(Replace(Replace(Replace(Replace(Value, "-",""), "_", "" ), ",", "" ),".","")," ","")
      1. This script removes the following characters from a string: “-“, “_”, “,”, “.” and a space “ “
        1. Example: Changes this __123456 to 123456
        2. Example: Changes this -123456 to 123456
        3. Example: Changes this .,123456 to 123456
      2. “ABC-“ & Value
        1. Add (concatenate) a string to a value
          1. Example: Changes this 123456 to ABC-123456
        2. Replace(FormatNumber(Replace(Value, "/", ""), 0, vbFALSE), ",", "")
          1. Remove leading 0’s and remove slashes / in a date.
            1. Example: Changes this 02/21/17 with 22117
          2. Right(Replace(Replace(Replace(Replace(Replace(Value, "-",""), "_", "" ), ",", "" ),".","")," ",""),5)
          3. Replace(Value, chr(34),"")
            1. This script replaces a double quote “ with a null value.
              1. Example: Changes this “47125 to 47125
            2. chr(34) is the character code for a double quote. You could also use replace(value, """", "") that """" gets evaluated as one double-quote character, but I believe the chr(34) is much less confusing.
          4. Replace(Replace(Replace(Replace(Replace(Replace(Value, "-",""), "_", "" ), ",", "" ),".","")," ",""),chr(34), “”)
            1. This script removes the following characters from a string: “-“, “_”, “,”, “.” and a space “ “ and the double quote “ with a null value.
          5. Trim(Value)
          6. trim(Split(Value, ",")(1))
            1. This will create an array out of th comma-separated parts of a text string, then access either the first or second part.
            2. trim(Split(Value, ",")(numberhere))
            3. this would be a good VBsript to separate a last name, first name
              1. Example String: Burnett, Carol
              2. trim(Split(Value, ",")(0))    
                1. Will return the first value before the comma which is Burnett
              3. trim(Split(Value, ",")(1))
                1. Will return the value after the first comma which is Carol

 

RO Number 

Replace(Left(Value, InStr(Replace(Value,"~","-"),"-")-1)," ","")
Name
Name

Replace(Replace(Replace(Replace(Value,"\",""),"-",""),"Commercial ",""),"Commercial","")
VIN

Left(Replace(Replace(Value," ",""),"VIN:",""),17)

Left(Replace(Replace(Replace(Replace(Value," ",""),"VIN:",""),"/","1"),".",""),17)
Cell Number

Left(Replace(Replace(Value,"~","-"),"?","7"),12)
Year

Year(value)
Week

datepart("ww",Value)

If you want an index field to be equal to today's date, select [Value} for the Zone Type and put any value but I recommend using "Today" as the [Keyword] and use the following script to change the value in the keyword cell to today's date.

Extract Year from date

Right(Replace(Replace(Replace(Value,"O","0"),"I","1"),"B","8"),4)
Replace common letters to numbers

Replace(Replace(Replace(Value,"O","0"),"I","1"),"B","8")
Extract the characters to the right of the “-“ symbol. 
The script below will extract “Carol Burnett” from “16557 – Carol Burnett”.

Right(Value,Len(Value)-InStr(Value,"-")-1)

I should mention that the scripts below work when the string you want to manipulate is in the format of: FirstName{space}Last Name

For example, the script below will turn JoHn SMitH to Smith, John

RETURNS PROPER LAST NAME, PROPER FIRST NAME

mid(value,(instr(value," ")+1),1) & LCase(right(value,Len(value)-(instr(value," ")+1))) & ", " & UCase(Left(value,1)) & LCase(MID(VALUE,2,(instr(value," ")-2)))
Various VBScripts Examples for FileBound Capture

UCase(Left(value,1)) & LCase(Right(value,Len(value)-1))

Ucase(left(value,1)) & Lcase(right(value,instr(value," ")-2))


RETURN POSITION # STRING IS FOUND

Instr(value," ")


RETURNS VALUE AFTER 1st SPACE

mid(value,(instr(value," ")+1),1)


RETURNS PROPER FIRST NAME

UCase(Left(value,1)) & LCase(MID(VALUE,2,(instr(value," ")-2)))


RETURNS PROPER LAST NAME

mid(value,(instr(value," ")+1),1) & LCase(right(value,Len(value)-(instr(value," ")+1)))


RETURNS PROPER LAST NAME, PROPER FIRST NAME

mid(value,(instr(value," ")+1),1) & LCase(right(value,Len(value)-(instr(value," ")+1))) & ", " & UCase(Left(value,1)) & LCase(MID(VALUE,2,(instr(value," ")-2)))