Jump to content
Sign in to follow this  
yousefsamy

here is a problem with saving a list

Recommended Posts

i want to save contains of list(names-class-number) in a text file..

here is my code :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>


$Form1 = GUICreate("Form1", 770, 500, 195, 134)
$List = GUICtrlCreateListView("Name|Class|Number",240,250,300,200)
$Button1 = GUICtrlCreateButton("Button1", 240, 168, 193, 41)
$Button2 = GUICtrlCreateButton("save", 50, 168, 193, 41)
$Input1 = GUICtrlCreateInput("Name", 260, 64, 249, 21)
$Input2 = GUICtrlCreateInput("Class", 0, 64, 249, 21)
$Input3 = GUICtrlCreateInput("Number", 550, 64, 249, 21)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $readN = GUICtrlRead($Input1)
            $readC = GUICtrlRead($Input2)
            $readNum = GUICtrlRead($Input3)
            GUICtrlCreateListViewItem($readN&"|"&$readC&"|"&$readNum, $List)
        Case $Button2
            $s = GUICtrlRead($List)
            $ss = FileSaveDialog("save",@DesktopDir,"TXT (*.txt)")
            FileWrite($ss,$s)





    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

really i have made some thing to save only line by line in a text file 

here is my code :

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>


$Form1 = GUICreate("Form1", 770, 500, 195, 134)
$List = GUICtrlCreateListView("Name|Class|Number",240,250,300,200)
$Button1 = GUICtrlCreateButton("Button1", 240, 168, 193, 41)
$Button2 = GUICtrlCreateButton("save", 50, 168, 193, 41)
$Input1 = GUICtrlCreateInput("Name", 260, 64, 249, 21)
$Input2 = GUICtrlCreateInput("Class", 0, 64, 249, 21)
$Input3 = GUICtrlCreateInput("Number", 550, 64, 249, 21)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $readN = GUICtrlRead($Input1)
            $readC = GUICtrlRead($Input2)
            $readNum = GUICtrlRead($Input3)
            $o = GUICtrlCreateListViewItem($readN&"|"&$readC&"|"&$readNum, $List)
            $s = GUICtrlRead($o)
            FileWriteLine(@WorkingDir&"\info.txt",$s)
    EndSwitch
WEnd

but i want to know can i save all things in the list by one click not line by line?

Edited by yousefsamy

Share this post


Link to post
Share on other sites

yousefsamy,

You were pretty close - this works for me: ;)

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 770, 500, 195, 134)

$List = GUICtrlCreateListView("Name|Class|Number", 240, 250, 300, 200)

$Button1 = GUICtrlCreateButton("Button1", 240, 168, 193, 41)
$Button2 = GUICtrlCreateButton("Save", 50, 168, 193, 41)
$Input1 = GUICtrlCreateInput("Name", 260, 64, 249, 21)
$Input2 = GUICtrlCreateInput("Class", 0, 64, 249, 21)
$Input3 = GUICtrlCreateInput("Number", 550, 64, 249, 21)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; Create text
            $sItemText = GUICtrlRead($Input1) & "|" & GUICtrlRead($Input2) & "|" & GUICtrlRead($Input3)
            ; Add text to ListView
            GUICtrlCreateListViewItem($sItemText, $List)
            ; Add text to file
            FileWriteLine(@ScriptDir & "\info.txt", $sItemText)
    EndSwitch
WEnd
As usual, please ask if you have any questions. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

- but it seems my second code only save 1 line no more? (I want to save all lines in the list by one click)

- and i have another question if i have a txt file have like 1000 line can i show them in the list?(Reload)

Edited by yousefsamy

Share this post


Link to post
Share on other sites

yousefsamy,

Some people are never satisfied: ;)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>

; Declare an array to hold the ListView content
Global $aLVText

$sFile = @ScriptDir & "\info.txt"

$Form1 = GUICreate("Form1", 770, 500, 195, 134)

$List = GUICtrlCreateListView("Name|Class|Number", 240, 250, 300, 200)

$Button1 = GUICtrlCreateButton("Save", 240, 168, 193, 41)
$Button2 = GUICtrlCreateButton("Load", 50, 168, 193, 41)
$Input1 = GUICtrlCreateInput("Name", 260, 64, 249, 21)
$Input2 = GUICtrlCreateInput("Class", 0, 64, 249, 21)
$Input3 = GUICtrlCreateInput("Number", 550, 64, 249, 21)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; Create text
            $sItemText = GUICtrlRead($Input1) & "|" & GUICtrlRead($Input2) & "|" & GUICtrlRead($Input3)
            ; Add text to ListView
            GUICtrlCreateListViewItem($sItemText, $List)

            ; Now read ListView contents into an array

            ; Get count of items
            $iCount = _GUICtrlListView_GetItemCount($List)
            ; Create array to hold text
            Global $aLVText[$iCount]
            ; Now loop through the ListView and store contents
            For $i = 0 To $iCount - 1
                $aLVText[$i] = _GUICtrlListView_GetItemTextString($List, $i)
            Next

            ; Delete any existing file
            If FileExists($sFile) Then
                FileDelete($sFile)
            EndIf
            ; Write new file
            _FileWriteFromArray($sFile, $aLVText)

        Case $Button2
            ; Load file into an array
            _FileReadToArray($sFile, $aLVText, $FRTA_NOCOUNT)
            ; Load items into the ListView
            If Not @error Then
                For $i = 0 To UBound($aLVText) - 1
                    GUICtrlCreateListViewItem($aLVText[$i], $List)
                Next
            EndIf

    EndSwitch
WEnd
All clear? :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

yousefsamy,

 

i will try first if i can't do it i will ask you

An excellent plan. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

yousefsamy,

If you want to get a really flexible ListView I suggest you look at my GUIListViewEx UDF (the link is in my sig) which allows you to add, delete, move, edit, sort and drag items. Very easy to use and I will be happy to guide you through any integration problems. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

×
×
  • Create New...