Jump to content

text file to gui


svss
 Share

Recommended Posts

Hi,

i tried to locate some info in the forum but so far all code i tried failed.

Here is what i am trying to achieve

I have a text file with usernames

user1

user2

user3

etc.

I am trying to create a gui with checkboxes for each user and then save the checkoxed users to a

new text file.

Could someone shine some light on this one.

Thx in advance

S.

Link to comment
Share on other sites

To read the lines from a file and checkbox them try this

#include <GUIConstants.au3>

GuiCreate( "Your checkbox script" )

GUISetState ()

$msg = 0

$read=FileReadLine( "yourfile.txt", 1)
$read1=FileReadLine( "yourfile.txt", 2)
$read2=FileReadLine( "yourfile.txt", 3)

$1=GUICtrlCreateCheckbox( $read, 5, 5)
$2=GUICtrlCreateCheckbox( $read1, 5, 30)
$3=GUICtrlCreateCheckbox( $read2, 5, 55)

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

To write to file use the comand FileWrite...but I can't help you more because i don't know how...hope that helped

Link to comment
Share on other sites

You could look at using _FileReadToArray() and _FileWriteFromArray().

This example may help to give you some direction. I do not want to spoil your fun and do too much... :P

#include <GUIConstants.au3>
#include <File.au3>

Global $aArray
_FileReadToArray(@ScriptDir & '\test.txt', $aArray)
If @error Then
    MsgBox(0x1, 'Error', "_FileReadToArray('test.txt', $aArray)")
    Exit
EndIf

GUICreate('Title')
Global $checkbox[$aArray[0]+1]
For $i = 1 To $aArray[0]
    $checkbox[$i] = GUICtrlCreateCheckbox($aArray[$i], 10, 18 * $i)
Next
$button_process = GUICtrlCreateButton('&Process', 100, 350, 80)
$button_exit = GUICtrlCreateButton('E&xit', 200, 350, 80)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button_exit
            Exit
        Case $msg = $button_process
            For $i = 1 To $aArray[0]
                ; Check state of checkboxes and do conditional action
                If GUICtrlRead($checkbox[$i]) = $GUI_CHECKED Then
                    $state = 'checked'
                Else
                    $state = 'unchecked'
                EndIf
                MsgBox(0x40000, $aArray[$i], $state)
            Next
    EndSelect
WEnd

Put some names into a text file called test.txt to see the example run.

Link to comment
Share on other sites

Thanks for the fast reply.

I got two issues with your script:

1)i have a list of hundred or so users and need to be able to browse the window.

I inserted the following in the script.I see the scroll button on the right side but i

am not able to go up or down?

GUICreate('Users to Move', 400, 500, -1, -1, $WS_VSCROLL)

2)I try to extract the checkboxed users to a text file with

_FileWriteToArray

but it gives me the following error

ERROR: _FileWriteToArray(): undefined function

Is there any other way to do this?

Thanks again for all your help

Very much appreciated

S.

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...