[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Passing a variable to a path in VBscript

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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