Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set/define a variable from two variables?

Status
Not open for further replies.

stable-x

Systems Engineer
Jun 2, 2023
4
DE
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:

[pre]
################## 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
##############################################
[/pre]

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

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

Thanks a lot!
 
[SOLVED] Ooops, never ask: the solution is around the corner ;-)

[pre]
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
[/pre]

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

[pre]
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
[/pre]
 
another little edit on the way to production:

[pre]
execute(StrLineElements(0) + " = " + StrLineElements(1))
[/pre]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top