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!

help with dialog strings, lists and routines requested

Status
Not open for further replies.

malium

ISP
Jun 26, 2003
23
0
0
US
Try not to laugh too hard, please, I know the stuff posted below doesn't compile and is riddled with errors. I don't have much in the way of progamming experience and I've spent the last day trying to read various references, sample scripts, posts and help files I could find and am not getting far. I have commented with some questions and a flow trying to explain what I want, I know I am missing some fundamental syntaxes and understanding of how
to do this. I'm still trying to get a better grasp of strings, if statements and how to tie actions to a dialog button. I've got the scripts I am trying to spawn working, I just want to tie it all together to a simple dialog so end users can use it with no fundamental understanding of Procomm.

What I've tried to do is outline enough of what I am wanting to do so that someone can help me with some better examples to make it do what I need - or if I could find an example of a dialog script that uses a few string and lists and then spawns some scripts inserting those strings based on different buttons pressed I might be able to get it to where I need.

; This script and related dialog box is used to select 3 variables -
; Router, Profile & MAC or EndOfMAC
; MAC/EndOfMAC string can be manually typed or pulled from clipboard using cliptostr
; If MAC entered manually it gets put back in clipboard
; with strtoclip for sub scripts to pull string and use it.
; then two buttons (UpdateProfile, ResetModem) use those three variable strings to invoke
; telnet sessions in same or a child window session. Third button EXIT exits Dialog Box and may
; want to close the pw5 session or leave it open, not sure
; but I'll probably want to do a version of the dialog or add a check box to close Procomm when exiting.
; UpdateProfile or ResetModem initiates telnet session using entry from dialing directory,
; this uses default script from Dialiing Directory to login. Then telnet needs to
; execute a script based on selection (UpdateProfile, ResetModem) passed from dialog box.
; This invoked script will need to pull Profile to
; determine script used and NAC/EndofMAC for data used in
; sub-scripts to reset modem or update profile.

; General question on text edit String MAC from dialog - do I need to use
; dlgevent somewhere to update string MAC from edit box?
; I probably want to be checking for any new string there as the user may
; process one string then multiple other strings.

proc main

string RouterList
string Router ="Abbotts,Ashbrook,Legacy,Jacksonville,SpringForest,Wilmington,Woodland"
string ProfileList
string Profile ="Deactivated,Basic,Express,Turbo"
string MAC
string EndOfMAC
cliptostr EndOfMAC

setaspect spawn ON ;allows script to spawn scripts
set dialentry scriptstart CONNECTED

dialogbox 0 68 22 218 142 2 "Modem Config Tool"
text 10 150 2 54 9 "Select Profile" left
text 11 41 2 50 9 "Select Router" left
listbox 12 18 13 94 73 RouterList SINGLE Router sort
text 13 6 95 126 12 "Enter MAC Address in format XX.XXXX" left
text 14 32 109 143 12 "Leave MAC empty to use Windows Clipboard" left
editbox 15 133 92 56 13 MAC 7
text 18 169 120 49 11 EndOfMAC left ; show string taken from cliptostr if any
pushbutton 19 128 34 84 12 "Update Modem Profile" ok default
pushbutton 20 132 53 78 13 "Reset Modem"
pushbutton 21 75 125 58 13 "Exit"
listbox 42 132 13 78 12 ProfileList SINGLE Profile
enddialog


;;;;;;; SELECT WHICH BUTTON WAS PRESSED
switch WhichButton ; Evaluate the WhichButton variable
if case 19
; UpdateProfile pressed,
; I think I have button label correct, do I?
call UpdateProfile

if case 20 ;ResetModem pressed
call ResetModem

if case 21 ;Exit pressed
call Exit

endcase
endswitch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; do I need to do a proc to Exit Dialog or just use something like
; dlgdestroy 0 CANCEL ; to Destroy the dialog under case 21 above

; on exit I want to leave last connected session still connected,
; or possibly close entire Procomm session

endproc ; end main proc


