Jump to content

INI read and display of partial information


Recommended Posts

I have a program that reads an ini and populates a series of combo boxes based on user selections. So for example the would pick a state from combo box A and combo box B would report different counties within that state. Then when they pick the county combo box C goes out reads the ini and displays the city. So all of the information is help in the ini for each combo box. My question is that can I only partially display the information from one of the ini headings. So if I have city.population can I set my varable to the full line but only show part of that in the combo box ie I would see the city but not the population. I do want my variable set to city.population though.

Link to comment
Share on other sites

  • Moderators

jcampbell,

Please help us to help you. Post a short version of your ini file (perhaps 2 example states/counties/cities) so we can see what we are dealing with. :)

From what you have said so far, using StringSplit on the city.population variable could be the answer to getting both elements into variables. But a better idea of the ini structure will confirm that. ;)

M23

P.S. When you post the file, please add [code] before and [/code] after the text - then you get it diplayed nicely. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Below is the snipit on how the ini will be structured. I add some extra information into the city line of the ini and parse it out later in the code. What I would like to do is also parse the display so that I only see the city in the combo drop down box and not the city.population

[ProjectLocation]
1=Missouri
2=Kansas
3=Texas

[CountyName]
1=Johnson
2=cass
3=Lafayette

[Johnson]
1=Blue Springs.1000
2=Independance.1000

[Cass]
1=City1.1000
2=City2.1000
3=City3.1000

So what I do is in my GUI I have three combo boxes. One for State that provides the ProjectLocation section from the ini. Once the user pics the Project Location I actualy point it to an ini file names say Missouri.ini. This ini then contains the County and city information. The user then picks the county and it list all the city's from that county. I need the variable set to the full City1.1000 but I only want the user to see the City name in the combo box just to keep it clean.

Link to comment
Share on other sites

I can't edit the above post, there are no options to edit delete, quote or anything for it.

Another consequence of the forum software being updated again.

Managed to delete the previous post and switched to code boxes

O.K. one more time...

You can store an array element index or the population number in the combo items user data,

then retrieve the population value from the user selected combo items user data.

If you want to keep the string formatting of the ini section population value then put it in an array and store the array element index in the combo items user data.

Retrieve the array index from the selected combo item and get the population string from the array.

The maximum number that can be stored in a combo items user data is: 999,999,999

Two examples based on your ini [Cass] section

Without array, and with array.

;example without array
;coded by rover 2k12
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <GuiComboBox.au3>

#cs info.ini
[Cass]
1=City1.1000
2=City2.2000
3=City3.3000
#ce

Example()

Func Example()
Local $msg, $cCombo, $sCity, $sPop
GUICreate("My GUI combo")
$cCombo = GUICtrlCreateCombo("", 10, 10)
$sCity = GUICtrlCreateLabel("", 10, 80, 290, 80)
$sPop = GUICtrlCreateLabel("", 10, 100, 290, 80)
_AddINISection($cCombo, @ScriptDir & "info.ini", "Cass")
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $cCombo ;get selected combo item
GUICtrlSetData($sCity, "City: " & GUICtrlRead($cCombo))
GUICtrlSetData($sPop, "Population: " & _GetData($cCombo))
ConsoleWrite("+City: " & GUICtrlRead($cCombo) & " - Population: " & _GetData($cCombo) & @CRLF)
EndSwitch
WEnd
EndFunc


Func _AddINISection($hWnd, $sCity, $sSection)
;coded by rover 2k12
Local $tInfo, $iIdx, $aCity = IniReadSection($sCity, $sSection)
If @error Then Return -1
_GUICtrlComboBox_GetComboBoxInfo($hWnd, $tInfo)
$hList = DllStructGetData($tInfo, "hList")
If _WinAPI_GetClassName($hList) <> "ComboLBox" Then Return -1 ;verify returned handle is a valid handle and is the handle to the ComboBoxes internal ListBox control (the dropdown menu)

For $i = 1 To $aCity[0][0]
     ConsoleWrite("Key: " & $aCity[$i][0] & " - Value: " & $aCity[$i][1] & @LF)

$aRet = StringSplit($aCity[$i][1], ".", 2)
_GUICtrlComboBox_InsertString($hWnd, $aRet[0]);insert a new item after the last one
$iIdx = _GUICtrlComboBox_GetCount($hWnd) ;get current count of items = index of current item
If @error Or $iIdx = -1 Then Return -3
_GUICtrlListBox_SetItemData($hList, $iIdx - 1, Number($aRet[1])) ;convert string from ini section to number
Next

Return 1
EndFunc


Func _GetData($hWnd)
;coded by rover 2k12
Local $tInfo
_GUICtrlComboBox_GetComboBoxInfo($hWnd, $tInfo)
Local $hList = DllStructGetData($tInfo, "hList")
If _WinAPI_GetClassName($hList) <> "ComboLBox" Then Return -1 ;verify returned handle is a valid handle and is the handle to the ComboBoxes internal ListBox control (the dropdown menu)

