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

    • Terenz
      By Terenz
      Hello,
      I have searched everywhere but on the forum there isn't an example of a combobox with checkbox. I think is a very useful control but require subclassing. Several example in C++, one of this:
      CheckComboBox Control
      If somone has some time to check it out. If need i can provide the source code. Thanks
    • Wingens
      By Wingens
      Hi,
       
      I am trying to create a list view wich shows the content of an ini file. There is a pulldown menu wich allows me to check a certain status in the ini file if the status is found it should read out the key and in every section the same key is located after that it should fill out the listview with all results found.
       
      $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1) GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", 8, 16, 185, 89) GUICtrlCreateLabel("Status:", 32, 40, 37, 17) $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlSetData($STATUS, "Aangevraagd|Verzonden|Afgehandeld", "") GUICtrlCreateGroup("", -99, -99, 1, 1) $View = GUICtrlCreateListView("RMANR|RMANRLEV|DEBITNR|KLANT|STATUS|MODEL|SERIENR|AANGEMELDDOOR|AANMELDDATUM|VERZENDDATUM|RETOURDATUM|KLACHT|OPLOSSING", 8, 120, 1218, 614) $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $EXIT $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?") If $YesOrNo = 6 then GUIDelete($OVERZICHTGUI) MAINMENU() ExitLoop EndIf Case $STATUS $GO = 1 $STATE = GUICtrlRead($STATUS) Local $aArray = IniReadSection(@ScriptDir & "\DB\rma.ini", "STATUS") _ArrayDisplay($aArray, "Gevonden") $FOUNDRMANR = _ArraySearch($aArray, $STATE) MsgBox(4096, "", $FOUNDRMANR) If $FOUNDRMANR = -1 Then MsgBox(4096, "Not Found", "No RMA requests with this status found.") $GO = 0 EndIf If $GO = 1 Then $VAR = IniRead(@ScriptDir & "\DB\rma.ini", "RMANR", $FOUNDRMANR, "Not found") MsgBox(4096, "", $VAR) EndIf EndSwitch WEnd  
      rma-forum.ini
    • Wingens
      By Wingens
      Hi,
      i a stuck with a hopefully a little problem.
      I know the value of a not yet known key in an ini file.
      I need to be able to find the key using the value. The value is a unique value in a section.
       
      Hope you guys can help me.
    • SaeidN
      By SaeidN
      Let's say I have 10 combobox and 10 items in each.
      1- If one item in a combobox is selected, I don't want it to be selectable in another combobox. (Or if it is, remove the duplicate one)
      2- When I click on button, I want 10 msgboxes to show, and each item showing in each msgbox in order they are selected. (from combobox1 to combobox10)
      I'm confused whether to use select or switch or other loops.
    • 31290
      By 31290
      Hi guys,
      I'm facing a problem that I can't solve, despite trying hard.
      I have an .ini file with several sections:
      [Latitude E5440] URL=http://downloads.dell.com/published/pages/latitude-e5440-laptop.html [Latitude E5450] URL=http://downloads.dell.com/published/pages/latitude-e5450-laptop.html [Latitude E5470] URL=http://downloads.dell.com/published/pages/latitude-e5470-laptop.html [Latitude E7240] URL=http://downloads.dell.com/published/pages/latitude-e7240-ultrabook.html [Latitude E7250] URL=http://downloads.dell.com/published/pages/latitude-e7250-ultrabook.html [Latitude E7270] URL=http://downloads.dell.com/published/pages/latitude-e7270-ultrabook.html Then I collect the computer model name and try to look if it exists in the ini file. But, when performing the search, I only got the index in the array.
      For example, my computer model is a "Latitude E7240". An "_ArraySearch" gives me "4" as a result and because this is also the fourth place of my search in the ini file. It works well if I move the section anywhere else in the file and always give me the correct position.
      Question is: How can I convert the index number to the section name so I can tell my script that if it's found in the ini file, the download URL variable will be set to the corresponding key in the ini file.
      Here's my code so far:
      Can someone give me an hand on this?
      Thanks
      -31290-