;;;;;;;UPDATE PROFILE FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;
proc UdpateProfile

; if MAC was entered manually
; copy MAC string to clipboard and EndOfMAC
; I could do this other ways but have scripts already
;set to use EndOfMAC string from clipboard, this lets me
;use same scripts. Wasn't sure if the spawned scripts will
;use strings from the parent script - using clipboard I
;can do what I need without dealing with DDE and multiple
;sessions of procomm.

if EndofMAC="" ; if clipboard empty fill with MAC string
strtoclip MAC
; if EndOfMAC is populated leave it alone. It'd be nice to validate clipboard has format &quot;XX.XXXX&quot; and to string any trailing <CR> here too if I can.

usermsg &quot;Connecting to site&quot;
; I want to use 'usermsg &quot;Connecting to %s&quot; Router' - I'm not clear if that will work using string
; from main script or if I need to define the string in some way in sub-routine also.


dial TELNET &quot;Router&quot;
;normally I invoke directory entry with
; 'dial TELNET &quot;Abbotts&quot;' - if I am using Router string to
; get my Directory entry does Router need to be in quotes or how do I use Router string here?

while $DIALING
yield
endwhile
; spawn Profile script (Basic, Express, Turbo,
; Deactivated) using Profile set in dialog
execute Profile
usermsg &quot;Profile Updated&quot;
edproc

;;;;;;;;;RESET MODEM FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;
proc ResetModem
; if use EndOfMAC from clipboard was not selected copy text entry MAC to clipboard
if EndofMAC=&quot;&quot;
strtoclip MAC
; MAC format is upper case, reset needs string to be in lower case
strlower EndofMac

usermsg &quot;Connecting to site&quot;
; can I include String Router, i.e.e usermsg &quot;Connecting to Router&quot; to ID router here?

dial TELNET &quot;Router&quot;
while $DIALING
yield
endwhile
execute ClipReset ; clipReset script pulls strtoclip to execute reset
usermsg &quot;Reset completed&quot;

endproc

;;;;;;;;;;;;;;;;EXIT - NOT SURE WHAT I NEED TO DO TO MAKE EXIT BUTTON EXIT DIALOG
;not sure I even need to do this as a proc or as part of
; the WUD dialog area

Thanks for any assistance, sample scripts, corrections or suggestion you may be able to offer.


 
Here is a cleaned-up version of the script that compiles. You'll notice that each case command usually ends with an endcase statement.

When you have a dialog box, you will want your script to sit in a while 1 (endless) loop, checking for events with the dlgevent command. This command gives you the value of the control activated in your dialog (using the whichbutton variable that already had in the switch/case structure).

To exit the script when button 21 is pressed, you can use the pwexit command.

I made EndOfMAC a global string so it can be accessed by the subprocedures called from main. You can pass variables to procedure to eliminate the need for global variables, but this it is probably easier to understand it this way in the beginning. I did the same thing for MAC.

To check if a string is null, you can use if nullstr MAC.

When you execute another script, the file name needs to be enclosed in double quotes, preferably with the .wax extension.
; This script and related dialog box is used to select 3 variables -
; Router, Profile & MAC or EndOfMAC
; MAC/EndOfMAC string can be manually typed or pulled from clipboard using cliptostr
; If MAC entered manually it gets put back in clipboard
; with strtoclip for sub scripts to pull string and use it.
; then two buttons (UpdateProfile, ResetModem) use those three variable strings to invoke
; telnet sessions in same or a child window session. Third button EXIT exits Dialog Box and may
; want to close the pw5 session or leave it open, not sure
; but I'll probably want to do a version of the dialog or add a check box to close Procomm when exiting.
; UpdateProfile or ResetModem initiates telnet session using entry from dialing directory,
; this uses default script from Dialiing Directory to login. Then telnet needs to
; execute a script based on selection (UpdateProfile, ResetModem) passed from dialog box.
; This invoked script will need to pull Profile to
; determine script used and NAC/EndofMAC for data used in
; sub-scripts to reset modem or update profile.

