Jump to content

combobox pull data from xls or csv


Recommended Posts

Was wondering if Combobox can pull data from xls or csv? I tested, but didn't work on me. I know how to pull text with filereadline, but this is a bit different from pulling text file.

Incase you wondering what data it's pulling... In excel: I have two/more rows

A1 = Item1

A2 = Item2

A3 = etc...

I want combox to pull those items into combobox.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

you have to to deformat the lines. uses stringsplit for csv files to get the "," commas out.

please provide an example for further help

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

Ok, This works:

$Test = Filereadline(@ScriptDir & "\Text.txt", 3)
 

On Text Line3:

John|Dong|Pheng

Now the hard part is how do I call the Func since the Text file isn't always John|Dong|Pheng?

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

yeah but I'm not going use John|Dong|Pheng all the time... I wanted to put it on text file so I can change the name whenever I want to.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

yeah but I'm not going use John|Dong|Pheng all the time... I wanted to put it on text file so I can change the name whenever I want to.

 

asianqueen, here is what i do to fill comboboxes that the values may change from time to time, or have a lot of values that i dont want cluttering up my script:

create an INI file

[DDLBValues]
statesDDLB=|AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY

Then in my script I read the value from the ini file into a string variable and use that to populate the DDLB

Local $statesDDLB = IniRead($INI_FileName, "DDLBValues", "statesDDLB", "")

Global $cboPropertyState = GUICtrlCreateCombo("", 235, 126, 97, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))

GUICtrlSetData($cboPropertyState, $statesDDLB, $defaultPropertyState)
Edited by Shrapnel
Link to comment
Share on other sites

I like your example. Can you write an example when calling the function for example if you click IA from the dropdown menu of the combobox; it populate msgbox saying "you selected IA"?

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

you would just use GUICtrlSetOnEvent to create a listener for the combo box to change

Global $cboPropertyState = GUICtrlCreateCombo("", 235, 126, 97, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
     GUICtrlSetOnEvent($cboPropertyState, "cboPropertyStateChange")

and the write a function for it

Func cboPropertyStateChange()
    MsgBox(0, "", "You have selected " & GUICtrlRead($cboPropertyState))
EndFunc   ;==>cboPropertyStateChange
Link to comment
Share on other sites

I'm a bit confuse here. What is $GUI_SS_DEFAULT_COMBO and $CBS_SIMPLE declaring to? I'm getting error saying used before declaration.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

same. Are we grabbing those variable from GUIConstantsEx?

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

Using your example to test before I implemented into mine.

#include <GUIConstantsEx.au3>
Local $statesDDLB = IniRead("test.ini", "DDLBValues", "statesDDLB", "")

Global $cboPropertyState = GUICtrlCreateCombo("", 235, 126, 97, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))

GUICtrlSetData($cboPropertyState, $statesDDLB, $defaultPropertyState)

Global $cboPropertyState = GUICtrlCreateCombo("", 235, 126, 97, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
GUICtrlSetOnEvent($cboPropertyState, "cboPropertyStateChange")

while 1
    sleep(200)
WEnd

Func cboPropertyStateChange()
    MsgBox(0, "", "You have selected " & GUICtrlRead($cboPropertyState))
EndFunc   ;==>cboPropertyStateChange

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

I am feeling nice today, so here ya go:

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Local $statesDDLB = IniRead("test.ini", "DDLBValues", "statesDDLB", "")


Global $frmForm = GUICreate("Form", 150, 50, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "frmClose")

Global $cboPropertyState = GUICtrlCreateCombo("", 10, 10, 97, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
    GUICtrlSetData($cboPropertyState, $statesDDLB, "PA")
    GUICtrlSetOnEvent($cboPropertyState, "cboPropertyStateChange")

GUISetState(@SW_SHOW)

while 1
    sleep(200)
WEnd

Func cboPropertyStateChange()
    MsgBox(0, "", "You have selected " & GUICtrlRead($cboPropertyState))
EndFunc   ;==>cboPropertyStateChange

Func frmClose()
    GUIDelete($frmForm)
    Exit
EndFunc   ;==>frmClose
Edited by Shrapnel
Link to comment
Share on other sites

perfectly what I'm looking for... Is it also possible to assign an id in the ini files too? so like for example

ini file

[DDLBValues]
statesDDLB=|AK|AL|AR
[DDLBIDS]
statesDDLB2=|1|2|3

with the same method for DDLBIDS - on the label next to combobox; if i select AK, label would display 1. Select AL, label would dsiplay 2, etc...? Or does it need a different ways of doing this?

Just need hint this times... Learn alot today!

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

nvm, I used iniread/iniwrite. Works much better :) thanks and much appreciated.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
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...