Sign in to follow this  
Followers 0
fikri1979

Load and Save File

13 posts in this topic

#1 ·  Posted (edited)

hello all.....

how to create script when I click the "SAVE" button it will be saved in format ".ini " as sample : config.ini  ; config2.ini etc

and if i click the "LOAD" button, it will look for the file load ".ini" so that it appears in GUI..

post-81604-0-96433300-1385625999_thumb.j if click Save Button will appear post-81604-0-65110400-1385626396_thumb.j and  if click Load Button will appear post-81604-0-79246000-1385626048_thumb.j

can give me example please?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 395, 172, 192, 114)
$inputhost = GUICtrlCreateInput("Input1", 96, 32, 145, 21)
$Label1 = GUICtrlCreateLabel("Host", 32, 32, 26, 17)
$inputusername = GUICtrlCreateInput("Input2", 96, 64, 145, 21)
$Label2 = GUICtrlCreateLabel("Username", 32, 72, 52, 17)
$inputpassword = GUICtrlCreateInput("Input3", 96, 96, 145, 21)
$Label3 = GUICtrlCreateLabel("Password", 32, 104, 50, 17)
$btnsave = GUICtrlCreateButton("SAVE", 280, 48, 73, 25)
$btnload = GUICtrlCreateButton("LOAD", 280, 88, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnsave
            IniWrite(@ScriptDir & "\Config.ini", "Data", "Host", GUICtrlRead($inputhost))
            IniWrite(@ScriptDir & "\Config.ini", "Data", "Username", GUICtrlRead($inputusername))
            IniWrite(@ScriptDir & "\Config.ini", "Data", "Password", GUICtrlRead($inputpassword))
        Case $btnload

    EndSwitch
WEnd
Edited by fikri1979

Share this post


Link to post
Share on other sites



fikri1979,

Look at FileOpenDialog and FileSaveDialog in the Help file. :)

But note that @WorkingDir is changed after each use of these functions, so you might need to change it back using FileChangeDir. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

fikri1979,

Look at FileOpenDialog and FileSaveDialog in the Help file. :)

But note that @WorkingDir is changed after each use of these functions, so you might need to change it back using FileChangeDir. ;)

M23

how to bring it in inputbox automatically when file select? can give me example?

Share this post


Link to post
Share on other sites

fikri1979,

 

how to bring it in inputbox automatically when file select

The 2 dialogs return the selected file name - so store it in a variable and use GUICtrlSetData to put it into the input. :)

Try and code it yourself and see how you get on - come back if you run into difficulties. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

#5 ·  Posted (edited)

Hi fikri1979,

  Just as an additional tip that might eventually save you some time and trouble.

The IniRead and IniWrite functions will automatically save to the ini file without the use of the save and open dialog boxes.

Just tie the Iniread with GUICtrlSetData function to your load button

and the iniwrite with GUICtrlRead to the save button.

Bill

Edited by billo

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi fikri1979,

  Just as an additional tip that might eventually save you some time and trouble.

The IniRead and IniWrite functions will automatically save to the ini file without the use of the save and open dialog boxes.

Just tie the Iniread with GUICtrlSetData function to your load button

and the iniwrite with GUICtrlRead to the save button.

Bill

thanks for the suggestion, but I want to save the file more than one file as shown below for example :

1.post-81604-0-84942400-1385643301_thumb.j

2.post-81604-0-83270400-1385643337_thumb.j when the load file "1.ini" it will show the data in a form that has been stored previously

3.post-81604-0-39010500-1385643358_thumb.j

4.post-81604-0-76534200-1385643374_thumb.j when the load file '2.ini" it will show the data in a form that has been stored previously

5.post-81604-0-89052800-1385643392_thumb.j

Edited by fikri1979

Share this post


Link to post
Share on other sites

fikri1979,

Look at FileOpenDialog and FileSaveDialog in the Help file. :)

But note that @WorkingDir is changed after each use of these functions, so you might need to change it back using FileChangeDir. ;)

M23

i have tried like this scrip below...how to fix it button load and use file open dialog? when click button load will appear data in inputbox

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

Global $readproxy
Global $readportproxy
Global $readhost
Global $readporthost
Global $readusername
Global $readpassword


