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

How to insert a filename into a variable

Status
Not open for further replies.

atascoman

Technical User
Oct 10, 2003
868
US
I am writing some simple scripts for my technicians to use in the field. The primary purpose is to upgrade the code on various devices. I have a working script which prompts them for a filename currently. Works fine, but I would like to take it a step further where they can just browse to the file and the script will use that filename later on in the script when it fires off the download commands. I'm not trying to execute the file, just need the name so I can use it in a variable.

Here is what I tried and it doesn't like this. I can browse and select the file, but the script errors out when it hits the line where I am trying to use the filename variable in a crt.Screen.send line of code. I am not an SME on VBScript, learning as I go.

set objShell = CreateObject("Shell.Application")
fileName = objShell.BrowseForFolder(0, "Pick a file" , 16384, 0)
 
I can browse and select the file, but the script errors out when it hits the line where I am trying to use the filename variable in a crt.Screen.send line of code.

Can you post the code, please

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Dim TFTPIP

TFTPIP=InputBox("Enter your TFTP address")
set objShell = CreateObject("Shell.Application")
fileName = objShell.BrowseForFolder(0, "Pick a file" , 16384, 0)

crt.Screen.send ("config t") & chr(13)
crt.Screen.send ("download address ") & TFTPIP & (" image ") & filename & (" no-reset") & chr(13)
crt.Screen.WaitForString "Finished Upgrading Image"
nextstep=MsgBox("Do you want to upgrade the diagnostic code now",VbYesNo)

Select Case nextstep
Case VbYes call diag
Case VbNo call exitscript
end select

Sub diag()

set objShell = CreateObject("Shell.Application")
diagfile = objShell.BrowseForFolder(0, "Pick a file" , 16384, 0)


crt.Screen.send ("download address ") & TFTPIP & (" diag ") & diagfile & chr(13)
crt.Screen.WaitForString "Rebooting"
call exitscript
end sub

Sub exitscript()
MsgBox("Upgrade complete")
end sub

 
OK, and what's the error? What is the command line showing as on the line that gets the error? I am guessing it will look something like:
download address 1.2.3.4 image myimage.jpg no-reset

Is the syntax your script creates correct?
 
crt is undefined

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Also, BrowseForFolder returns a folder object, even when a file is selected. You'll need to build the file path in order to access it.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFolder = objShell.BrowseForFolder(0, "Pick a folder" , 16384, 0) 

strFile = objFolder.Title
set objFolder = objFolder.ParentFolder
strPath = objFSO.BuildPath(objFolder.ParentFolder.ParseName(objFolder.Title).Path, strFile)

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks, yes the syntax is correct on the line you mentioned. That is the desired output I want to push to the device. That is where the script fails. I will have to fire one up and run it again as I didn't document the specific error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top