×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to set/define a variable from two variables?

How to set/define a variable from two variables?

How to set/define a variable from two variables?

(OP)
Hello!

I am looking for help with setting a variable from two other variables.

Here my current test.vbs (the attachment upload failed); the commented 'WScript.Echo' in line 28 works fine, but in line 29, I fail to set the variable - I assume because of a quoting or escaping mistake:

################## test.vbs ##################
Dim StrLine
Dim FSO
Dim TSO
Dim StrLineElements
Dim Index
Dim i
Dim Delimiter
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TSO = FSO.OpenTextFile(".\test.ini")

Delimiter="="
Index = 1

'Do While TSO.AtEndOfStream = False
'	StrLine = TSO.ReadLine
'	StrLineElements = Split(StrLine, Delimiter) 
'	For i = LBound(StrLineElements) To UBound(StrLineElements)
'		WScript.Echo StrLineElements(i)
'	next
'	Index = Index + 1
'Loop

Do While TSO.AtEndOfStream = False
	StrLine = TSO.ReadLine
	StrLineElements = Split(StrLine, Delimiter) 
	For i = LBound(StrLineElements) To UBound(StrLineElements)
	next
'	WScript.Echo (StrLineElements(0) & "=" & StrLineElements(1))
	set StrLineElements(0) = StrLineElements(1)
	Index = Index + 1
Loop

TSO.Close
##############################################
 

The referenced 'test.ini' needs to reside in the same directory:

################## test.ini ##################
service="C:\Program Files\Notepad++\notepad++.exe"
parameters=""
interval=60
delay=10
trayicon="true"
##############################################
 

Thanks a lot!

RE: How to set/define a variable from two variables?

(OP)
[SOLVED] Ooops, never ask: the solution is around the corner winky smile

While TSO.AtEndOfStream = False
	StrLine = TSO.ReadLine
	StrLineElements = Split(StrLine, Delimiter) 
	For i = LBound(StrLineElements) To UBound(StrLineElements)
	next
'	WScript.Echo (StrLineElements(0) & "=" & StrLineElements(1))
	inikey = StrLineElements(0)
	inival = StrLineElements(1)
	inikey = inival
	WScript.Echo inikey
	Index = Index + 1
Loop
 

RE: How to set/define a variable from two variables?

(OP)
Well, that had been too fast, but here's the /real/ solution:

Dim StrLine
Dim FSO
Dim TSO
Dim StrLineElements
Dim Index
Dim i
Dim Delimiter
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TSO = FSO.OpenTextFile(".\test.ini")

Delimiter="="
Index = 1

Do While TSO.AtEndOfStream = False
	StrLine = TSO.ReadLine
	StrLineElements = Split(StrLine, Delimiter) 
	For i = LBound(StrLineElements) To UBound(StrLineElements)
	next
	execute(StrLineElements(0) + " = StrLineElements(1)")
	wscript.echo service + parameters + interval + delay + trayicon
	Index = Index + 1
Loop

TSO.Close
 

RE: How to set/define a variable from two variables?

(OP)
another little edit on the way to production:

execute(StrLineElements(0) + " = " + StrLineElements(1))
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close