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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read input file, Each line can have 4 to 8 entries. need to

Status
Not open for further replies.

jrvilla1

Technical User
Apr 3, 2003
7
US
I'm a little new to the more detailed use of the Aspect scripts.
Here is my need.
Creating on a Voicemail system distribution lists.
The input file could have up to eight fields of data.
But will always have four fields that are constant; MBX #, user Name, Dept name, temporary passcode. All fields are seperated with a pip "|".
Field 5 would be the first dist list member number. Field 6 could have the next member number. Then Field 7 and then 8 could be more members.
Now when reading the line of data, how do I get the script to jump to the next procedure if the data in field(s) 6, 7 or 8 are null?

The next proc would be an tranmit of the creation steps for the dist list members. Here is my script.

Thanks.
;================================================================*
; NOTE: The source file must have more than 1 record to run *
;================================================================*
; Input File - Data *
; *
; There are 8 fields in each line of input data *
; ===All fields are seperated with a pip "|" == *
; *
; Field #1 = Mailbox number "szMbxno" *
; Field #5 = Distribution list #1, 1st entry "szDL0101" *
; Field #6 = Distribution list #1, 2nd entry "szDL0102" *
; Field #7 = Distribution list #1, 3rd entry "szDL0103" *
; Field #8 = Distribution list #1, 4th entry "szDL0104" *
;----------------------------------------------------------------*
; These fields are in the source file and are not needed *
; *
; Field #2 = User Name "szUsername" *
; Field #3 = Department code "szDeptcd" *
; Field #4 = Temporary passcode "szPasscode" *
; *
;******************************************************************
;
INTEGER LOOPFLAG
proc main ;Beginning of main procedure
string szFile ;File name to be entered to be opened for data
string szLine ;Variable to store line from file.
string szMbxno ;String for mailbox number
string szUsername ;String for Users Name.
string szDeptcd ;String for Department code
string szPasscode ;String for Passcode to be assigned
string szDL0101 ;String for Dist list 01 member 01
string szDL0102 ;String for Dist list 01 member 02
string szDL0103 ;String for Dist list 01 member 03
string szDL0104 ;String for Dist list 01 member 04

;
usermsg "This Script will create the Dorm Shared Extension Mailbox dist list members."

sdlginput "Input File Name Entry" "Enter File name:" szFile
usermsg "the file name entered is :%s!" szFile
;******************************************************************

FOPEN 1 szFile READ TEXT ;OPEN FILE IN READ MODE ONLY
;
IF FAILURE ;IF FILE OPEN FAILS DISPLAY ERR MSG
ERRORMSG "Couldn't open :%s!" szFile "For Input"
EXIT ;EXIT SCRIPT
ENDIF
;
WHILE 1 ;LOOP FOREVER
FFLUSH 1
FGETS 1 szLine ;Get a line from the file and extract the
;
IF FEOF 1 ;IF EOF REACHED ..
EXITWHILE ;JUMP OUT OF WHILE LOOP
ENDIF
; Seperate the field data
;
strtok szMbxno szLine "|" 1 ; Mailbox number
strtok szUsername szLine "|" 1 ; Users Name has a comma in it
strtok szDeptcd szLine "|" 1 ; Department code
strtok szPasscode szLine "|" 1 ; Temporary Passcode
strtok szDL0101 szLine "|" 1 ; Dist list 01 member 01
strtok szDL0102 szLine "|" 1 ; Dist list 01 member 02
strtok szDL0103 szLine "|" 1 ; Dist list 01 member 03
strtok szDL0104 szLine "|" 1 ; Dist list 01 member 04
;
; Need to check for null values for members 2 to 4. The dlist members could be 1 to 4.
; If there are less than 4, then do not need the action to create dlist entries for those.
;
; End of the line of data needed
;
; To create the mailbox data
; Now to create the Distribution List 01 entry, member 01
;
TRANSMIT "dcreate m1=" ; QNX batch mode command
TRANSMIT szMbxno ; From file mailbox NUMBER
TRANSMIT " dl=1 dm=" ; dlist 1, member is...
TRANSMIT szDL0101 ; Member = Shared Ext MB number
; TRANSMIT "-s" ; Dist list is to be sorted
; Default is Unsorted list
TRANSMIT " +c -v ^M" ; Chk for dup and do not show detail then SEND CARRIAGE RETURN
WAITFOR "#" 10 ; WAIT 10 SECONDS FOR COMMAND COMPLETION
TRANSMIT "^M" ; SEND 2nd CARRIAGE RETURN to force # back
Pause 1 ; pause 1 second
;
; Now to create the Distribution List 01 entry, member 02
;
TRANSMIT "dcreate m1=" ; QNX batch mode command
TRANSMIT szMbxno ; From file mailbox NUMBER
TRANSMIT " dl=1 dm=" ; dlist 1, member is...
TRANSMIT szDL0102 ; Member = Shared Ext MB number
; TRANSMIT "-s" ; Dist list is to be sorted
; Default is Unsorted list
TRANSMIT " +c -v ^M" ; Chk for dup and do not show detail then SEND CARRIAGE RETURN
WAITFOR "#" 10 ; WAIT 10 SECONDS FOR COMMAND COMPLETION
TRANSMIT "^M" ; SEND 2nd CARRIAGE RETURN to force # back
Pause 1 ; pause 1 second
;
; Now to create the Distribution List 01 entry, member 03
;
TRANSMIT "dcreate m1=" ; QNX batch mode command
TRANSMIT szMbxno ; From file mailbox NUMBER
TRANSMIT " dl=1 dm=" ; dlist 1, member is...
TRANSMIT szDL0103 ; Member = Shared Ext MB number
; TRANSMIT "-s" ; Dist list is to be sorted
; Default is Unsorted list
TRANSMIT " +c -v ^M" ; Chk for dup and do not show detail then SEND CARRIAGE RETURN
WAITFOR "#" 10 ; WAIT 10 SECONDS FOR COMMAND COMPLETION
TRANSMIT "^M" ; SEND 2nd CARRIAGE RETURN to force # back
Pause 1 ; pause 1 second
;
; Now to create the Distribution List 01 entry, member 04
;
TRANSMIT "dcreate m1=" ; QNX batch mode command
TRANSMIT szMbxno ; From file mailbox NUMBER
TRANSMIT " dl=1 dm=" ; dlist 1, member is...
TRANSMIT szDL0104 ; Member = Shared Ext MB number
; TRANSMIT "-s" ; Dist list is to be sorted
; Default is Unsorted list
TRANSMIT " +c -v ^M" ; Chk for dup and do not show detail then SEND CARRIAGE RETURN
WAITFOR "#" 10 ; WAIT 10 SECONDS FOR COMMAND COMPLETION
TRANSMIT "^M" ; SEND 2nd CARRIAGE RETURN to force # back
Pause 1 ; pause 1 second
;
;
;******************************************************************
; Created the required data for a Mailbox, get more data input *
;******************************************************************
; end of the mailbox on to the next
CALL CMD_PMPT ;WAIT FOR # PROMPT LOOP
;
ENDWHILE
;
FCLOSE 1 ;CLOSE THE FILE
CALL CMD_PMPT ;WAIT FOR 6.0 # PROMPT LOOP
TRANSMIT "date^M" ;EXIT QNX OPERATING SYSTEM
;
; Show System Time, would be at QNX prompt now.
;
usermsg "End of script, either setup to run the next required Script or exit Procomm"
;
; Inform User that the Script is completed
;
ENDPROC
 
