Sign in to follow this  
Followers 0
shay

loop with many values

7 posts in this topic

HI

i need to write from one INI to other files

one way to do this is line by line, can i do that in loop or so so the code will be "nicer"??

see my example, ( i need to do that x10 )

$path = "c:\unit.ini"
$instance = ""
$pathTo = "C:\Program Files (x86)\LiveU1\config\"

;>>>>>> instance 1 <<<<<<
$port1 = IniRead($path, "instance1", "port1","default")
$port2 = IniRead($path, "instance1", "port2","default")
$name = IniRead($path, "instance1", "name","default")
IniWrite("C:\Program Files (x86)\LiveU1\config\server.ini","DMUX1","data_port", " " & $port1)
IniWrite("C:\Program Files (x86)\LiveU1\config\server.ini","DMUX1","control_port", " " & $port2)
IniWrite("C:\Program Files (x86)\LiveU1\config\server.ini","PLAYER", "unit_name", " " & $name)

;>>>>>> instance 2 <<<<<<
$port1 = IniRead($path, "instance2", "port1","default")
$port2 = IniRead($path, "instance2", "port2","default")
$name = IniRead($path, "instance2", "name","default")
IniWrite("C:\Program Files (x86)\LiveU2\config\server.ini","DMUX1","data_port", " " & $port1)
IniWrite("C:\Program Files (x86)\LiveU2\config\server.ini","DMUX1","control_port", " " & $port2)
IniWrite("C:\Program Files (x86)\LiveU2\config\server.ini","PLAYER", "unit_name", " " & $name)

;>>>>>> instance 3 <<<<<<
$port1 = IniRead($path, "instance3", "port1","default")
$port2 = IniRead($path, "instance3", "port2","default")
$name = IniRead($path, "instance3", "name","default")
IniWrite("C:\Program Files (x86)\LiveU3\config\server.ini","DMUX1","data_port", " " & $port1)
IniWrite("C:\Program Files (x86)\LiveU3\config\server.ini","DMUX1","control_port", " " & $port2)
IniWrite("C:\Program Files (x86)\LiveU3\config\server.ini","PLAYER", "unit_name", " " & $name)

"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$path = "c:\unit.ini"
$instance = ""
$pathTo = "C:\Program Files (x86)\LiveU1\config\"

For $i = 1 to 3
;>>>>>> instance 1 <<<<<<
$port1 = IniRead($path, eval("instance" & $i), "port1","default")
$port2 = IniRead($path, eval("instance" & $i), "port2","default")
$name = IniRead($path, eval("instance" & $i), "name","default")
IniWrite("C:\Program Files (x86)\" & eval("LiveU" & $i) & "\config\server.ini","DMUX1","data_port", " " & $port1)
IniWrite("C:\Program Files (x86)\" & eval("LiveU" & $i) & "\config\server.ini","DMUX1","control_port", " " & $port2)
IniWrite("C:\Program Files (x86)\" & eval("LiveU" & $i) & "\config\server.ini","PLAYER", "unit_name", " " & $name)

next

Something like this?

Edited by notsure

Share this post


Link to post
Share on other sites

Hi,

second try:

Global $port1, $port2, $name
$path = "c:\unit.ini"

For $i = 1 To 3
    _myiniread ($i)
    _myiniwrite ($i)
Next

Func _myiniread ($number)
    $port1 = IniRead($path, "instance" & $number, "port1","default")
    $port2 = IniRead($path, "instance" & $number, "port2","default")
    $name = IniRead($path, "instance" & $number, "name","default")
EndFunc

Func _myiniwrite ($number)
    IniWrite("C:\Program Files (x86)\LiveU" & $number & "\config\server.ini","DMUX1","data_port", " " & $port1)
    IniWrite("C:\Program Files (x86)\LiveU" & $number & "\config\server.ini","DMUX1","control_port", " " & $port2)
    IniWrite("C:\Program Files (x86)\LiveU" & $number & "\config\server.ini","PLAYER", "unit_name", " " & $name)
EndFunc

;-))

Stefan

Share this post


Link to post
Share on other sites

thenks you all

always good to learn how to improve my code!! :mellow:


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

Hi Stefan

i try using your script with partially success,

i increase the loop to 10 cycles.

i have problem in cycles above 7,

some time the "IniWrite" return with the default parameters,

i try to add "sleep" after "IniWrite" but still problem exist.

any idea?


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

Hi,

i think you have problems with iniread.

For debugging:

For $i = 1 To 3
    _myiniread ($i)
    ConsoleWrite ("Port1: " & $port1 & " " & "Port2: " & $port2 & " " & "Name: " & $name & @crlf)
    _myiniwrite ($i)
Next

You may post your ini file for further investigation or try to recode with suggestions from @MvGulik.

;-))

Stefan

Share this post


Link to post
Share on other sites

Hi,

i think you have problems with iniread.

For debugging:

For $i = 1 To 3
 _myiniread ($i)
 ConsoleWrite ("Port1: " & $port1 & " " & "Port2: " & $port2 & " " & "Name: " & $name & @crlf)
 _myiniwrite ($i)
Next

You may post your ini file for further investigation or try to recode with suggestions from @MvGulik.

;-))

Stefan

indeed problem in my INI file,

all working fine

once again thanks :mellow:


"If the facts don't fit the theory, change the facts." Albert Einstein

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0