brewerdude
IS-IT--Management
I'm trying to create a script for a Nortel PBX that will allow the user to just enter a phone extension to get a print out of the phone (normally you print the extension, get the port, the print the port). However, if an extension is on more than one phone, you'll get a list of ports that it's on. To handle that, I have the code save the list of ports to a text file, than want to use a list box in a dialog box that will let the user pick the port they want to print. The issue I'm having is my list box always comes up empty in the script that creates the text file that the list box reads. However, if I run the dialog box code just by itself, the list box works properly. Can't figure out what I'm doing wrong. Was wondering if there's some sort of refresh I need to do to have the text file read correctly. Anyway, here's the code that creates the text file to be read into the list box:
;*******************************************************************
;*** This script will ask the user for a DN to print. If there ***
;*** is only one TN, it will print right away. If there are ***
;*** multiple TN's, the user will be given a list of available ***
;*** TN's to choose from. Selecting the desired TN will print it ***
;*******************************************************************
string DN_input
string fname ;file name for dn print output capture
string pname ;path name for dn pring output capture
string filename
integer linecount
string lineinfo
string TN
string multiple_TN[10] ;used if more than one TN to print
integer TN_count
integer num
string write_name = "C:\Program Files\Symantec\Procomm Plus\Capture\write_test.txt" ;file for list box entries
string write_string
string ListItem ; Item selected from list.
integer Event ; Dialog box event.
proc main
;*******************************************************************************************
;*** Start by setting the filename and path for the capture file, delete it if it exists ***
;*******************************************************************************************
fname = "capture_dn.txt"
pname = "C:\Program Files\Symantec\Procomm Plus\Capture\"
if isfile "C:\Program Files\Symantec\Procomm Plus\Capture\capture_dn.txt"
delfile "C:\Program Files\Symantec\Procomm Plus\Capture\capture_dn.txt"
endif
set capture file fname
set capture path pname
;*******************************************************
;*** Dialog box to get input from user, and print DN ***
;*******************************************************
sdlginput "Extension" "What is the Extension:" DN_Input
strcat DN_input "^M"
clear
capture on
transmit "******^M"
transmit "LD 20^M"
capture on
waitfor "REQ:"
transmit "prt^M"
waitfor "TYPE: "
transmit "DN^M"
waitfor "CUST "
transmit "0^M"
waitfor "DN "
transmit DN_Input
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT "
transmit "^M"
capture off
;****************************************************************************
;*** copy path and file name into new variable so can read from text file ***
;****************************************************************************
strcpy filename pname
strcat filename fname
;***********************************
;*** read DN info from text file ***
;***********************************
if fopen 0 filename READ TEXT ; Open file for read only.
while not feof 0 ; Loop while not end of file.
linecount++
fgets 0 LineInfo ; Get line from file.
if strsearch LineInfo "TN"
TN_Count++
if TN_Count >= 2 ;determine if more than one TN
multiple_TN[1] = TN ;first copy the first TN info first array
substr multiple_TN[TN_Count] Lineinfo 5 12 ;and if so, put them into an array
else
substr TN Lineinfo 5 12
endif
endif
endwhile
fclose 0 ; Close file opened for read.
else
errormsg "Couldn't open file `"%s`"." Filename
endif
;************************************************************
;*** Create and write to file of all entries in the array ***
;*** so they can be read into the list box later on ***
;************************************************************
if fopen 0 write_name CREATE
for num = 1 upto TN_Count
strcpy write_string multiple_TN[num]
strcat write_string "`r`n"
fputs 0 write_string
endfor
endif
;***************************************************************
;*** Print the phone depending on the situation, if there's ***
;*** only one TN, print right away, if there's more than one ***
;*** give user list box to pick TN they want to print ***
;***************************************************************
if TN_Count < 2
transmit "^M^M"
waitfor "REQ: "
transmit "prt^M"
waitfor "TYPE: "
transmit "tn^M"
waitfor "TN "
transmit TN
transmit "^M"
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT"
transmit "^M"
else
;pause 10
;fileview write_name
;usermsg write_name
dialogbox 0 0 0 100 120 11 "TN List"
text 1 5 5 90 12 "Select the TN you wish" CENTER
text 2 5 15 90 12 "to print." CENTER
flistbox 3 25 30 50 70 write_name SINGLE ListItem
enddialog
while 1
dlgevent 0 Event ; Get the dialog event.
switch Event ; Evaluate the event.
case 0 ; No event occurred.
endcase
case 3 ; Something was chosen.
usermsg "`"%s`" selected!" ListItem ;this will eventually contain the code to print the phone
endcase
default ; Exit case chosen.
exitwhile ; Exit the loop.
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL ; Destroy the dialog box.
endif
endproc
---------------------------------------------------
Here's the dialog box code by itself, largely copied directly from the ProcomPlus help files
proc main
string ListItem ; Item selected from list.
integer Event ; Dialog box event.
string write_name = "C:\Program Files\Symantec\Procomm Plus\Capture\write_test.txt"
; Display dialog box with list of items. You need
; a file called "items.lst" that contains items
; to choose from (one on a line).
fileview write_name
dialogbox 0 0 0 100 120 11 "TN List"
text 1 5 5 90 12 "Select the TN you wish" CENTER
text 2 5 15 90 12 "to print." CENTER
flistbox 5 25 30 55 70 write_name SINGLE ListItem
enddialog
while 1
dlgevent 0 Event ; Get the dialog event.
switch Event ; Evaluate the event.
case 0 ; No event occurred.
endcase
case 5 ; Something was chosen.
usermsg "`"%s`" selected!" ListItem
endcase
default ; Exit case chosen.
exitwhile ; Exit the loop.
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL ; Destroy the dialog box.
endproc
;*******************************************************************
;*** This script will ask the user for a DN to print. If there ***
;*** is only one TN, it will print right away. If there are ***
;*** multiple TN's, the user will be given a list of available ***
;*** TN's to choose from. Selecting the desired TN will print it ***
;*******************************************************************
string DN_input
string fname ;file name for dn print output capture
string pname ;path name for dn pring output capture
string filename
integer linecount
string lineinfo
string TN
string multiple_TN[10] ;used if more than one TN to print
integer TN_count
integer num
string write_name = "C:\Program Files\Symantec\Procomm Plus\Capture\write_test.txt" ;file for list box entries
string write_string
string ListItem ; Item selected from list.
integer Event ; Dialog box event.
proc main
;*******************************************************************************************
;*** Start by setting the filename and path for the capture file, delete it if it exists ***
;*******************************************************************************************
fname = "capture_dn.txt"
pname = "C:\Program Files\Symantec\Procomm Plus\Capture\"
if isfile "C:\Program Files\Symantec\Procomm Plus\Capture\capture_dn.txt"
delfile "C:\Program Files\Symantec\Procomm Plus\Capture\capture_dn.txt"
endif
set capture file fname
set capture path pname
;*******************************************************
;*** Dialog box to get input from user, and print DN ***
;*******************************************************
sdlginput "Extension" "What is the Extension:" DN_Input
strcat DN_input "^M"
clear
capture on
transmit "******^M"
transmit "LD 20^M"
capture on
waitfor "REQ:"
transmit "prt^M"
waitfor "TYPE: "
transmit "DN^M"
waitfor "CUST "
transmit "0^M"
waitfor "DN "
transmit DN_Input
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT "
transmit "^M"
capture off
;****************************************************************************
;*** copy path and file name into new variable so can read from text file ***
;****************************************************************************
strcpy filename pname
strcat filename fname
;***********************************
;*** read DN info from text file ***
;***********************************
if fopen 0 filename READ TEXT ; Open file for read only.
while not feof 0 ; Loop while not end of file.
linecount++
fgets 0 LineInfo ; Get line from file.
if strsearch LineInfo "TN"
TN_Count++
if TN_Count >= 2 ;determine if more than one TN
multiple_TN[1] = TN ;first copy the first TN info first array
substr multiple_TN[TN_Count] Lineinfo 5 12 ;and if so, put them into an array
else
substr TN Lineinfo 5 12
endif
endif
endwhile
fclose 0 ; Close file opened for read.
else
errormsg "Couldn't open file `"%s`"." Filename
endif
;************************************************************
;*** Create and write to file of all entries in the array ***
;*** so they can be read into the list box later on ***
;************************************************************
if fopen 0 write_name CREATE
for num = 1 upto TN_Count
strcpy write_string multiple_TN[num]
strcat write_string "`r`n"
fputs 0 write_string
endfor
endif
;***************************************************************
;*** Print the phone depending on the situation, if there's ***
;*** only one TN, print right away, if there's more than one ***
;*** give user list box to pick TN they want to print ***
;***************************************************************
if TN_Count < 2
transmit "^M^M"
waitfor "REQ: "
transmit "prt^M"
waitfor "TYPE: "
transmit "tn^M"
waitfor "TN "
transmit TN
transmit "^M"
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT"
transmit "^M"
else
;pause 10
;fileview write_name
;usermsg write_name
dialogbox 0 0 0 100 120 11 "TN List"
text 1 5 5 90 12 "Select the TN you wish" CENTER
text 2 5 15 90 12 "to print." CENTER
flistbox 3 25 30 50 70 write_name SINGLE ListItem
enddialog
while 1
dlgevent 0 Event ; Get the dialog event.
switch Event ; Evaluate the event.
case 0 ; No event occurred.
endcase
case 3 ; Something was chosen.
usermsg "`"%s`" selected!" ListItem ;this will eventually contain the code to print the phone
endcase
default ; Exit case chosen.
exitwhile ; Exit the loop.
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL ; Destroy the dialog box.
endif
endproc
---------------------------------------------------
Here's the dialog box code by itself, largely copied directly from the ProcomPlus help files
proc main
string ListItem ; Item selected from list.
integer Event ; Dialog box event.
string write_name = "C:\Program Files\Symantec\Procomm Plus\Capture\write_test.txt"
; Display dialog box with list of items. You need
; a file called "items.lst" that contains items
; to choose from (one on a line).
fileview write_name
dialogbox 0 0 0 100 120 11 "TN List"
text 1 5 5 90 12 "Select the TN you wish" CENTER
text 2 5 15 90 12 "to print." CENTER
flistbox 5 25 30 55 70 write_name SINGLE ListItem
enddialog
while 1
dlgevent 0 Event ; Get the dialog event.
switch Event ; Evaluate the event.
case 0 ; No event occurred.
endcase
case 5 ; Something was chosen.
usermsg "`"%s`" selected!" ListItem
endcase
default ; Exit case chosen.
exitwhile ; Exit the loop.
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL ; Destroy the dialog box.
endproc