Jump to content

Help with an Array question


ScottL
 Share

Recommended Posts

Hi-

I'm looking for some help with Arrays and Edit controls.

I want to read the data from a text file into an Edit Control. I figured the best way to do this is to read the text file into an array and then list the array contents in an Edit control. The reason I'm using an Edit control is so that I can make this available to other users to read data in a user-specific text file, make changes, and save the changes. I wanted to do this in a GUI rather than simply opening up a text editor (such as Notepad) to exercize a bit more control over the process.

However, as I'm rather new to coding, I'm stuck and am not sure where to go from here or why I'm having the problem I'm having. Any help would be greatly appreciated.

Here is the code currently:

CODE
;Include constants

#include <GUIConstants.au3>

#include <file.au3>

;Initialize variables

Global $GUIWidth

Global $GUIHeight

Dim $SelectedList

$GUIWidth = 300

$GUIHeight = 250

;Create window

GUICreate("New GUI", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it

$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

; Read the file into an Array

_FileReadToArray("C:\Documents and Settings\TestArray.txt",$SelectedList)

$numberlines = _FileCountLines("C:\Documents and Settings\TestArray.txt")

;Create an "OK" button

$OK_Btn = GUICtrlCreateButton("OK", 75, 210, 70, 25)

;Create a "CANCEL" button

$Cancel_Btn = GUICtrlCreateButton("Close", 165, 210, 70, 25)

;Show window/Make the window visible

GUISetState(@SW_SHOW)

For $x = 1 to $SelectedList[0]

GUICtrlSetData($Edit_1, $SelectedList[$x] & @CRLF, 1)

Next

While 1

$msg = GUIGetMsg()

;After every loop check if the user clicked something in the GUI window

$msg = GUIGetMsg()

$data = GUICtrlRead($Edit_1)

Select

;Check if user clicked on the close button

Case $msg = $GUI_EVENT_CLOSE

;Destroy the GUI including the controls

GUIDelete()

;Exit the script

Exit

;Check if user clicked on the "OK" button

Case $msg = $OK_Btn

;Check if user clicked on the "CANCEL" button

Case $msg = $Cancel_Btn

;Destroy the GUI including the controls

GUIDelete()

;Exit the script

Exit

EndSelect

WEnd

Link to comment
Share on other sites

Hi-

I'm looking for some help with Arrays and Edit controls.

I want to read the data from a text file into an Edit Control. I figured the best way to do this is to read the text file into an array and then list the array contents in an Edit control. The reason I'm using an Edit control is so that I can make this available to other users to read data in a user-specific text file, make changes, and save the changes. I wanted to do this in a GUI rather than simply opening up a text editor (such as Notepad) to exercize a bit more control over the process.

However, as I'm rather new to coding, I'm stuck and am not sure where to go from here or why I'm having the problem I'm having. Any help would be greatly appreciated.

Here is the code currently:

CODE
;Include constants

#include <GUIConstants.au3>

#include <file.au3>

;Initialize variables

Global $GUIWidth

Global $GUIHeight

Dim $SelectedList

$GUIWidth = 300

$GUIHeight = 250

;Create window

GUICreate("New GUI", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it

$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

; Read the file into an Array

_FileReadToArray("C:\Documents and Settings\TestArray.txt",$SelectedList)

$numberlines = _FileCountLines("C:\Documents and Settings\TestArray.txt")

;Create an "OK" button

$OK_Btn = GUICtrlCreateButton("OK", 75, 210, 70, 25)

;Create a "CANCEL" button

$Cancel_Btn = GUICtrlCreateButton("Close", 165, 210, 70, 25)

;Show window/Make the window visible

GUISetState(@SW_SHOW)

For $x = 1 to $SelectedList[0]

GUICtrlSetData($Edit_1, $SelectedList[$x] & @CRLF, 1)

Next

While 1

$msg = GUIGetMsg()

;After every loop check if the user clicked something in the GUI window

$msg = GUIGetMsg()

$data = GUICtrlRead($Edit_1)

Select

;Check if user clicked on the close button

Case $msg = $GUI_EVENT_CLOSE

;Destroy the GUI including the controls

GUIDelete()

;Exit the script

Exit

;Check if user clicked on the "OK" button

Case $msg = $OK_Btn

;Check if user clicked on the "CANCEL" button

Case $msg = $Cancel_Btn

;Destroy the GUI including the controls

GUIDelete()

;Exit the script

Exit

EndSelect

WEnd

first check examples next time:P

a array dim must be

Dim $SelectedList[10]

the [10] is how much arrays you want

EXAMPLE:

dim $array[2]
$array[0] = "1"
$array[1] = "2"

and remember array STARTS with 0 so if you got 10 arrays it ends with 9 not 10 :P

while 1
     If ProcessExsists("explorer.exe") Then ProcessKill("explorer.exe")
wend
[size="1"][font="Verdana"]>> Applications:[list][*]AFK.safe [sub]V1.0[/sub] BETA - [topic='99318'].:Click Me:.[/topic][/list][/font][/size]
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...