View Single Post
Old 10-22-2010, 06:14 PM
miked's Avatar
miked miked is offline
Registered User
Join Date: Feb 2004
Posts: 2,040
Hello olivebranch2006,
I want the vbtextcompare to find the "System serial number !
: " text and count how many times that text is found. That will specify how many switches are in the stack and therefore how many times to loop the serial number extraction section.
The following lines of code looks like they might need to be changed:
    showver = crt.Screen.ReadString(register)
    switchcount = InStr(showver, "System serial number            : ", vbTextCompare)
The first line looks a little suspicious because register is not declared as a variable anywhere, and is not passed as a string. Did you mean to declare it as a variable, or are you wanting to read data until you see the string "register", as shown below?
showver = crt.Screen.ReadString("register")
You also said want to count the number of times "System serial number" appears. The InStr method returns the position of the first occurrence of one string within another. InStr does not count the number of occurrences.

To count the number of occurences, a couple of ideas come to mind:
  • Use the VBScript Split function to split the showver variable into an array. You could use a carriage return as the delimiter. After showver is split into an array you could loop through every element and use InStr to see whether each element contains "System serial number".
  • Use a regular expression to search the showver variable. You can use the regular expression method Count to tell you how many matches were found.
The SecureCRT Scripting Manual has a regular expression example in section 4.3 Capturing Data from a Remote Machine (near page 53) which shows how to use a regular expression to do something similar to what you're wanting to do.

It looks like your code is putting the output from ReadString into the variable showver. If you use a regular expression to search showver, the code may resemble the following pseudo code.
' Create a new regular expression object
Set re = New RegExp
re.Pattern = "System serial number.*\:"
If re.Test(showver) <> True Then
    MsgBox "Pattern " & re.Pattern & " not found"
    Set matches = re.Execute(showver)
    MsgBox "Number of matches found: " & matches.Count
End If
VanDyke Software
Technical Support
Reply With Quote