View Single Post
  #2  
Old 07-24-2015, 04:57 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 955
How to prompt for input is handled in chapter 6 of the SecureCRT scripting guide, so I won't spend much time on that here.

One thing I will add here is that you may want to consider getting the data from the clipboard, since I'm assuming that in some/many cases the data will already be there having been copied from somewhere else?
strData = crt.Clipboard.Text
If the data is coming from the clipboard, each "line" will be separated from the next one by a CRLF combo, so an array of the lines can be obtained like this:
vLines = Split(crt.Clipboard.Text, vbcrlf)

If you choose to go with a simple InputBox that provides only a single line entry, you'll want to choose a separator that everyone is instructed to use when supplying multiple "lines" of data, like "," (comma) or space, or "|||" (three consecutive pipe chars).

If typed in as a single line, you'd split on your "separator" character you decided on. If it's a comma character, (as in "xe-0/0/0,xe-0/1/0,xe-0/2/0,xe-0/3/0"), then an array of lines can be obtain with this:
vLines = Split(strInputBoxResults, ",")


Sending a command with each "line" element substituted in place is done with a for each...next loop that would look like this:

Code:
    For Each strLine In vLines
        crt.Screen.Send "show interface diagnostic optics " & strLine & vbcr
        crt.Screen.WaitForString strPrompt
    Next
There are a lot of ways to parse out data from strings. Much of the "good stuff" related to such a task has already been detailed in chapter 4 of the SecureCRT scripting guide (see section 4.3, the subsection starting with "Extracting Specific Information"). There you'll find information about using Split(), as well as brief references to Instr(), Mid(), Left(), and Right() methods that are built in to VBScript to allow you to tear apart strings. While slightly more complicated to understand, regular expressions are usually best at parsing data that is always expected to match a particular pattern. This is also addressed in that same sub-section, in a sub-sub-section titled "Using Regular Expressions to Parse Information".

Rather than reinvent the wheel... I'll simply add that, in your specific case, I'd use a regular expression to parse out the a/b/c, as in "(\d+)/(\d+)/(\d+)", which will give you submatches(0) as a, submatches(1) will be b, and submatches(2) will be c.

You already know how to build up a string by using literal ""s coupled with variables and the & char, so piecing together your command would be the easiest part once you've extracted the a/b/c components with a regexp.


--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support