; General question on text edit String MAC from dialog - do I need to use
; dlgevent somewhere to update string MAC from edit box?
; I probably want to be checking for any new string there as the user may
; process one string then multiple other strings.

string EndOfMAC
string MAC

proc main

string RouterList
string Router =&quot;Abbotts,Ashbrook,Legacy,Jacksonville,SpringForest,Wilmington,Woodland&quot;
string ProfileList
string Profile =&quot;Deactivated,Basic,Express,Turbo&quot;
integer whichbutton

cliptostr EndOfMAC

set aspect spawn ON ;allows script to spawn scripts
set dialentry scriptstart CONNECTED

dialogbox 0 68 22 218 142 2 &quot;Modem Config Tool&quot;
text 10 150 2 54 9 &quot;Select Profile&quot; left
text 11 41 2 50 9 &quot;Select Router&quot; left
listbox 12 18 13 94 73 RouterList SINGLE Router sort
text 13 6 95 126 12 &quot;Enter MAC Address in format XX.XXXX&quot; left
text 14 32 109 143 12 &quot;Leave MAC empty to use Windows Clipboard&quot; left
editbox 15 133 92 56 13 MAC 7
text 18 169 120 49 11 EndOfMAC left ; show string taken from cliptostr if any
pushbutton 19 128 34 84 12 &quot;Update Modem Profile&quot; ok default
pushbutton 20 132 53 78 13 &quot;Reset Modem&quot;
pushbutton 21 75 125 58 13 &quot;Exit&quot;
listbox 42 132 13 78 12 ProfileList SINGLE Profile
enddialog

while 1
dlgevent 0 whichbutton
;;;;;;; SELECT WHICH BUTTON WAS PRESSED
switch WhichButton ; Evaluate the WhichButton variable
case 19
; UpdateProfile pressed,
; I think I have button label correct, do I?
call UpdateProfile
endcase
case 20 ;ResetModem pressed
call ResetModem
endcase
case 21 ;Exit pressed
pwexit
endcase
endswitch
endwhile
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; do I need to do a proc to Exit Dialog or just use something like
; dlgdestroy 0 CANCEL ; to Destroy the dialog under case 21 above

; on exit I want to leave last connected session still connected,
; or possibly close entire Procomm session

endproc ; end main proc


;;;;;;;UPDATE PROFILE FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;
proc UpdateProfile

; if MAC was entered manually
; copy MAC string to clipboard and EndOfMAC
; I could do this other ways but have scripts already
;set to use EndOfMAC string from clipboard, this lets me
;use same scripts. Wasn't sure if the spawned scripts will
;use strings from the parent script - using clipboard I
;can do what I need without dealing with DDE and multiple
;sessions of procomm.

if nullstr EndofMAC ; if clipboard empty fill with MAC string
strtoclip MAC
; if EndOfMAC is populated leave it alone. It'd be nice to validate clipboard has format &quot;XX.XXXX&quot; and to string any trailing <CR> here too if I can.
endif
usermsg &quot;Connecting to site&quot;
; I want to use 'usermsg &quot;Connecting to %s&quot; Router' - I'm not clear if that will work using string
; from main script or if I need to define the string in some way in sub-routine also.


dial TELNET &quot;Router&quot;
;normally I invoke directory entry with
; 'dial TELNET &quot;Abbotts&quot;' - if I am using Router string to
; get my Directory entry does Router need to be in quotes or how do I use Router string here?

while $DIALING
yield
endwhile
; spawn Profile script (Basic, Express, Turbo,
; Deactivated) using Profile set in dialog
execute &quot;Profile.wax&quot;
usermsg &quot;Profile Updated&quot;
endproc

;;;;;;;;;RESET MODEM FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;
proc ResetModem
; if use EndOfMAC from clipboard was not selected copy text entry MAC to clipboard
if nullstr EndofMAC
strtoclip MAC
; MAC format is upper case, reset needs string to be in lower case
endif
strlwr EndofMac

