Solved

Passing a variable to a path in VBscript

Posted on 2007-03-30
3
429 Views
Last Modified: 2010-04-24
I need to pass a vbscript variable to a path name.  So far, all my attempts have resulted in a literal result. How do I get the variable of lookname to replace "lookname" in the path?

Dim lookname
lookname = Page1.Num1.value
MsgBox ("File name to find is  " & lookname)  'this works so I know variable is good.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Graphis\Diagrams\lookname.doc") Then
etc.
etc.
0
Comment
Question by:legendgraphics
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
JohnK813 earned 125 total points
ID: 18824152
Right, if you include the variable name in quotes, it will take the literal result.  You need to concatenate the variable with the rest of the string using &'s:

If objFSO.FileExists("C:\Graphis\Diagrams\" & lookname & ".doc") Then

Everything inside of the quotes is taken literally.  Everything outside of quotes is taken as a variable.  The &'s combine everything together.

0
 

Author Comment

by:legendgraphics
ID: 18824399
Thanks!

That works perfectly.

Dumb me...I spent hours browsing for some sample code and testing ideas before I solicited an expert.

legendgraphics

0
 
LVL 14

Expert Comment

by:JohnK813
ID: 18824627
Not a problem.

Some lanuages, like Perl, do let you put the variable right in the middle of the string like you did at first.  (Perl uses a special symbol in front of the variable name to signify that it's a variable.)  So it's easy to get confused.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now