Jump to content

Read next entry in inifile on clicking 'NEXT'


dash007
 Share

Recommended Posts

Hi all,

Below is my code example. When you run the code, it will search the first entry in the inifile (movies.ini) and show that in the input box. When you click the 'Check' button it will show the corresponding value (found in the movies.ini) and paste this in the GUI. So far so good.

What I don't know is how can I enable the 'NEXT' button such that when I click on it, it will search the ini and get the entry that is immediately following the entry that is already in the GUI (Input1). For example, I have 'Monday' on the GUI when the GUI is launched. This is because 'Monday' is the first entry in the ini. When I click on 'NEXT' I want 'Tuesday' to populate the Input1 field (as Tuesday is the next entry in the ini).

#include <GUIConstants.au3>
; == GUI generated with Koda ==

$Form1 = GUICreate("What2See", 338, 206, 192, 125)
$Check = GUICtrlCreateButton("Check", 64, 168, 85, 25)
$Next = GUICtrlCreateButton("Next", 192, 168, 85, 25)
$Input1 = GUICtrlCreateInput("", 72, 24, 193, 21, -1, $WS_EX_CLIENTEDGE)
$Edit1 = GUICtrlCreateEdit("", 40, 64, 265, 89, -1, $WS_EX_CLIENTEDGE)

$var = IniReadSection("movies.ini", "Movies")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
    GUICtrlSetData($Input1,$var[1][0])
    Next
EndIf


GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Check
        GUICtrlSetData($Edit1, IniRead("movies.ini", "Movies",GUICtrlRead($Input1),"No File"))

    Case $msg = $Next
                ;"xxxxxxxxxxxxxx  HELP NEEDED HERE  xxxxxxxxxxxxxxx"
    EndSelect
WEnd
Exit

The inifile is below (please name it movies.ini and place in same directory as script):

[Movies]
Monday=Will & Grace, Simpsons, Friends
Tuesday=Lost, Revelations
Wednesday=SouthPark, CSI
Thursday=Friends, Travel
Friday=Movie, Simpsons
Saturday=Soccer
Sunday=Friends
Other (DVD etc)=Madagaskar

Can somebody shed some light on this please.... Thanks in advance :o

Link to comment
Share on other sites

what are you doing?

#include <GUIConstants.au3>
; == GUI generated with Koda ==

$Form1 = GUICreate("What2See", 338, 206, 192, 125)
$Check = GUICtrlCreateButton("Check", 64, 168, 85, 25)
$Next = GUICtrlCreateButton("Next", 192, 168, 85, 25)
$Input1 = GUICtrlCreateInput("", 72, 24, 193, 21, -1, $WS_EX_CLIENTEDGE)
$Edit1 = GUICtrlCreateEdit("", 40, 64, 265, 89, -1, $WS_EX_CLIENTEDGE)

$var = IniReadSection("movies.ini", "Movies")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    $i = 1
    GUICtrlSetData($Input1,$var[$i][0])
EndIf


GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Check
        GUICtrlSetData($Edit1, $var[$i][1])

    Case $msg = $Next
$i = $i + 1
if $i > 8 then $i = $i - 8
guictrlsetdata ($input1, $var[$i][0])
guictrlsetdata ($edit1, $var[$i][1])
    EndSelect
WEnd
Exit

this should work

edit: didn't realize you had "others"

Edited by Nuffilein805
Link to comment
Share on other sites

Hi Nuffilein805,

Thanks for the idea and script :o I have modified it slightly (taken off the "Check" button and also modified it to loop based on the number of entries in the ini rather than hardcode the value of '8'). This is incase I decide to add any additional entries into the ini :geek:

The new code (if anyone is interested) is:

#include <GUIConstants.au3>
; == GUI generated with Koda ==

$Form1 = GUICreate("What2See", 338, 206)
$Next = GUICtrlCreateButton("Next", 126, 168, 85, 25)
$Input1 = GUICtrlCreateInput("", 72, 24, 193, 21, -1, $WS_EX_CLIENTEDGE)
$Edit1 = GUICtrlCreateEdit("", 40, 64, 265, 89, -1, $WS_EX_CLIENTEDGE)

$var = IniReadSection("movies.ini", "Movies")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    $i = 1
    GUICtrlSetData($Input1,$var[$i][0])
    GUICtrlSetData($Edit1, $var[$i][1])
EndIf


GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
    Case $msg = $Next
        guictrlsetdata ($edit1, "")
        $i = $i + 1
    
    if $i > $var[0][0] then $i = $i - $var[0][0]
    guictrlsetdata ($input1, $var[$i][0])
    GUICtrlSetData($Edit1, $var[$i][1])
    EndSelect
WEnd
Exit
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...