Sign in to follow this  
Followers 0
digitalexpl0it

Ini to combo box

6 posts in this topic

hello,

I am having an issue were I am trying to pull everything under a section in a INI file into a combobox.Issue I have is it only selects 2 out of the list. Not sure why

 

func _ReadHistory()
    Local Const $sFilePath = "history1.ini"
    Local $iFileExists = FileExists($sFilePath)
    ; If the INI file is not found, output error message
    If not $iFileExists Then
        msgbox(0,"Oh NO!", $sFilePath & " not found!")
    endif
    
    Local $aArray = IniReadSection($sFilePath, "RemoteHistory")
    ; Start the array loop and run robocopy
    If Not @error Then
        for $i = 0 to $aArray[0][0]
            _GUICtrlComboBox_InsertString($rdesktopInput, $aArray[$i][1], 0)
            $i = $i +1
        next
    endif
endfunc
INI FILE Example

[RemoteHistory]
HOST=12.12.12.12
HOST=127.0.0.1
HOST=10.10.10.1
HOST=192.168.1.1
HOST=0.0.0.0

 

Share this post


Link to post
Share on other sites



By adding this line to your next statement...

$i = $i + 1

...you are effectively counting by 2, as the Next loop already increments. Try this to see what I mean:

Local Const $sFilePath = "my.ini"
Local $iFileExists = FileExists($sFilePath)
    If not $iFileExists Then msgbox(0,"Oh NO!", $sFilePath & " not found!")

    Local $aArray = IniReadSection($sFilePath, "RemoteHistory")
    If Not @error Then
       for $i = 1 to $aArray[0][0]
           ConsoleWrite($i & @CRLF)
           ConsoleWrite($aArray[$i][1] & @CRLF)
           $i = $i + 1
        next
    endif

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

DOH, thank you. Wasn't thinking there about counting by Two, removing the $i=$i+1 worked. Thank you, Just needed another set of eyes on this.

Share this post


Link to post
Share on other sites

So the next thing is, how would I check for duplicates when writing to the ini file? 

I have a function to write to the ini file like this. But it just adds to the end of the file. Not sure how to check to not write if a duplicate is found

 

func _WriteHistory($txt)
    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen("history1.ini", $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "Error: Cant write to history1.ini")
        ;Return False
        FileClose($hFileOpen)
    EndIf
    
    FileWriteLine($hFileOpen, "HOST=" & $txt & @CRLF)
    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)
endfunc

 

Share this post


Link to post
Share on other sites

Is there a reason you have all of the keys named the same? If you named them sequentially instead of all HOST, you could use the built in functions such as IniWrite, which would be much easier to manage. The way you have it, you would basically have to do an IniReadSection, then loop through the resultant array looking for the value. If you don't find it, then add it.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

basically it just dumps to the ini file as a history, in which I can pull from and show in a combobox, I could use a txt file for this since the history file will jsut keep growing, but an option to set other ini header sections was mentioned so I started it this way. May not be the best way. 

Edited by digitalexpl0it

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

  • Similar Content

    • RC86
      By RC86
      Afternoon, I could very well be doing this wrong so feel free to totally advise otherwise - I'm wanting to use a GUI to first display a key from within an INI file, then secondly change the INI file by using a FileSelectFolder command but then I want to see the GUI change to reflect the change I've just made.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Input1 = GUICtrlCreateInput(Iniread(@WorkingDir & "\test.ini","Path","FilePath",""), 64, 80, 121, 21) $Button1 = GUICtrlCreateButton("Change", 200, 80, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $selectedFolder = FileSelectFolder("Select Log Path Directory",@WorkingDir,0) If NOT $selectedFolder = "" Then $newLogPath = IniWrite(@WorkingDir & "\test.ini","Path","FilePath",$selectedFolder) EndIf EndSwitch WEnd So 2 part question really: (1) Should I be using GUICtrlCreateInput to display my INI read from within the GUI? (2) How can I refresh the GUI to update that to read the new information I've just written to the GUI?
      Thanks!

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'm working on a little project, and I was wondering if there's a way ( sure there is ) to insert data to a ComboBox control everytime the user insert some text in the ComboBox which is not in the ComboBox data. I'll try to explain with an example:
      - Form with some data ( ComboBox is empty );
      - User prompt something in the ComboBox: if what the user prompts is not in the ComboBox values ( at the moment empty ), then insert the value in the ComboBox values, in order to have, next time the user prompts the form, the value that he entered.
      More pratical example:
      - First call of the form, ComboBox empty;
      - I prompt "A" in the ComboBox;
      - Second call, in the ComboBox I should see "A";
      - I prompt "B" in the ComboBox;
      - Third call, I should see "A"
                                                 "B";
      - And so on...
      Everytime the form is called, I re-create it, so I think I can't use _GUICtrlComboBox_AddStrings().
      I tried with
      Global $strCboStrings = "" ; When the user prompt the form, the code below is executed. ; I.E. : User prompt "A", after the if I should have "A"; ; In the second call, If I write "B", I should see "A" ; "B"; ; If I write "A" again, in the combobox values should not be any changes. If Not StringInStr($strCboStrings, GUICtrlRead($cboVoiceCategory)) <> 0 Then $strCboStrings &= $strCboStrings & "|" & GUICtrlRead($cboVoiceCategory) EndIf Any suggestion?
      Thanks
    • kstriyhon
      By kstriyhon
      hello Comunity i am new to autoit and i bump into a pitfall regarding the creation of objects in a dinamyc way but more especific  creating combobox at runtime
      i need many comboboxes and sofar i createdthem manually 
      like this 
      $idCombo_1 = GUICtrlCreateCombo("", 500, 40, 130, 21)     $idCombo_2 = GUICtrlCreateCombo("", 500, 70, 130, 21)     $idCombo_3 = GUICtrlCreateCombo("", 500, 100, 130, 21)     $idCombo_4 = GUICtrlCreateCombo("", 500, 130, 130, 21)     $idCombo_5 = GUICtrlCreateCombo("", 500, 160, 130, 21)     $idCombo_6 = GUICtrlCreateCombo("", 500, 190, 130, 21)     $idCombo_7 = GUICtrlCreateCombo("", 500, 220, 130, 21)     $idCombo_8 = GUICtrlCreateCombo("", 500, 250, 130, 21)     $idCombo_9 = GUICtrlCreateCombo("", 500, 280, 130, 21)     GUICtrlSetData($idCombo_1, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_2, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_3, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_4, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_5, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_6, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_7, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_8, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_9, "Item1|Item2|Item3|Item4|Item5") now i need this example but create them at runtime as there are more than 9 combos what i need thanks in advance kind regards
    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys
      I am working on a little project, in which I have to retrieve 8000+ rows of data from a table, from a SQLite database, to populate a combobox 
      This is what I tried 'til now, but it still takes about 12 seconds to populate the combobox.
      _SQLite_Exec($objDatabase, "BEGIN TRANSACTION;") If _SQLite_GetTable($objDatabase, "SELECT DISTINCT Comune FROM LISTA_COMUNI;", $arrRisultatoQuery, $intRighe, $intColonne) = $SQLITE_OK Then For $i = 2 To UBound($arrRisultatoQuery) - 1 If $i < UBound($arrRisultatoQuery) - 1 Then GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i] & "|") Else GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i]) EndIf Next _SQLite_Exec($objDatabase, "COMMIT;") Are there any other solution to retrieve 8000+ records from a SQLite database?
      Thank you very much