Sign in to follow this  
Followers 0
Guest JRowe_1

populating a combo box from values returned using the mysql UDF

4 posts in this topic

ok, so I have a combo box, and I have a database, and I can sucessfully return all the values in the database (I'm better with SQL than autoit at this point.)

I'm building a time management program that allows employees to upload their hours spent/location to a database.

I want to populate the Job Site combo box with the jobsite names from the database.

I only want the list to populate if $loginStatus = 1.

I created a function that returns a list of names, supposedly, but I'm not certain at this point. $jobsList is supposed to be an array with a list of all the names of the job sites.

I've already created the login functionality, with a global $loginStatus = "Logged In" if you're logged in, other error messages otherwise.

Func GetJobSites()
    If $LoginStatus = "Logged In" Then
    $query = "SELECT Name FROM Sites WHERE Code >-1"
    $i =0
    $jobs = _Query($connect , $query)
        With $jobs
        While NOT .EOF
            $i = $i+1
            $jobsList[$i] = $jobs.Fields('Code').Value
            .MoveNext
        WEnd
    EndWith
EndIf
EndFuncoÝ÷ ØÛh¦n«^¶¬r¡º1Â+a¶¥Ëh~:²+^©°·­Ø^ëI¡´¢µëºw-Înø¨ºÉr'(uè^­ë.rKj{(ê'z¥¦g«z­-¢Ö¤zØ^Ó~£¡»ËZ®¶²jwi¢¥jצÉÊ&nèÅ«­¢+Ø(ÀÌØíµå
½µ½  ½àôU%
Ñɱ
ÉÑ
½µ¼ ÅÕ½ÐìÅÕ½Ðì°äÌ°äØ°ÄÐÔ°ÈÔ¤)
±° ÅÕ½ÐíÑ)½M¥ÑÌÅÕ½Ðì¤)U%
ÑɱMÑÑ ÀÌØí©½Í1¥ÍÑmt¤)¹%(

Share this post


Link to post
Share on other sites



Func GetJobSites()
    If $LoginStatus = "Logged In" Then
        $query = "SELECT Name FROM Sites WHERE Code >-1"
        $jobs = _Query($connect , $query)
        With $jobs
            While NOT .EOF
                $jobsList = $jobsList & "|" & $jobs.Fields('Code').Value
                .MoveNext
            WEnd
        EndWith
    EndIf
EndFunc

$myComboBox = GUICtrlCreateCombo("", 93, 96, 145, 25)
Call("GetJobSites")
GUICtrlSetData($jobsList)

Or something similiar to that.

Combo boxes items are seperated by "|", so just loop thru the list like above.

-CMR

Share this post


Link to post
Share on other sites

you kick ass, man ;) Thanks very much.

Share this post


Link to post
Share on other sites

Ok, I can't get a Function to work, so what I did was create a single fire if function which turns itself off after a successful run, in the main loop.

If $populated = 0 Then
        If $loginStatus = "Logged In" Then
        $query2 = "SELECT Name FROM Sites WHERE Code >-1"
        $jobs = _Query($connect , $query2)
            With $jobs
            While NOT .EOF
                $siteList = $siteList & "|" & $jobs.Fields('Name').Value
                .MoveNext
            WEnd
            EndWith
                $populated = 1
        GUICtrlSetData($JobSiteDDControl, $siteList)
        EndIf
EndIf

The code checks if $populated is at 0, which means the list isn't populated, then checks if you're logged in. If it's populated, it doesnt run the function at all. Ifyou're not logged in, and it's not populated, it doesnt run the function either.

If you're logged in, and the list hasnt been populated, it generates $siteList (a list of the names of the jobsites,) and then assigns that list to the combo box, then sets $populated to 1, turning the function off until it needs to be run again.

What this does is allow you to generate values dynamically in a list from a MySQL server. Yippee! ;)

Is there a way to call a function when the combo box is clicked, rather than putting this in the main loop?

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