Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling script variables from multiple files.

Status
Not open for further replies.

jeditom

IS-IT--Management
Dec 3, 2003
23
0
0
US
In the first few steps in the script below, is there a way to have the shelf number pulled from one text file and the slot number pulled from another. (In other words, I need the numbers transmitted in both those steps to be grabbed from a text file. Can I use the same text file and separate each pair of delimeters with a comma or such??)


proc main
string sLine

if fopen 0 "nychips1.txt" READ TEXT
; TELNET INTO THE CONTROLLER
connectmanual telnet "89.1.16.101"

; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO CHANGE THE SHELF
waitfor "SHELF=" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; ENTER THE SHELF NUMBER
waitfor "ENTER SHELF : ^[[24;28H" Forever
transmit "3"
transmit "^M"


; CHOOSE 2 TO CHANGE THE SLOT
waitfor "ENTER SELECTION : " Forever
while not feof 0
fgets 0 sLine
transmit "2"
transmit "^M"

; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever


if nullstr sLine
exitwhile
endif
transmit sLine
transmit "^M"


; CHOOSE 3 TO ENTER THE SHELF AND SLOT CHOSEN
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "3"
transmit "^M"

; CHOOSE 7 FOR DIAL BACKUP
waitfor "DIAL BACKUP" forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "7"
transmit "^M"

; CHOOSE 1 TO GO TO DIAL BACKUP
waitfor " GO TO DIAL BACKUP" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO DIAL STORED NUMBER
waitquiet 1
waitfor "DIAL STORED NUMBER" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; CHOOSE 1 TO DIAL THE FIRST STORED NUMBER
waitfor "ENTER NUMBER TO DIAL :" Forever
transmit "1"
transmit "^M"
waitquiet 8

transmit "^["
waitquiet 2
transmit "^["
waitquiet 2


endwhile
endif
fclose 0
endproc
 
Yes, you could have both variables in the same line in a text file, separated by commas or another delimiter. After you've read the line in from the file, you could use either strtok or strextract to get the particular variable you are looking for (I think strextract will likely be easier to use).


aspect@aspectscripting.com
 
Knob,

I am unfamiliar with the strextract command. Can you hook me up with an example?
 
Here is the info from the ASPECT help file, plus an example.

strextract strvar string string integer
Returns a string from a list of elements.

strvar A string variable which will receive the output characters.
string A list of elements separated by a common series of characters.
string The common series of characters that separate each element in the list string. This string could contain a single character such as a space, comma or tab, or several characters.
integer A zero-based integer specifying the occurrence to return.

Example

proc main
string FileList ; String to contain list of files.
string CurFname ; String to contain current file.
integer nItem = 0 ; Integer to indicate current file.

; Assign a list of files to our file list string and
; check all files to see that they exist in current
; directory.
FileList = "File.txt,Second.doc,Three.lst"
while 1 ; Loop forever, or until EXITWHILE.
; Extract file from list and confirm

; file exists. If not, display message.
strextract CurFname FileList "," nItem
if not nullstr CurFname ; See if we're at the end of list.
if not isfile CurFname ; If not, see if the file exists.
errormsg "File `"%s`" doesn't exist." CurFname
endif
nItem++ ; Increment our item pointer.
else
exitwhile ; If blank file name, exit loop.
endif

endwhile
endproc

Comments

strextract is useful for extracting specific items from a comma- or tab-separated string. To determine the number of items in a delimited string list, use the strsearch command.

aspect@aspectscripting.com
 
I am unsure how to relate that to a TRANSMIT statement
 
Hmm, maybe not the best sample after I look at it again. Here is one I whipped up (assumes the data has already been read in from a file and is in the variable sLine):

proc main
string sLine = "1,2"
string sShelf, sSlot

strextract sShelf sLine "," 0
strextract sSlot sLine "," 1

usermsg "Now transmitting Shelf #"
transmit sShelf
usermsg "Now transmitting Slot #"
transmit sSlot
endproc

This will send 1 for the shelf number and 2 for the slot number.


aspect@aspectscripting.com
 
(assumes the data has already been read in from a file and is in the variable sLine):

Knob,

One more please. I cannot get the script (sLine) to reference my data.txt file and ge the variables ? ? ?
 
To open and read from a file:

if fopen 0 "data.txt" READ TEXT
while not feof 0
fgets 0 sLine
;insert previous commands here
endwhile
endif

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top