Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-02-2010, 05:14 AM
giovalx giovalx is offline
Registered User
 
Join Date: Nov 2010
Posts: 14
Using File Name with parameters

Hello,
a new question to the experts.

I'd like to use a script and writing data to a file, where the file name includes a string received as a parameter from the command line. In the following example, the sript writes a string into the file named "log.txt". Can I open a file named "Device1.txt" instead log.txt, were the string "Device1" is passed to the script with /ARG ?

command line call to the script:
SecureCRT.exe /SCRIPT rollback.vbs /Telnet 127.0.0.1 2001 /ARG Device1

script:
#$language = "VBScript"
#$interface = "1.0"
Const ForWriting = 2
Const ForAppending = 8
crt.Screen.Synchronous = True
Sub Main
device= crt.Arguments(0)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.OpenTextFile( "log.txt", ForAppending, True)
objStream.WriteLine "Opening file: " & device & ".txt"
objStream.WriteLine "Writing Test data into" & device & ".txt"
End sub
Reply With Quote
  #2  
Old 12-02-2010, 09:50 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi giovalx,

You just need to use the variable when opening the file also. So the one line changes as shown below:
Code:
Set objStream = objFSO.OpenTextFile(device & ".txt", ForAppending, True)
Also, keep in mind that it's a good idea to close the "stream" when done writing to the file.
Code:
objStream.close
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 12-02-2010, 10:19 AM
giovalx giovalx is offline
Registered User
 
Join Date: Nov 2010
Posts: 14
Thanks Again Brenda.

One more question:

do exist in crt scripting the "GoTo label:" and the "On Error GoT label:" statements?

Thanks again

giorgio
Reply With Quote
  #4  
Old 12-02-2010, 10:30 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi giorgio,

Yes, SecureCRT supports the VBScript "On Error" statements:
Code:
On Error Resume Next
On Error GoTo 0
You can find additional tips on error handling (section 3.6) in the scripting guide available on our website here.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 12-03-2010, 07:19 AM
giovalx giovalx is offline
Registered User
 
Join Date: Nov 2010
Posts: 14
Thanks again,
but I knew about those to statements. I was looking for somthing like the VB:

On Error GoTo Label:


.....

Label:
do somthging else.

Anyway, I can do with Case and If.

Thanks again

giorgio
Reply With Quote
  #6  
Old 12-03-2010, 08:41 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
giorgio,

VBScript doesn't have the exact same capabilities as VBA.
  • VBA has some capabilities that VBScript does not have.
  • VBScript has some capabilities that VBA does not have.
One capability that VBA has that VBScript does not support is the creation of "Line Labels" and the ability to use "On Error Goto <Label>" statements.

For more information about differences between VBScript and VBA, see the following.
Microsoft information: Visual Basic for Applications Features Not In VBScript
--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by rtb; 12-03-2010 at 09:42 AM.
Reply With Quote
  #7  
Old 12-04-2010, 02:27 AM
giovalx giovalx is offline
Registered User
 
Join Date: Nov 2010
Posts: 14
Thanks Jake,

The linked URL will be very usefull.

Giorgio
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 04:57 PM.