Computing.Net > Forums > Programming > Two variables into one

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Two variables into one

Reply to Message Icon

Name: Crossroad
Date: November 13, 2008 at 11:09:46 Pacific
OS: xp
CPU/Ram: 1gb
Product: Dell
Comment:

Hi !

Can anyone help me ?

How would you declare one variable that will contain 2 other variables in vbscript ?

Right now, I have ;

SearchPath1 = "C:\Temp1"
SearchPath2 = "C:\Temp2"

ResultSearchPath = SearchPath1 and SearchPath2

But I get a Type mismatch: 'Temp2" error message

Thanks

CR



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: November 13, 2008 at 11:50:54 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

set v1=this
set v2=that
set v3=!v1!!v2!
echo v3 is now set to !v3!

==========================
NOTE: In your example, the SET has spaces on both sides of =, which will lead to unexpected, and usually unpleasant, consequences


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Crossroad
Date: November 13, 2008 at 16:24:41 Pacific
Reply:

Thanks for your help M2 but now I get this syntax error at the line
set v3=!v1!!v2!

Probably vbscript doesn't like these (!!) exclamation marks


0

Response Number 3
Name: Mechanix2Go
Date: November 13, 2008 at 16:49:27 Pacific
Reply:

I didn't realize it was VBS. Wait for one of the other guys.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Razor2.3
Date: November 13, 2008 at 18:20:07 Pacific
Reply:

The concatenation operator is &.

ResultSearchPath = SearchPath1 & SearchPath2

That would give you C:\Temp1C:\Temp2. This may not be what you want, but I can only work with what I'm given.

0

Response Number 5
Name: shutat
Date: November 13, 2008 at 18:23:58 Pacific
Reply:

I haven't used VBS before, but if it similar to VB, then try using &

var1 = "string1"
var2 = "string2"
var3 = var1 & var2

If you need some way to break them up again, then try

var3 = var1 & some_deliminator & var2

The deliminator should be something that isn't in either string or something VBS wouldn't choke on such as an escaped or html type special char.

HTH


0

Related Posts

See More



Response Number 6
Name: Crossroad
Date: November 13, 2008 at 19:09:23 Pacific
Reply:

Thanks for replies guys, I should have explained what Im trying to do. I want to make one string to search two folders for a file.

Here is what I have so far but I get an error msg at the last line of the script saying "Path not found"

Dim FileName
Dim FileName2
Dim Folder

ReDim Location(0)
FileName="test.txt"
FileName2="Test.txt"

path1="c:\temp"
path2="c:\temp2"
PFolder=path1&path2

Set System=CreateObject("Scripting.FileSystemObject")

Call FindFile(PFolder)


Sub FindFile(ThisFolder)
Dim File
Dim Folder

For Each Folder In System.GetFolder(ThisFolder).SubFolders

The last script line above is where I get the error message "Path not found"

Any help appreciated.

Thanks
CR


0

Response Number 7
Name: klint
Date: November 14, 2008 at 02:34:00 Pacific
Reply:

You need to think very clearly about what exactly you are doing at each step. What are you passing to Sub FindFile? The sub expects a string variable that names a single folder. You passed it "c:\temp1c:\temp2". There is no such folder on your system.

Also, the documentation for System.GetFolder says it expects the name of a single folder.

You need to think about exactly how you are going to "combine" the two folders. What does combining actually mean?

For your application, you can put all the folder names into an array, and put a loop where you call FindFile each time through the loop.


0

Response Number 8
Name: Crossroad
Date: November 15, 2008 at 07:17:33 Pacific
Reply:

Thanks for your reply Klint

Actually, all I'd like to do is to search for a file in two folders (c:\temp and c:\temp2) one after the other.

I know that this can be done in vbscript, I just don't know how to set one variable that will hold the path of these two folders.

Thanks

CR


0

Response Number 9
Name: Razor2.3
Date: November 15, 2008 at 09:42:20 Pacific
Reply:

You don't. You do the search twice. Once on each directory, separately.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Two variables into one

how to combine two strings into one www.computing.net/answers/programming/how-to-combine-two-strings-into-one/800.html

combine two files into one file www.computing.net/answers/programming/combine-two-files-into-one-file/17093.html

need help with PHP www.computing.net/answers/programming/need-help-with-php/12828.html