Sign in to follow this  
Followers 0
JohnRichard

INI Help

6 posts in this topic

Hi all. Need your help about INI. I have created a GUI to remotely connect to PC via VNC. GUI has a combo where to input the hostname of the PC to connect. I wanted to save the hostname in INI everytime i connect so that when i open the GUI again, i can select to previous hostname that i connected. I was able to save it in INI and able to set the default data on the combo when i re-open the GUI. My problem is, only one hostname was saved in INI file. I wanted when it writes to INI, it will just append the hostname at the end. What is happening it is only saving one value in INI so my default value in combo is also one.

How will i make to write in INI to add the data but not overwrite the data.

part of the script is like this...

$var = IniRead("C:\myfile.ini", "section2", "key", "NotFound")
$Form = GUICreate("Remote PC", 360, 130, -1, -1, $WS_SYSMENU)
$Input = GUICtrlCreateCombo("", 150, 15, 197, 24)
$Button_Connect = GUICtrlCreateButton("Connect", 75, 60, 90, 26, 0)
GUICtrlSetOnEvent($Button_Connect, "Connect_to_PC")
$Button_Exit = GUICtrlCreateButton("Exit", 180, 60, 90, 26, 0)
GUISetState(@SW_SHOW)

Func Connect_to_PC()
$PC3 = GUICtrlRead($Input3)
    IniWrite("C:\myfile.ini", "section2", "key", $PC3)
EndFunc

appreciate any help from all of you.

thanks.

Share this post


Link to post
Share on other sites



JohnRichard,

This should give you an idea of how to go about it:

#include <GUIConstantsEx.au3>

$sIni_File = @ScriptDir & "\Test.ini"

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Select the hostname", 10, 10)
$hCombo = GUICtrlCreateCombo("", 10, 30, 200, 20)

$hButton_Connect = GUICtrlCreateButton("Connect", 220, 30, 80, 30)
$hButton_Save = GUICtrlCreateButton("Save INI", 220, 90, 80, 30)
$hButton_Load = GUICtrlCreateButton("Load INI", 220, 150, 80, 30)

GUISetState()

$sCurrent_Hostname = ""
$sHostname_List = "|"

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_Save
            IniWrite($sIni_File, "Hostnames", "List", $sHostname_List)
            GUICtrlSetData($hCombo, "")
        Case $hButton_Load
            $sHostname_List = IniRead($sIni_File, "Hostnames", "List", "|")
            GUICtrlSetData($hCombo, $sHostname_List)
        Case $hButton_Connect
            $sCurrent = GUICtrlRead($hCombo)
            If StringinStr($sHostname_List, $sCurrent) = 0 Then
                $sHostname_List &= GUICtrlRead($hCombo) & "|"
                GUICtrlSetData($hCombo, $sHostname_List)
            EndIf
    EndSwitch
    
WEnd

M23


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

Hi all. Need your help about INI. I have created a GUI to remotely connect to PC via VNC. GUI has a combo where to input the hostname of the PC to connect. I wanted to save the hostname in INI everytime i connect so that when i open the GUI again, i can select to previous hostname that i connected. I was able to save it in INI and able to set the default data on the combo when i re-open the GUI. My problem is, only one hostname was saved in INI file. I wanted when it writes to INI, it will just append the hostname at the end. What is happening it is only saving one value in INI so my default value in combo is also one.

How will i make to write in INI to add the data but not overwrite the data.

part of the script is like this...

$var = IniRead("C:\myfile.ini", "section2", "key", "NotFound")
$Form = GUICreate("Remote PC", 360, 130, -1, -1, $WS_SYSMENU)
$Input = GUICtrlCreateCombo("", 150, 15, 197, 24)
$Button_Connect = GUICtrlCreateButton("Connect", 75, 60, 90, 26, 0)
GUICtrlSetOnEvent($Button_Connect, "Connect_to_PC")
$Button_Exit = GUICtrlCreateButton("Exit", 180, 60, 90, 26, 0)
GUISetState(@SW_SHOW)

Func Connect_to_PC()
$PC3 = GUICtrlRead($Input3)
    IniWrite("C:\myfile.ini", "section2", "key", $PC3)
EndFunc

appreciate any help from all of you.

thanks.

The IniWrite() function will not write more than one instance of the same key name within a section, so you wind up overwriting the same one over and over.

You either need variable key names (i.e. $key = "Key_" & $n) or use IniReadSection() to get them, modify the array, then IniWriteSection() to write them.

^_^


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

many thanks melba from your sample. i'll work on it and see how will i improve more my script.

Share this post


Link to post
Share on other sites

many thanks melba from your sample. i'll work on it and see how will i improve more my script.

Share this post


Link to post
Share on other sites

Indeed it would be hard to write 2 keys with the same name and force for AutoIt (by writing your own ini UDFs) to be fine with that.

I would not recomend saving you program data in ini just for the reason that Micro$oft will not let user to modify files in "Program Files" unless user is admin in later versions of Windows. Use registry (that will make it not portable too ^_^ ).

Here is some food for ideas from my UDFs regarding INI:

Func getini($vars, $desc = 'Input Requred', $got = '', $timeout = 0, $psf = ' M', $w = 250, $h = 120, $def = '')
    $tgot = $got
    $got = IniRead(@ScriptFullPath & '.ini', 'vars', $vars, "``")
    If $tgot <> '' Then $got = $tgot
    If $got <> 0 And $got <> '``' Then
        $got = InputBox($vars, $desc, $got, ' M', $w, $h, -1, -1, $timeout)
        If $got <> '' Then IniWrite(@ScriptFullPath & '.ini', 'vars', $vars, $got)
        Return $got
    Else
        $got = InputBox($vars, $desc, $got, ' M', $w, $h, -1, -1, $timeout)
        If $got <> 0 Or $got <> '' Then
            IniWrite(@ScriptFullPath & '.ini', 'vars', $vars, $got)
            Return $got
        Else
            Return $def
        EndIf

    EndIf
EndFunc  ;==>getini

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