?
Solved

Passing a variable to a path in VBscript

Posted on 2007-03-30
3
Medium Priority
?
481 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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