If the strings are truly null after the strtok command has been run, you can use nullstr to see if the resulting string is null. The command syntax is like this:

if nullstr szDL0102
perform necessary commands...
endif
if nullstr szDL0103
perform necessary commands...
endif
if nullstr szDL0104
perform necessary commands...
endif

In your case, I would recommend using the if nullstr commands as above to "wrap" each operation being performed based on the data in that string. If the string is null, then the commands you would normally transmit will be skipped, but the transmit commands will be used if the string is not null. Here is an example based on your script that hopefully illustrates what I am talking about:

;
; Now to create the Distribution List 01 entry, member 02
;
if nullstr szDL0102
TRANSMIT "dcreate m1=" ; QNX batch mode command
TRANSMIT szMbxno ; From file mailbox NUMBER
TRANSMIT " dl=1 dm=" ; dlist 1, member is...
TRANSMIT szDL0102 ; Member = Shared Ext MB number
; TRANSMIT "-s" ; Dist list is to be sorted
; Default is Unsorted list
TRANSMIT " +c -v ^M" ; Chk for dup and do not show detail then SEND CARRIAGE RETURN
WAITFOR "#" 10 ; WAIT 10 SECONDS FOR COMMAND COMPLETION
TRANSMIT "^M" ; SEND 2nd CARRIAGE RETURN to force # back
Pause 1 ; pause 1 second
endif aspect@aspectscripting.com
 
One more little item. The Input file, if there is no szDL0102, or szDL0103 or even szDL0104. They would not be seperated with "|" so there would not be any data. Does that not cause a problem?

Sample data, line one is not in the file.

mbx# | user name |dept |pcode|dl0101|dl0102|dl0103|dl0104
22861|THERAPY-GYM1-NAMES-TREE|22861|8952 |90224 |90225 |90226 |90227
27321|ENDO-FELLOWS |27321|9865 |95823 |92325 |95899
45492|PIERCE,304TREE |8XXXX|9869 |95005 |95006


; Seperate the field data
;
strtok szMbxno szLine "|" 1 ; Mailbox number
strtok szUsername szLine "|" 1 ; Users Name has a comma in it
strtok szDeptcd szLine "|" 1 ; Department code
strtok szPasscode szLine "|" 1 ; Temporary Passcode
strtok szDL0101 szLine "|" 1 ; Dist list 01 member 01
strtok szDL0102 szLine "|" 1 ; Dist list 01 member 02
strtok szDL0103 szLine "|" 1 ; Dist list 01 member 03
strtok szDL0104 szLine "|" 1 ; Dist list 01 member 04