usermsg &quot;Connecting to site&quot;
; can I include String Router, i.e.e usermsg &quot;Connecting to Router&quot; to ID router here?

dial TELNET &quot;Router&quot;
while $DIALING
yield
endwhile
execute &quot;ClipReset.wax&quot; ; clipReset script pulls strtoclip to execute reset
usermsg &quot;Reset completed&quot;

endproc

aspect@aspectscripting.com
 
Thanks. You helped quite a bit. I figured out a few other mistakes causing the list items not to display and have debugged it to the point that the ResetModem function seems to be working fine.

But when I try to pass a string to execute a script name it doesn't seem to take it. I even tried renaming the listitems to include the .wax extension. In the Reset proc part I always use the same script, and it works ok there. It seems to be an issue with getting the string passed to the execute command when I use (condensed to the essence of it):

string Profile
execute Profile
(or execute &quot;Profile&quot; or execute &quot;Profile.wax&quot;)
even though I can do a usermsg just before that to verify the string has the correct data.

>When you execute another script, the file name needs to >be enclosed in double quotes,

This seems to conflict with the help file example for execute, it doesn't seem to need &quot;&quot; around the script string that is passed:

proc main
string ScriptName ; Script file to run.
if sdlginput &quot;Run Script&quot; &quot;Name:&quot; ScriptName
if isfile ScriptName
usermsg &quot;Executing Script&quot;
execute ScriptName ; Execute the script file.
usermsg &quot;Returned from Script&quot;
else
errormsg &quot;Script doesn't exist!&quot;
endif
endif
endproc

But I can't see the script get executed no matter how I try to pass the name and I know the other procedure can execute a sub script ok if I specify the script name instead of passing it from a string.

Also wasn't sure if the main proc statement
set aspect spawn ON
set as a global or if I needed to include it in each proc routine. So I added it just to be sure. But that doens't seem to be related to the problems.

The other concern I have is how to make the EndOfMAC string
check for changes or updates during the dialog box usage. I want the tool to be able to be open for a while and used to process multiple strings and anticipate it changing. Not sure how or where to get the script to look for updates. I'd also like to see any updates displayed on the dialog window to show current string value of EndOfMAC.

I'm thinking maybe I don't really need EndOfMAC as a global string if I just copy MAC to Clipboard with cliptostr if not null and copy MAC back to clipboard after any upper/lower case changes to make sure it's in the format I need. One function needs upper case and the other needs lower case variations of the same string.

Here's a revised version of what I have now:

string EndOfMAC
string MAC
string Router
string Profile

proc main

string RouterList =&quot;Abbotts,Ashbrook,Legacy,Jacksonville,SpringForest,Wilmington,Woodland&quot;
string ProfileList =&quot;Disabled.wax,Basic.wax,Express.wax,Turbo.wax&quot;
integer whichbutton
cliptostr EndOfMAC
set aspect spawn ON ;allows script to spawn scripts
set dialentry scriptstart CONNECTED


dialogbox 0 72 22 212 147 2 &quot;Modem Config Tool&quot;
text 10 146 2 54 9 &quot;Select Profile&quot; left
text 11 37 2 50 9 &quot;Select Router&quot; left
listbox 12 14 13 94 73 RouterList SINGLE Router sort
text 13 8 96 126 12 &quot;Enter MAC Address in format XX.XXXX&quot; left
text 14 28 109 142 12 &quot;Leave MAC empty to use Windows Clipboard&quot; left
editbox 15 138 94 56 13 MAC 7
text 18 146 122 49 11 EndOfMAC left
pushbutton 19 124 60 84 12 &quot;Update Modem Profile&quot; OK DEFAULT
pushbutton 20 126 75 78 13 &quot;Reset Modem&quot;
pushbutton 21 71 125 58 13 &quot;Exit&quot;
listbox 42 128 13 79 40 ProfileList SINGLE Profile
enddialog


