Problem with regread/regwrite

11/04/2013 17:11 mlukac89#1
hi

im trying to write data from my gui to registry but it write some dummy data

here is code

Code:
$Input1 = GUICtrlCreateInput("1000", 18, 74, 38, 17, 0x0001)
$Input2 = GUICtrlCreateInput("1000", 72, 74, 38, 17, 0x0001)
$Input3 = GUICtrlCreateInput("1000", 125, 74, 38, 17, 0x0001)
$Input4 = GUICtrlCreateInput("1000", 179, 74, 38, 17, 0x0001)
$Input5 = GUICtrlCreateInput("1000", 232, 74, 38, 17, 0x0001)
$Input6 = GUICtrlCreateInput("1000", 286, 74, 38, 17, 0x0001)
$Input7 = GUICtrlCreateInput("1000", 339, 74, 38, 17, 0x0001)
$Input8 = GUICtrlCreateInput("1000", 393, 74, 38, 17, 0x0001)
$Input9 = GUICtrlCreateInput("1000", 446, 74, 38, 17, 0x0001)
$Input10 = GUICtrlCreateInput("1000", 500, 74, 38, 17, 0x0001)
$Input11 = GUICtrlCreateInput("3", 30, 46, 17, 17, 0x0001)
$Input12 = GUICtrlCreateInput("4", 84, 46, 17, 17, 0x0001)
$Input13 = GUICtrlCreateInput("5", 137, 46, 17, 17, 0x0001)
$Input14 = GUICtrlCreateInput("6", 190, 46, 17, 17, 0x0001)
$Input15 = GUICtrlCreateInput("7", 243, 46, 17, 17, 0x0001)
$Input16 = GUICtrlCreateInput("8", 296, 46, 17, 17, 0x0001)
$Input17 = GUICtrlCreateInput("9", 350, 46, 17, 17, 0x0001)
$Input18 = GUICtrlCreateInput("0", 404, 46, 17, 17, 0x0001)
$Input19 = GUICtrlCreateInput("-", 457, 46, 17, 17, 0x0001)
$Input20 = GUICtrlCreateInput("+", 510, 46, 17, 17, 0x0001)



and function to write data

Func _addToRegistry()
	; create key in registry
	RegWrite("HKEY_CURRENT_USER\Software\Test")

	; write keys and times to registry
	RegWrite("HKEY_CURRENT_USER\Software\Test", "Keys", "REG_MULTI_SZ", $Input11 & @LF & $Input12 & @LF & $Input13 & @LF & $Input14 & @LF & $Input15 & @LF & $Input16 & @LF & $Input17 & @LF & $Input18 & @LF & $Input19 & @LF & $Input20)
	RegWrite("HKEY_CURRENT_USER\Software\Test", "Times", "REG_MULTI_SZ", $Input1 & @LF & $Input2 & @LF & $Input3 & @LF & $Input4 & @LF & $Input5 & @LF & $Input6 & @LF & $Input7 & @LF & $Input8 & @LF & $Input9 & @LF & $Input10)
EndFunc
when i run this it write me this to registry

keys :
14
15
16
17
18
19
20
21
22
23

times :
4
5
6
7
8
9
10
11
12
13


and it need to write for keys 3 4 5 6 7 8 9 0 ' +
and for times 1000 1000 1000 1000 1000 etc...

anyone know the problem ?
11/04/2013 17:21 alpines#2
Why don't you use array for the controls? It would be much better if you use them.
By the way you're writing the handle of the control inside the Registry Entry.
You have to use GUICtrlRead($hControl) to get the data inside.

Don't forget to add #RequireAdmin, some users need admin rights to access or edit the registry.
11/04/2013 17:41 mlukac89#3
oh thx for that i forgot GUICtrlRead() :) and i dont know how tu use arrays im not that good in autoit ;(

how can i now read from registry into the input fields i used this and this list me all data in first input
Code:
$readTime1 = RegRead("HKEY_CURRENT_USER\Software\Test", "Times")
$Input1 = GUICtrlSetData($Input1, $readTime1)
MsgBox(0, "Time", $readTime1)
but is i use this

Code:
$readTime1 = RegRead("HKEY_CURRENT_USER\Software\Test\Times", $Input1)
$Input1 = GUICtrlSetData($Input1, $readTime1)
i get blank result.

My question is how to take that result and put in input field separate ?
11/05/2013 16:59 berkay2578#4
Code:
$_rd = RegRead("HKEY_CURRENT_USER\Software\Test", "Times")
$_str = StringSplit($_rd, @LF)
;GUICtrlSetData($Input1, $_str[1])

For $i = 1 to UBound($_str) - 1
    MsgBox(0, "_str array nr: " & $i, $_str[$i])
Next
and here's the code for the *array controls* :p
Code:
Global $txtBOX[5]

$hGUI = GUICreate("", 120, 160)

For $i = 0 To 4
    $txtBOX[$i] = GUICtrlCreateInput("", 10, 10 + ($i * 30), 100, 20)
Next
; if you don't want to use an automated for loop do it like this
; $txtBOX[0] = GUICtrlCreateInput("1000", 18, 74, 38, 17, 0x0001)
; $txtBOX[1] = GUICtrlCreateInput("1000", 72, 74, 38, 17, 0x0001)
; $txtBOX[2] = GUICtrlCreateInput("1000", 125, 74, 38, 17, 0x0001)

GUISetState(@SW_SHOW, $hGUI)

_SetData()

While 1
	Switch GUIGetMsg()
		Case -3
			Exit
	EndSwitch
WEnd

Func _SetData()
	$_rd = RegRead("HKEY_CURRENT_USER\Software\Test", "Keys")
	$_str = StringSplit($_rd, @LF)

	For $i = 1 to UBound($_str) - 1
		GUICtrlSetData($txtBOX[$i-1], $_str[$i])
	Next
EndFunc