Jump to content

List function


Recommended Posts

If I use the

$mylist=GUICtrlCreateList ("", 176,32,450,200)

GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling

To create a list

Then populate the list with

For $i = 1 to 1

$var = FileSelectFolder("Choose a folder to backup!", "")

GUICtrlSetData($mylist, $var)

Next

That seems to work fine on screen.

But I'm stuck with

- Removing items from the list

and most important

Writing the list to a text file........

I was thinking about using an array but I can't make an array show in the list and it looks like the array is limited to 21 items :o

Really all i want to do is select folders, be able to remove them from the selection and then when done just dump them to a text file

c:\nick

c:\documents and settings

and so on

.........

!?

Link to comment
Share on other sites

Check out: _GUICtrlListDeleteItem in the help file (Beta?)

Well, ok.. after reading all afternoon maybe i need to forget this and use an array?

I can read a text file into an array, sort it but how can I display it on the screen in the list (i.e. make the list show the contents of the array)?

At least with an array i guess i have more control over doing things with the data

Any pointers on sorting an array and removing duplicates wouldbe good as well;)

Link to comment
Share on other sites

ok..!

This reads a text file, puts the lines into an array. and then converts the array to a string that is tab delimited.

am I half way there?

I now just need to be able to display this in a list box, without the tabs of course, really i guess i need to convert the array into lots of strings? and then display them in a table like so

$string1

$string2

corresponding to each line in the text file.

then lines can be added and removed etc

or am i completely wrong.

I guess its better to keep it all in the array but just dispplay the array on the screen somehow as a list box....

#include <GUIConstants.au3>

#include <GuiList.au3>

#include<Array.au3>

#include<File.au3>

;#NoTrayIcon

dim $folders

_FileReadToArray("test.txt",$folders)

$sArrayString = _ArrayToString($folders,@TAB, -1, -1)

Link to comment
Share on other sites

OK i've crackedmost of this by myself!!!

It reads and writes from a text file and populates a list

All I need now is how to remove the selected item from the list and array

#include <GUIConstants.au3>

#include <GuiList.au3>

#include<Array.au3>

#include<File.au3>

;#NoTrayIcon

dim $folders

$txtsize = FileGetSize("test.txt")

if $txtsize = 0 then

FileDelete ( "test.txt" )

endif

If FileExists("test.txt") Then

$CountLines = _FileCountLines("test.txt")

_FileReadToArray("test.txt",$folders)

Else

$file = FileOpen("test.txt", 1)

_FileReadToArray("test.txt",$folders)

_ArrayDelete($folders,0)

EndIf

;$sArrayString = _ArrayToString($folders,@TAB, -1, -1)

GUICreate("Q-Backup Setup and Installation Wizard",640,480)

GuiCtrlCreatePic("qbackup.gif",0,0, 175,35,$WS_EX_TRANSPARENT)

TrayTip("Welcome to Q-Backup", "The Q-Backup Setup and Installation Wizard will hold your hand all the way through getting Q-Backup working on your system!", 5, 1)

$filemenu = GuiCtrlCreateMenu ("File")

$fileitem = GuiCtrlCreateMenuitem ("Open...",$filemenu)

$recentfilesmenu = GuiCtrlCreateMenu ("Recent Files",$filemenu)

$separator1 = GuiCtrlCreateMenuitem ("",$filemenu)

$exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu)

$helpmenu = GuiCtrlCreateMenu ("?")

$aboutitem = GuiCtrlCreateMenuitem ("About",$helpmenu)

$mylist=GUICtrlCreateList ("", 176,50,450,200)

GUICtrlSetLimit(-1,200) ; to limit horizontal scrolling

$Add = GuiCtrlCreateButton ("Add folder",0,300,70,20)

$removebutton = GuiCtrlCreateButton ("Remove Folder",100,300,70,20)

$nextbutton = GuiCtrlCreateButton ("Next",200,300,70,20)

$clearbutton = GuiCtrlCreateButton ("Clear all",400,300,70,20)

GuiSetState()

for $i = 1 to $countlines

$sArrayString = _ArrayToString($folders,@TAB, $i,$i )

GUICtrlSetData($mylist, $sArrayString)

;MsgBox(0, "", $i & $sArrayString)

next

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE Or $msg = $nextbutton

$file=FileOpen("test.txt", 2)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open/create current configuration.")

Exit

EndIf

_FileWriteFromArray("test.txt",$folders,1)

$file=FileClose("test.txt")

exitloop

Case $msg = $fileitem

$file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")

If @error <> 1 Then GuiCtrlCreateMenuItem ($file,$recentfilesmenu)

Case $msg = $exititem

ExitLoop

Case $msg = $removebutton

$ret = _GUICtrlListDeleteItem ($mylist, 1)

If ($ret == $LB_ERR) Then

;MsgBox(16, "Error", "Unknown error from _GUICtrlListDeleteItem")

MsgBox(16, "Q-Backup!", "You should really leave at least one folder for backup, to clear all press the Clear Button")

EndIf

Case $msg = $clearbutton

_GUICtrlListClear ($mylist)

Case $msg = $Add

For $i = 1 to 1

$var = FileSelectFolder("Choose a folder to backup!", "")

if @error = 1 Then exitloop

$drivetype = DriveGetType( $var )

; for testing the drive type! MsgBox(4096, "Q-Backup", $drivetype)

if $drivetype = "Removable" Then

MsgBox(4096, "Q-Backup", "Sorry you cannot backup floppy or removable drives!")

exitloop

EndIf

if $drivetype = "CDROM" Then

MsgBox(4096, "Q-Backup", "Sorry you cannot backup CD-ROM or DVD-ROM Drives!")

exitloop

EndIf

if $drivetype = "Net1work" Then

MsgBox(4096, "Q-Backup", "Network shares are backup up in the next part of this Wizard!")

exitloop

EndIf

if $drivetype = "" Then

MsgBox(4096, "Q-Backup", "Sorry you cannot backup this location!")

exitloop

EndIf

_ArrayAdd ( $folders, $var )

GUICtrlSetData($mylist, $var)

Next

Case $msg = $aboutitem

Msgbox(0,"About","Q-Backup Setup and Installation Wizard version 2.00. ©2006 Qual-IT. www.qualit-uk.com/backup")

EndSelect

WEnd

GUIDelete()

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