while 1
cliptostr EndOfMAC
; I want EndOfMAC to be updated anytime new data is copied to clipboard.
; not sure where to do this.
dlgevent 0 whichbutton
;;;;;;; SELECT WHICH BUTTON WAS PRESSED
switch WhichButton ; Evaluate the WhichButton variable
case 19 ; UpdateProfile pressed,
call UpdateProfile
endcase
case 20 ;ResetModem pressed
call ResetModem
endcase
case 21 ;Exit pressed
pwexit
endcase
endswitch
endwhile

endproc ; end main proc


;;;;;;;UPDATE PROFILE FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;
proc UpdateProfile

set aspect spawn ON ;allows script to spawn scripts
set dialentry scriptstart CONNECTED
; wasn't sure if these need to be set as global or in sub proc
; do I set outside main proc to use globally or need to be using it here?

if nullstr EndofMAC ; if clipboard empty fill with MAC string
strtoclip MAC
; if EndOfMAC is populated leave it alone.
endif

; test to show strings populated correctly
usermsg &quot;Connecting to Site, Router = %s&quot; Router
usermsg &quot;Profile = %s&quot; Profile
usermsg &quot;MAC = %s, EndOfMAC = %s&quot; MAC, EndOfMAC
; end test to show strings populated correctly
pause 2

dial TELNET &quot;%s&quot; Router
while $DIALING
yield
endwhile
pause 2

execute &quot;Profile&quot;
; spawn Profile script (Basic.wax, Express.wax, Turbo.wax,
; Disabled.wax) using Profile set in dialog

; execute doesn't seem to be working above
; execute Profile ;also does not work
; execute &quot;Profile.wax&quot; didn't work, so I added .wax to ProfileList entries
; execute works fine in proc ResetModem where script is specified manually

pause 5
usermsg &quot;Profile Updated&quot;
endproc

;;;;;;;;;RESET MODEM FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;
proc ResetModem

set aspect spawn ON ;allows script to spawn scripts
set dialentry scriptstart CONNECTED

; MAC/EndofMAC format is upper case
; reset needs string to be in lower case
strlwr EndOfMAC
strlwr MAC

if nullstr EndOfMAC
strtoclip MAC
endif

; cliptostr EndOfMAC

pause 2
usermsg &quot;Connecting to %s&quot; Router
usermsg &quot;MAC = %s, EndOfMAC = %s&quot; MAC, EndOfMAC
pause 1

dial TELNET &quot;%s&quot; Router
while $DIALING
yield
endwhile
pause 2
execute &quot;Reset.wax&quot; ; Reset script pulls strtoclip to execute reset
usermsg &quot;Reset completed&quot;

endproc

 
I didn't realize earlier that the values you were trying to execute earlier were strings containing the script name instead of the script name itself. In that case, you'll just want:

execute Profile

with no double quotes or .wax extension (since this is all taken care of in the dialog).

Since you are just using the execute command, I don't believe you need the set aspect spawn command at all.

Here is some additional information based on the comments in your script:

There is not a way for Procomm to be automatically notified when the value of the Windows clipboard changes.

The set dialentry command only needs to be issued once, but you first need to do a set dialentry access <dialclass> <entry> where <dialclass> is replaced by the connection type (data, telnet, etc.) and <entry> is the name of the entry to use. You will also need to issue a dialsave afterwards to save this change.



aspect@aspectscripting.com
 
<i>I didn't realize earlier that the values you were trying to execute earlier were strings containing the script name instead of the script name itself. In that case, you'll just want:

execute Profile

with no double quotes or .wax extension (since this is all taken care of in the dialog). </i>

Right, that should work, but for some reason doesn't, even with variations with or without &quot;&quot; and with the string now as complete script.wax file name. But the ResetModem routine calls the same script every time instead of passing a string with the script name and that seems to work ok.

I verified the Profile string the script name using usermsg but can't seem to get to pass Profile to execute a script.

