Solved

Passing a variable to a path in VBscript

Posted on 2007-03-30
3
465 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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