Jump to content

How To...


Sobiech
 Share

Recommended Posts

You will not be able to use a "for loop" with different names

(unless they are in an array, but that is another story and more complicated)

And no one here thought to use ControlGetText and ControlSetText? that way you can keep whatever names you've got already.

$INI = "MyINI.ini"

$Form1 = GUICreate("Massive over-exaggeration FTW", 800, 600)

For $x= 8 To 600 Step 130
   For $y = 8 To 400 Step 24
      GUICtrlCreateInput("", $x, $y, 121, 21)
   Next
Next

For $n = 1 To 85
   ControlSetText ($Form1, "", "Edit" & $n, IniRead ($INI, "Inputs", "Input" & $n , ""))
Next

$Save = GUICtrlCreateButton("Save values", 8, 450, 100, 100)

GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $save
         For $n = 1 To 85
            ToolTip ("saving value " & $n)
            IniWrite ($INI, "Inputs", "Input" & $n, ControlGetText ($Form1, "", "Edit" & $n))
         Next
      Case -3
         Exit
   EndSwitch
WEnd

Edit:

Now has some nice functions that read and restore every single edit control from any window to a given ini file.

$Form1 = GUICreate("Massive over-exaggeration FTW", 800, 600)

For $x= 8 To 600 Step 130
   For $y = 8 To 400 Step 24
      GUICtrlCreateInput("", $x, $y, 121, 21)
   Next
Next

$Save = GUICtrlCreateButton("Save values", 8, 450, 100, 100)
$Restore = GUICtrlCreateButton("Restore values", 112, 450, 100, 100)

GUISetState(@SW_SHOW)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $save
         _SaveAll ($Form1)
      Case $Restore
         _RestoreAll ($Form1)
      Case -3
         Exit
   EndSwitch
WEnd

Func _RestoreAll ($hWnd, $sIni = "")
   If Not WinExists ($hWnd) Then Return SetError (1, 0, 0)
   If $sIni = "" Then $sIni = @ScriptDir & "\Inputs.ini"

   Local $sText, $i = 0
   While 1
      $i += 1
      ControlGetHandle ($hWnd, "", "Edit" & $i)
      If @Error Then ExitLoop

      ControlSetText ($hWnd, "", "Edit" & $i, IniRead ($sIni, "Inputs", "Input" & $i, ""))
   WEnd
   Return SetExtended ($i, 1)
Endfunc ; ==> _RestoreAll


Func _SaveAll ($hWnd, $sIni = "")
   If Not WinExists ($hWnd) Then Return SetError (1, 0, 0)
   If $sIni = "" Then $sIni = @ScriptDir & "\Inputs.ini"

   Local $sText, $i = 0
   While 1
      $i += 1
      ControlGetHandle ($hWnd, "", "Edit" & $i)
      If @Error Then ExitLoop

      IniWrite ($sIni, "Inputs", "Input" & $i, ControlGetText ($hWnd, "", "Edit" & $i))
   WEnd

   Return SetExtended ($i, 1)
EndFunc ; ==> _SaveAll
Edited by Mat
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...