I thought it was something like the default connect script not releasing control back to the parent script but am stumped because I can get it working when I specify a script name instead of using a string for the script name.

I'll play with it some more and see if I can find any difference between the child Profile and Reset scripts that could afftec things.

<i>Since you are just using the execute command, I don't believe you need the set aspect spawn command at all.
</i>

I seemed to have some problems in other scripts that invoked sub scripts previously and that seemed to be the workaround. I think it was an issue where the default scripts for a Dial entry in the Directory were not executing when I invoked a telnet connect from a script unless I added this. Because I need a two tiered login with two passwords I wasn't able to use the password functions in the Directory entry and needed to run a script to login twice to get to the level I need.

<i>The set dialentry command only needs to be issued once, but you first need to do a set dialentry access <dialclass> <entry> where <dialclass> is replaced by the connection type (data, telnet, etc.) and <entry> is the name of the entry to use. You will also need to issue a dialsave afterwards to save this change. </i>

Ok, I don't follow you here. Could you explain or show an example of what you mean? I don't understand what I am saving - are you talking about updating the Directory entry?

You are saying I should have something like this?

set dialentry access TELNET <SomeDirectoryEntry>
set dialentry scriptstart CONNECTED

As far as invoking a telnet session this part of it all seems to work fine for me. I wasn't able to get the default login scripts to run without this and the spawn statement, for example:

String SomeDirectoryEntry
set aspect spawn ON ;allows script to spawn scripts
set dialentry scriptstart CONNECTED
; run default script once connected

dial TELNET &quot;SomeDirectoryEntry&quot;
while $DIALING
yield
endwhile
pause 2


I'm not seeing issues with invoking telnet sessions or connecting using the method I use so I'm not clear what I'd need to save or why.

Thanks again for your help.


 
There is not a way for Procomm to be automatically notified when the value of the Windows clipboard changes.

Could there be a way look for updates clipboard data with a while/if statement? i.e. during the dialog check for button presses periodically check for a changed string using cliptostr and comparing that to the existing string and updating EndOfMAC if the clipboard changes. Or to invoke something like this as I exit other sub routines back to the main dialog.

Something like:

String Clipboard
String EndOfMAC
cliptostr Clipboard

while 1
wait 30
cliptostr Clipboard
if Clipboard=EndOfMAC
loop
if Clipboard does not = EndOfMAC
set EndOfMAC = Clipboard
endwhile
 
Regarding the set dialentry commands, you should not need them in your script since you cannot specify if a script should be run when connected or when the connection attempt starts for a telnet connection. If you look at the entry in the Connection Directory and click on the Basic Options button, you'll see there is no Setup button to the right of the Script dropdown listbox like there is for a data connection.

You likely wouldn't want to check the status of the clipboard while the script was instead the endless loop that executes after the dialog is displayed, especially if you were pausing now and the, since that might slow down the reaction to a user's choice in the dialog. However, I don't see a problem with making a procedure call now and then in the script that updates the value of EndOfMAC from the clipboard.

aspect@aspectscripting.com
 
I don't use the Data type connection entries so I'm not clear on what the Setup allows there, but I do have my Telnet entries intiating a script after dialup. Are you saying it can't do that, or just suggesting I am using a superfluous command that doesn't matter anyway?

It took a bit of tweaking to get it to work initially and I may have tried things that are not really doing anything. But all of my Telnet Directory entries run a script automatically after connect that effects a two tiered cisco router login with secondary enable password passed to the host.

I don't see a lot of references to Cisco here but from my perspective Procomm is an essential tool for scripting telnet sessions and it opens a lot of automation possibilities for us. On the other hand a lot of people are probably doing the same kind of scripting on a unix platorm instead of from PC clients.

Thanks again, you've helped me jumps some hurdles and dead-ends a few times.
 
The set dialentry scriptstart commands are only valid for data and FTP connections according to the help file, so I don't believe it will do anything (bad or good) in your environment using telnet connections.


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

Part and Inventory Search

Sponsor

Back
Top