Thanks again
 
No, it should not cause a problem. I used the various strtok commands and the last line of data (which did not have values for all fields) and szDL0103 and szDL0104 were null as expected.
aspect@aspectscripting.com
 
I tried this and I do not think the result is what I needed.

From what i saw as an result and from what the manual example shows it looks like it does not ignore the procedure but will only act upon it if it is null.
The manual is from 2.0 and my software version is 4.8 which has a very limited explaination in the doc pdf file.
2.0 shows this example.

proc main
string TextStr ; string for text entry.
transmit "Name?" ;Ask remote user for some info
rget TextStr 30 ;Get some text from the remote user.
if nullstr TextStr ; check to see if text is null.
transmit "^M^J^M^JYou must enter a value!^M^J"
endif
endproc

From that example it looks like the second transmit will only happen if TextStr is null.

For my need, I do not what that second tramsmit(example) to happen.
 
Sorry about that, I got my thinking backwards. Change if nullstr ... to if not nullstr ... This will cause the code between the if not nullstr/endif statements to be executed only if the string is not a null string.
aspect@aspectscripting.com
 
I tried that and it now is what I was looking for.

Here is my testing Script, in case others would like the tip.

;******************************************************************
; Date: 04/0342003
;******************************************************************
;
proc main ;Beginning of main procedure
string szFile ;File name to be entered to be opened for data
string szLine ;Variable to store line from file.
string szMbxno ;String for mailbox number
string szUsername ;String for Users Name.
string szDeptcd ;String for Department code
string szPasscode ;String for Passcode to be assigned
string szDL0101 ;String for Dist list 01 member 01
string szDL0102 ;String for Dist list 01 member 02
string szDL0103 ;String for Dist list 01 member 03
string szDL0104 ;String for Dist list 01 member 04

;
USERMSG "This Script will create the Dorm Shared Extension Mailbox dist list members."

sdlginput "Input File Name Entry" "Enter File name:" szFile
usermsg "the file name entered is :%s!" szFile
;******************************************************************

FOPEN 1 szFile READ TEXT ;OPEN FILE IN READ MODE ONLY
;
IF FAILURE ;IF FILE OPEN FAILS DISPLAY ERR MSG
ERRORMSG "Couldn't open :%s!" szFile "For Input"
EXIT ;EXIT SCRIPT
ENDIF
;
WHILE 1 ;LOOP FOREVER
FFLUSH 1
FGETS 1 szLine ;Get a line from the file and extract the
;
IF FEOF 1 ;IF EOF REACHED ..
EXITWHILE ;JUMP OUT OF WHILE LOOP
ENDIF
; Seperate the field data
;
TERMMSG &quot;Data item is :>%s<&quot; szLine

strtok szMbxno szLine &quot;|&quot; 1 ; Mailbox number
strtok szUsername szLine &quot;|&quot; 1 ; Users Name has a comma in it
strtok szDeptcd szLine &quot;|&quot; 1 ; Department code
strtok szPasscode szLine &quot;|&quot; 1 ; Temporary Passcode
strtok szDL0101 szLine &quot;|&quot; 1 ; Dist list 01 member 01
strtok szDL0102 szLine &quot;|&quot; 1 ; Dist list 01 member 02
strtok szDL0103 szLine &quot;|&quot; 1 ; Dist list 01 member 03
strtok szDL0104 szLine &quot;|&quot; 1 ; Dist list 01 member 04
;
; Need to check for null values for members 2 to 4. The dlist members could be 1 to 4.
; If there are less than 4, then do not need the action to create dlist entries for those
;
; End of the line of data needed
;
; To create the mailbox data
; Now to create the Distribution List 01 entry, member 01
;
if not nullstr szDL0101
usermsg &quot;mailbox for > %s<&quot; szUsername
usermsg &quot; member 01 =>%s<&quot; szDL0101
endif
;
; Now to create the Distribution List 01 entry, member 02
;
if not nullstr szDL0102
usermsg &quot;mailbox for > %s<&quot; szUsername
usermsg &quot;member 02 =>%s<&quot; szDL0102
endif

;
; Now to create the Distribution List 01 entry, member 03
;
if not nullstr szDL0103
usermsg &quot;mailbox for > %s<&quot; szUsername
usermsg &quot;member 03 =>%s<!&quot; szDL0103
endif
;
; Now to create the Distribution List 01 entry, member 04
;
if not nullstr szDL0104
usermsg &quot;mailbox for > %s<&quot; szUsername
usermsg &quot;member 04 =>%s<!&quot; szDL0104
endif
;
;******************************************************************
; Created the required data for a Mailbox, get more data input *
;******************************************************************

;
ENDWHILE
;
FCLOSE 1 ;CLOSE THE FILE

;
usermsg &quot;End of script, either setup to run the next required Script or exit Procomm&quot;
;
; Inform User that the Script is completed
;
ENDPROC




Many thanks. And have a great day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top