Sign in to follow this  
Followers 0
IvanCodin

Read INI to GUI

3 posts in this topic

I am trying to read the ini file into the GUI and then provide a button to read the next section. I'll use it later to send to a file. I am stuck tring to read the sections into the GUI. I got the previous and next Sections working.

; Example 1
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
$sect=1
$read1 = IniRead( "myip.ini", "ipconfig" & $sect, "ip", "Error" )
$read2 = IniRead( "myip.ini", "ipconfig" & $sect, "subnet", "Error" )
$read3 = IniRead( "myip.ini", "ipconfig" & $sect, "gateway", "Error" )
; MsgBox(0, "Read ini", $read1 &  $read2 &  $read3)  ;  Used to test variables
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IP Address Information", 623, 444, 910, 183)
$Input1 = GUICtrlCreateInput($read1, 56, 40, 289, 24)
$Input2 = GUICtrlCreateInput($read2, 56, 72, 289, 24)
$Input3 = GUICtrlCreateInput($read3, 56, 104, 289, 24)
$Group1 = GUICtrlCreateGroup("IP Info", 24, 24, 345, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Next", 64, 168, 75, 25)
$Button2 = GUICtrlCreateButton("Previous", 280, 168, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   NextIP()
  Case $Button2
   PreviousIP()
EndSwitch
WEnd

Func NextIP()
$sect = $sect + 1
MsgBox(0, "Button1", $sect)
$read1 = IniRead( "myip.ini", "ipconfig" & $sect, "ip", "Error" )
$read2 = IniRead( "myip.ini", "ipconfig" & $sect, "subnet", "Error" )
$read3 = IniRead( "myip.ini", "ipconfig" & $sect, "gateway", "Error" )
EndFunc
Func PreviousIP()
If $sect <= 1 Then
$sect = 1
Else
$sect = $sect - 1
EndIf
MsgBox(0, "Button2", $sect)
$read1 = IniRead( "myip.ini", "ipconfig" & $sect, "ip", "Error" )
$read2 = IniRead( "myip.ini", "ipconfig" & $sect, "subnet", "Error" )
$read3 = IniRead( "myip.ini", "ipconfig" & $sect, "gateway", "Error" )
EndFunc

And here is the INI file:

[ipconfig1]

ip="192.168.1.1"

subnet="255.255.255.0"

gateway="192.168.1.1"

[ipconfig2]

ip="192.168.1.2"

subnet="255.255.255.0"

gateway="192.168.1.1"

[ipconfig3]

ip="192.168.1.3"

subnet="255.255.255.0"

gateway="192.168.1.1"

[ipconfig4]

ip="192.168.1.4"

subnet="255.255.255.0"

gateway="192.168.1.1"

Any suggestions?

Me

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You create the InputBoxes with the initial value, but if you load the new ini values to the variables, the input boxes need to be updated with this value, too:

; Example 1
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
$sect = 1
$read1 = IniRead("myip.ini", "ipconfig" & $sect, "ip", "Error")
$read2 = IniRead("myip.ini", "ipconfig" & $sect, "subnet", "Error")
$read3 = IniRead("myip.ini", "ipconfig" & $sect, "gateway", "Error")
; MsgBox(0, "Read ini", $read1 &  $read2 &  $read3)  ;  Used to test variables
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IP Address Information", 623, 444, 910, 183)
$Input1 = GUICtrlCreateInput($read1, 56, 40, 289, 24)
$Input2 = GUICtrlCreateInput($read2, 56, 72, 289, 24)
$Input3 = GUICtrlCreateInput($read3, 56, 104, 289, 24)
$Group1 = GUICtrlCreateGroup("IP Info", 24, 24, 345, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Next", 64, 168, 75, 25)
$Button2 = GUICtrlCreateButton("Previous", 280, 168, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            NextIP()
        Case $Button2
            PreviousIP()
    EndSwitch
WEnd

Func NextIP()
    $sect = $sect + 1
    MsgBox(0, "Button1", $sect)
    $read1 = IniRead("myip.ini", "ipconfig" & $sect, "ip", "Error")
    $read2 = IniRead("myip.ini", "ipconfig" & $sect, "subnet", "Error")
    $read3 = IniRead("myip.ini", "ipconfig" & $sect, "gateway", "Error")
    UpdateInput()
EndFunc   ;==>NextIP
Func PreviousIP()
    If $sect <= 1 Then
        $sect = 1
    Else
        $sect = $sect - 1
    EndIf
    MsgBox(0, "Button2", $sect)
    $read1 = IniRead("myip.ini", "ipconfig" & $sect, "ip", "Error")
    $read2 = IniRead("myip.ini", "ipconfig" & $sect, "subnet", "Error")
    $read3 = IniRead("myip.ini", "ipconfig" & $sect, "gateway", "Error")
    UpdateInput()
EndFunc   ;==>PreviousIP

Func UpdateInput()
    GUICtrlSetData($Input1,$read1)
    GUICtrlSetData($Input2,$read2)
    GUICtrlSetData($Input3,$read3)
EndFunc
Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites

Thanks!!! Simple but effective. I had forgot to run Tidy to clean up the layout. Thanks for the reminder!

Me

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