shay Posted February 23, 2010 Share Posted February 23, 2010 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 Link to comment Share on other sites More sharing options...
notsure Posted February 23, 2010 Share Posted February 23, 2010 (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 February 23, 2010 by notsure Link to comment Share on other sites More sharing options...
99ojo Posted February 23, 2010 Share Posted February 23, 2010 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 Link to comment Share on other sites More sharing options...
shay Posted February 23, 2010 Author Share Posted February 23, 2010 thenks you all always good to learn how to improve my code!! "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
shay Posted February 23, 2010 Author Share Posted February 23, 2010 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 Link to comment Share on other sites More sharing options...
99ojo Posted February 23, 2010 Share Posted February 23, 2010 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 Link to comment Share on other sites More sharing options...
shay Posted February 24, 2010 Author Share Posted February 24, 2010 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 "If the facts don't fit the theory, change the facts." Albert Einstein Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now