Local $iPop = _GUICtrlListBox_GetItemData($hList, _GUICtrlComboBox_GetCurSel($hWnd)) ;get index of selected ComboBox item and retrieve population value from ListBox user data
If $iPop > 1 Then
Return $iPop
Else ;if $iPop is 0 then item does not have a population value
Return -1
EndIf
EndFunc

;example with array
;coded by rover 2k12
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <GuiComboBox.au3>

#cs info.ini
[Cass]
1=City1.1000
2=City2.2000
3=City3.3000
#ce

Example()

Func Example()
Local $msg, $cCombo, $sCity, $sPop, $aPop[1]
GUICreate("My GUI combo")
$cCombo = GUICtrlCreateCombo("", 10, 10)
$sCity = GUICtrlCreateLabel("", 10, 80, 290, 80)
$sPop = GUICtrlCreateLabel("", 10, 100, 290, 80)
_AddINISection($cCombo, @ScriptDir & "info.ini", "Cass", $aPop)
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $cCombo ;get selected combo item
GUICtrlSetData($sCity, "City: " & GUICtrlRead($cCombo))
GUICtrlSetData($sPop, "Population: " & _GetData($cCombo, $aPop))
ConsoleWrite("+City: " & GUICtrlRead($cCombo) & " - Population: " & _GetData($cCombo, $aPop) & @CRLF)
EndSwitch
WEnd
EndFunc


Func _AddINISection($hWnd, $sCity, $sSection, ByRef $aArray)
;coded by rover 2k12
Local $tInfo, $iIdx, $aRet, $aCity = IniReadSection($sCity, $sSection)
If @error Then Return -1
_GUICtrlComboBox_GetComboBoxInfo($hWnd, $tInfo)
$hList = DllStructGetData($tInfo, "hList")
If _WinAPI_GetClassName($hList) <> "ComboLBox" Then Return -2 ;verify returned handle is a valid handle and is the handle to the ComboBoxes internal ListBox control (the dropdown menu)


;Add population to array and store 1 based index in ListBox user data (default value in unused ListBox item data is 0, using a 1 based index allows unambiguous ListBox userdata validation)
ReDim $aArray[$aCity[0][0]+1]

For $i = 1 To $aCity[0][0]
     ConsoleWrite("Key: " & $aCity[$i][0] & " - Value: " & $aCity[$i][1] & @LF)
$aRet = StringSplit($aCity[$i][1], ".", 2)
_GUICtrlComboBox_InsertString($hWnd, $aRet[0]);insert a new item after the last one
$iIdx = _GUICtrlComboBox_GetCount($hWnd) ;get current count of items = index of current item
If @error Or $iIdx = -1 Then Return -3
$aArray[$i] = $aRet[1]
_GUICtrlListBox_SetItemData($hList, $iIdx - 1, $i) ;use a 1-based index - set to element of array with population value
Next

Return 1
EndFunc



Func _GetData($hWnd, ByRef $aArray)
;coded by rover 2k12
Local $tInfo
_GUICtrlComboBox_GetComboBoxInfo($hWnd, $tInfo)
Local $hList = DllStructGetData($tInfo, "hList")
If _WinAPI_GetClassName($hList) <> "ComboLBox" Then Return -1 ;verify returned handle is a valid handle and is the handle to the ComboBoxes internal ListBox control (the dropdown menu)

Local $iPop = _GUICtrlListBox_GetItemData($hList, _GUICtrlComboBox_GetCurSel($hWnd)) ;get index of selected ComboBox item and retrieve population value from ListBox user data
If $iPop > 0 Then
Return $aArray[$iPop]
Else ;if $iPop is 0 then item does not have a population value
Return -2
EndIf
EndFunc
Edited by rover

I see fascists...

Link to comment
Share on other sites

one minute the forum is fixed post upgrade, the next it's fucked up again.

there isn't even a button to edit my post.

That has happened for some time with some non-english characters, but I'm not sure why the code you posted would do this. If you scroll to the bottom you'll find Quote and Report so I assume that Edit is there too. You'll also find the complete post if you quote the broken post.
Link to comment
Share on other sites

Hi

I just reloaded the page (Firefox 14.01)

the AutoIt code box is messed up and the edit, report, quote, etc. buttons are jumbled at the bottom of the

code box. (required scrolling to the bottom of the code box to see the buttons. another symptom is the includes with arrow brackets are always stripped from the code)

Nothing in the code or OS localization is non-english,

will try the delete post button

O.K, 2nd attempt to edit this post. It just timed out again.

Going to use only plain Code boxes from now on, the colour AutoIt boxes are consistently damaged by every forum update.

Edited by rover

I see fascists...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...