#Region ### START Koda GUI section ###
$formdata = GUICreate("data", 350, 280, 200, 114)
GUISetBkColor(0xC0DCC0)
$server = GUICtrlCreateGroup("Server", 8, 8, 225, 97)
$inputhost = GUICtrlCreateInput($readhost, 88, 32, 137, 21)
$Label1 = GUICtrlCreateLabel("Host", 24, 32, 26, 17)
$Label2 = GUICtrlCreateLabel("Port", 24, 64, 23, 17)
$inputporthost = GUICtrlCreateInput($readporthost, 88, 64, 137, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("User", 8, 112, 225, 97)
$Label3 = GUICtrlCreateLabel("Username", 24, 136, 52, 17)
$inputusername = GUICtrlCreateInput($readusername, 88, 136, 137, 21)
$Label4 = GUICtrlCreateLabel("Password", 24, 168, 50, 17)
$inputpassword = GUICtrlCreateInput($readpassword, 88, 168, 137, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Proxy", 8, 216, 225, 49)
$inputproxy = GUICtrlCreateInput("127.0.0.1", 88, 232, 137, 21)
$Label5 = GUICtrlCreateLabel("Proxy", 16, 232, 30, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$btnsimpan = GUICtrlCreateButton("SIMPAN", 248, 240, 89, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$btnload = GUICtrlCreateButton("LOAD", 248, 200, 89, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group3 = GUICtrlCreateGroup("Akun", 248, 8, 89, 177)
$AkunRadio1 = GUICtrlCreateRadio("Akun1", 256, 32, 65, 17)
$AkunRadio2 = GUICtrlCreateRadio("Akun2", 256, 56, 65, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnsimpan
            save()
        Case $btnload
            load()

    EndSwitch
WEnd

Func save()
    If GUICtrlRead($AkunRadio1) = $gui_checked Then     ;jika diklik radio button1 mka akan tersimpan di file config.ini
        IniWrite(@ScriptDir & "\Config.ini", "Data", "Host", GUICtrlRead($inputhost))
        IniWrite(@ScriptDir & "\Config.ini", "Data", "Port Host", GUICtrlRead($inputporthost))
        IniWrite(@ScriptDir & "\Config.ini", "Data", "Proxy", GUICtrlRead($inputproxy))
        IniWrite(@ScriptDir & "\Config.ini", "Data", "Username", GUICtrlRead($inputusername))
        IniWrite(@ScriptDir & "\Config.ini", "Data", "Password", GUICtrlRead($inputpassword))
    EndIf
    If GUICtrlRead($AkunRadio2) = $gui_checked Then     ;;jika diklik radio button2 mka akan tersimpan di file config2.ini
        IniWrite(@ScriptDir & "\Config2.ini", "Data", "Host", GUICtrlRead($inputhost))
        IniWrite(@ScriptDir & "\Config2.ini", "Data", "Port Host", GUICtrlRead($inputporthost))
        IniWrite(@ScriptDir & "\Config2.ini", "Data", "Proxy", GUICtrlRead($inputproxy))
        IniWrite(@ScriptDir & "\Config2.ini", "Data", "Username", GUICtrlRead($inputusername))
        IniWrite(@ScriptDir & "\Config2.ini", "Data", "Password", GUICtrlRead($inputpassword))
    EndIf

EndFunc

Func load()
    If GUICtrlRead($AkunRadio1) = $gui_checked Then
        $readproxy = IniRead(@ScriptDir & "\Config.ini", "Data", "Proxy", "NotFound")
        $readhost = IniRead(@ScriptDir & "\Config.ini", "Data", "Host", "NotFound")
        $readporthost = IniRead(@ScriptDir & "\Config.ini", "Data", "Port Host", "NotFound")
        $readusername = IniRead(@ScriptDir & "\Config.ini", "Data", "Username", "NotFound")
        $readpassword = IniRead(@ScriptDir & "\Config.ini", "Data", "Password", "NotFound")
    EndIf
    If GUICtrlRead($AkunRadio2) = $gui_checked Then
        $readproxy = IniRead(@ScriptDir & "\Config2.ini", "Data", "Proxy", "NotFound")
        $readhost = IniRead(@ScriptDir & "\Config2.ini", "Data", "Host", "NotFound")
        $readporthost = IniRead(@ScriptDir & "\Config2.ini", "Data", "Port Host", "NotFound")
        $readusername = IniRead(@ScriptDir & "\Config2.ini", "Data", "Username", "NotFound")
        $readpassword = IniRead(@ScriptDir & "\Config2.ini", "Data", "Password", "NotFound")
    EndIf

EndFunc

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Just tie the Iniread with GUICtrlSetData function to your load button

going to be the same basic funtion with or without the open dialog...

you have radio buttons, why do you still need the file open dialog?

with there now being only 2 choices.

 

edit:  here is a snippet of mine, might help....

Edited by billo
1 person likes this

Share this post


Link to post
Share on other sites

going to be the same basic funtion with or without the open dialog...

you have radio buttons, why do you still need the file open dialog?

with there now being only 2 choices.

 

edit:  here is a snippet of mine, might help....

thank you for your help... :thumbsup:

it turns out that less is :

GUICtrlSetData($inputhost,$readhost)

GUICtrlSetData($inputporthost,$readporthost)

GUICtrlSetData($inputusername,$readusername)

GUICtrlSetData($inputpassword,$readpassword)

GUICtrlSetData($inputproxy,$readproxy)

 

but I am still curious about how to use the FileOpenDialog and FileSaveDialog in case like this, if without radiobuttons

Share this post


Link to post
Share on other sites

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

Global $readproxy
Global $readportproxy
Global $readhost
Global $readporthost
Global $readusername
Global $readpassword


#Region ### START Koda GUI section ###
$formdata = GUICreate("data", 350, 280, 200, 114)
GUISetBkColor(0xC0DCC0)
$server = GUICtrlCreateGroup("Server", 8, 8, 225, 97)
$inputhost = GUICtrlCreateInput($readhost, 88, 32, 137, 21)
$Label1 = GUICtrlCreateLabel("Host", 24, 32, 26, 17)
$Label2 = GUICtrlCreateLabel("Port", 24, 64, 23, 17)
$inputporthost = GUICtrlCreateInput($readporthost, 88, 64, 137, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("User", 8, 112, 225, 97)
$Label3 = GUICtrlCreateLabel("Username", 24, 136, 52, 17)
$inputusername = GUICtrlCreateInput($readusername, 88, 136, 137, 21)
$Label4 = GUICtrlCreateLabel("Password", 24, 168, 50, 17)
$inputpassword = GUICtrlCreateInput($readpassword, 88, 168, 137, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Proxy", 8, 216, 225, 49)
$inputproxy = GUICtrlCreateInput("127.0.0.1", 88, 232, 137, 21)
$Label5 = GUICtrlCreateLabel("Proxy", 16, 232, 30, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$btnsimpan = GUICtrlCreateButton("SIMPAN", 248, 240, 89, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$btnload = GUICtrlCreateButton("LOAD", 248, 200, 89, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group3 = GUICtrlCreateGroup("Akun", 248, 8, 89, 177)
$AkunRadio1 = GUICtrlCreateRadio("Akun1", 256, 32, 65, 17)
$AkunRadio2 = GUICtrlCreateRadio("Akun2", 256, 56, 65, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnsimpan
            save()
        Case $btnload
            load()

    EndSwitch
WEnd

Func save()
    Local $ini_file, $workingdir
    ; save workingdir
    $workingdir = @WorkingDir
    ; save file dialog
    $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $formdata)
    ; check if return is valid
    If @error Or $ini_file == '' Then
        FileChangeDir($workingdir)
        Return SetError(1, 0, '')
    EndIf
    ; write to ini file
    IniWrite($ini_file, "Data", "Host", GUICtrlRead($inputhost))
    IniWrite($ini_file, "Data", "Port Host", GUICtrlRead($inputporthost))
    IniWrite($ini_file, "Data", "Proxy", GUICtrlRead($inputproxy))
    IniWrite($ini_file, "Data", "Username", GUICtrlRead($inputusername))
    IniWrite($ini_file, "Data", "Password", GUICtrlRead($inputpassword))
    ; restore workingdir
    FileChangeDir($workingdir)
EndFunc

Func load()
    Local $ini_file, $workingdir
    ; save workingdir
    $workingdir = @WorkingDir
    ; open file dialog
    $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $formdata)
    ; check if return is valid
    If @error Or $ini_file == '' Then
        FileChangeDir($workingdir)
        Return SetError(1, 0, '')
    EndIf
    ; read from ini file
    GUICtrlSetData($inputproxy, IniRead($ini_file, "Data", "Proxy", "127.0.0.1"))
    GUICtrlSetData($inputhost, IniRead($ini_file, "Data", "Host", ""))
    GUICtrlSetData($inputporthost, IniRead($ini_file, "Data", "Port Host", ""))
    GUICtrlSetData($inputusername, IniRead($ini_file, "Data", "Username", ""))
    GUICtrlSetData($inputpassword, IniRead($ini_file, "Data", "Password", ""))
    ; restore workingdir
    FileChangeDir($workingdir)
EndFunc

I modified the load and save functions to use FileOpenDialog and FileSaveDialog. Comments added to help to know what happens at each event. Perhaps not exactly what you may want but may show you how to do it. :)

1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Global $readproxy
Global $readportproxy
Global $readhost
Global $readporthost
Global $readusername
Global $readpassword


#Region ### START Koda GUI section ###
$formdata = GUICreate("data", 350, 280, 200, 114)
GUISetBkColor(0xC0DCC0)
$server = GUICtrlCreateGroup("Server", 8, 8, 225, 97)
$inputhost = GUICtrlCreateInput($readhost, 88, 32, 137, 21)
$Label1 = GUICtrlCreateLabel("Host", 24, 32, 26, 17)
$Label2 = GUICtrlCreateLabel("Port", 24, 64, 23, 17)
$inputporthost = GUICtrlCreateInput($readporthost, 88, 64, 137, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("User", 8, 112, 225, 97)
$Label3 = GUICtrlCreateLabel("Username", 24, 136, 52, 17)
$inputusername = GUICtrlCreateInput($readusername, 88, 136, 137, 21)
$Label4 = GUICtrlCreateLabel("Password", 24, 168, 50, 17)
$inputpassword = GUICtrlCreateInput($readpassword, 88, 168, 137, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Proxy", 8, 216, 225, 49)
$inputproxy = GUICtrlCreateInput("127.0.0.1", 88, 232, 137, 21)
$Label5 = GUICtrlCreateLabel("Proxy", 16, 232, 30, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$btnsimpan = GUICtrlCreateButton("SIMPAN", 248, 240, 89, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$btnload = GUICtrlCreateButton("LOAD", 248, 200, 89, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Group3 = GUICtrlCreateGroup("Akun", 248, 8, 89, 177)
$AkunRadio1 = GUICtrlCreateRadio("Akun1", 256, 32, 65, 17)
$AkunRadio2 = GUICtrlCreateRadio("Akun2", 256, 56, 65, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnsimpan
            save()
        Case $btnload
            load()

    EndSwitch
WEnd

Func save()
    Local $ini_file, $workingdir
    ; save workingdir
    $workingdir = @WorkingDir
    ; save file dialog
    $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $formdata)
    ; check if return is valid
    If @error Or $ini_file == '' Then
        FileChangeDir($workingdir)
        Return SetError(1, 0, '')
    EndIf
    ; write to ini file
    IniWrite($ini_file, "Data", "Host", GUICtrlRead($inputhost))
    IniWrite($ini_file, "Data", "Port Host", GUICtrlRead($inputporthost))
    IniWrite($ini_file, "Data", "Proxy", GUICtrlRead($inputproxy))
    IniWrite($ini_file, "Data", "Username", GUICtrlRead($inputusername))
    IniWrite($ini_file, "Data", "Password", GUICtrlRead($inputpassword))
    ; restore workingdir
    FileChangeDir($workingdir)
EndFunc

Func load()
    Local $ini_file, $workingdir
    ; save workingdir
    $workingdir = @WorkingDir
    ; open file dialog
    $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $formdata)
    ; check if return is valid
    If @error Or $ini_file == '' Then
        FileChangeDir($workingdir)
        Return SetError(1, 0, '')
    EndIf
    ; read from ini file
    GUICtrlSetData($inputproxy, IniRead($ini_file, "Data", "Proxy", "127.0.0.1"))
    GUICtrlSetData($inputhost, IniRead($ini_file, "Data", "Host", ""))
    GUICtrlSetData($inputporthost, IniRead($ini_file, "Data", "Port Host", ""))
    GUICtrlSetData($inputusername, IniRead($ini_file, "Data", "Username", ""))
    GUICtrlSetData($inputpassword, IniRead($ini_file, "Data", "Password", ""))
    ; restore workingdir
    FileChangeDir($workingdir)
EndFunc

I modified the load and save functions to use FileOpenDialog and FileSaveDialog. Comments added to help to know what happens at each event. Perhaps not exactly what you may want but may show you how to do it. :)

very helpful, thank you very much :thumbsup: :ILA2:

Edited by fikri1979

Share this post


Link to post
Share on other sites

Glad you got it working!

just another side tip:

I noticed you saving differnt ini files, you can save several differnt configurations in one ini file. Just change the Section Name.

Good tip, thank you :ILA3:

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  
Followers 0