Jump to content

Ini to combo box


Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

 

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

×
×
  • Create New...