Solved

Passing a variable to a path in VBscript

Posted on 2007-03-30
3
475 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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