Sign in to follow this  
Followers 0
MattX

Combo Box from lookup table

15 posts in this topic

I am knocking up a quick app [ The app is just a simple home drive mapping util which will prompt the user for their password. ] which will have a combo box with a list of user IDs in from a 2003 server.

Now as there are quite a few I don't want to code them all in the main script

$Combo_1 = GUICtrlCreateCombo("", 20, 10, 120, 21)
GUICtrlSetData(-1, "|user01|user02|user03|user04|user05|user06|")

etc etc

so was wondering how I would go about having them in a text file say or an ini file and the combo box picking up from there.

Would apprecaite some advice.

Share this post


Link to post
Share on other sites



I had a similar question and this is what I did with some help. It needs the rest of the code, but should get you on the right path.

;$xFile = file location

$ComboBox1 = GuiCtrlCreateCombo("Select Data", 16, 8, 225, 21)
GUICtrlSetData($ComboBox1,$ComboList)

Func _ComboBoxData()
Dim $aRecords,$xFile, $comboList
If Not _FileReadToArray($xFile,$aRecords) Then
   MsgBox(4096,"Error", "Unable to Read File! Error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    $ComboList=$comboList & $aRecords[$x] & "|"
Next
$ComboList=StringTrimRight($ComboList,1)
EndFunc

Share this post


Link to post
Share on other sites

I did what you want to do doing this.

;#NoTrayIcon
Break(0)
#include <GuiConstants.au3>
;-----------------------------
fileopen ("quickpaste.ini", 0)
$note1 = FileReadLine ("quickpaste.ini")
GUICreate("QuickPaste", 400, 75)
$Combo_2 = GuiCtrlCreateCombo("", 20, 20, 300, 80)
GuiCtrlSetData($combo_2, $note1)
$button1 = GuiCtrlCreateButton("Paste", 330, 20, 60, 20)

; Run the GUI until it is closed
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    ;When button is pressed, label text is copied to the clipboard
    Case $msg = $button1
      $data = GUICtrlRead($Combo_2)
      ClipPut($data)
      sleep(200)
      exit
    EndSelect
WEnd
Exit
[\code]

This little tool is a sort of a "sticky" clipboard, where you can add data to a ini file, and it will show up in a list for the user to choose from. It runs in combination with another app I use, but the idea you need solving is shown here.


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    

    The Vollatran project



    _____



    I'm famous



    My blog: http://www.vollysinterestingshit.com/


  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
MattX   

    
        
    
             0
    
        
    

        
            
                Universalist
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             0
    
        
    

                356 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #4 · 
            Posted 
            
            
            
        
    

    


            
        
            Thanks for the advice chaps, I'll get cracking with it tomorrow. I'll let you know how I get on.....


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
Zedna   

    
        
    
             131
    
        
    

        
            
                AutoIt rulez!
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             131
    
        
    

                8,904 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #5 · 
            Posted 
            
            
            
        
    

    


            
        
            I like idea from kpu
You can store users also instead of TXT in INI file (only keys without values)
and then read it into array by calling one function IniReadSection

GUICtrlSetData($users,""); delete previous values
        $tmp = ""
        $a_users = IniReadSection(@ScriptDir & "\file.ini", "Users")
        If @error Then 
            MsgBox(48, "", "Error occured, probably no INI file.")
        Else
            For $i = 1 To $a_users[0][0]
                $tmp &= $a_users[$i][0] & "|"
            Next
            $tmp = StringTrimRight($tmp,1)
        EndIf
        GUICtrlSetData($users,$tmp)

this is modified piece of code from my post on similar problem

from here

INI should look something like that:

[users]User1

User2

User3

User4

User5

You can choose what you prefer: TXT or INI

Share this post


Link to post
Share on other sites

I'm stuck chaps - getting the combo box up but its blank !! There are no users in it. Would appreciate some help.

#include <GuiConstants.au3>
#include <file.au3>
GUICreate("Select PC", 155, 66, (@DesktopWidth - 155) / 2, (@DesktopHeight - 66) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$xFile = ("c:\users.txt")
Dim $aRecords, $xFile, $comboList
$ComboBox1 = GUICtrlCreateCombo("Select Data", 16, 8, 225, 21)
GUICtrlSetData($ComboBox1, $comboList)

Func _ComboBoxData()
    
    If Not _FileReadToArray($xFile, $aRecords) Then
        MsgBox(4096, "Error", "Unable to Read File! Error:" & @error)
        Exit
    EndIf
    For $x = 1 To $aRecords[0]
        $comboList = $comboList & $aRecords[$x] & "|"
    Next
    $comboList = StringTrimRight($comboList, 1)
EndFunc   
While 1
WEnd

Share this post


Link to post
Share on other sites

You just forgot to call the function. B)

This should do it! :o

#include <GuiConstants.au3>
#include <file.au3>
Dim $xFile,$aRecords,$comboList
_ComboBoxData()
GUICreate("Select PC", 155, 66, (@DesktopWidth - 155) / 2, (@DesktopHeight - 66) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
Dim $aRecords, $xFile, $comboList
$ComboBox1 = GUICtrlCreateCombo("Select Data", 16, 8, 225, 21)
GUICtrlSetData($ComboBox1, $comboList)

Func _ComboBoxData()
    $xFile = ("users.txt")
    If Not _FileReadToArray($xFile, $aRecords) Then
        MsgBox(4096, "Error", "Unable to Read File! Error:" & @error)
        Exit
    EndIf
    For $x = 1 To $aRecords[0]
        $comboList = $comboList & $aRecords[$x] & "|"
    Next
    $comboList = StringTrimRight($comboList, 1)
EndFunc  
While 1
WEnd

Share this post


Link to post
Share on other sites

When I run this I just get the 'select Data' in the combo box and nothing else....

I even changed the path of the users.txt so its looking the correct location..

You just forgot to call the function. B)

This should do it! :o

#include <GuiConstants.au3>
#include <file.au3>
Dim $xFile,$aRecords,$comboList
_ComboBoxData()
GUICreate("Select PC", 155, 66, (@DesktopWidth - 155) / 2, (@DesktopHeight - 66) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
Dim $aRecords, $xFile, $comboList
$ComboBox1 = GUICtrlCreateCombo("Select Data", 16, 8, 225, 21)
GUICtrlSetData($ComboBox1, $comboList)

Func _ComboBoxData()
    $xFile = ("users.txt")
    If Not _FileReadToArray($xFile, $aRecords) Then
        MsgBox(4096, "Error", "Unable to Read File! Error:" & @error)
        Exit
    EndIf
    For $x = 1 To $aRecords[0]
        $comboList = $comboList & $aRecords[$x] & "|"
    Next
    $comboList = StringTrimRight($comboList, 1)
EndFunc  
While 1
WEnd

Share this post


Link to post
Share on other sites

One thing I don't understand either is the [$x] on the $aRecords[$x] var - can someone explain that to me...

Share this post


Link to post
Share on other sites

Right I have got a little further with this, I have combo box with the list of what I need. Problem I now have is that on every option within the list I have a small box character at the end of it.

Code that is doing this is as follows - I am sure its something to do with the StringTrimRight - would apprecaite some advice again !!

#include <file.au3>
#include <GuiConstants.au3>
Dim $aRecords, $xFile, $Combolist
$xFile = ("c:\dir.txt")
If Not _FileReadToArray($xFile, $aRecords) Then
    MsgBox(4096, "Error", " Error reading log to Array   error:" & @error)
    Exit
EndIf
For $x = 1 To $aRecords[0]
    $Combolist = $Combolist & $aRecords[$x] & "|"
Next
$Combolist = StringTrimRight($Combolist, 1)
GUICreate("Select PC", 155, 66, (@DesktopWidth - 155) / 2, (@DesktopHeight - 66) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$ok = GUICtrlCreateButton("Select", 40, 40, 80, 20)
GUISetState()
$ComboBox1 = GUICtrlCreateCombo("", 10, 10)
GUICtrlSetData($ComboBox1, $Combolist)
While 1
WEnd

Share this post


Link to post
Share on other sites

Well if I comment out the $Combolist = StringTrimRight($Combolist, 1) it does not do anything anyhoo.

I am sure [ looking at other people's code ] that this is how you get rid of the small box on the right after each combo box entry.

Christ, this is really pissing me off now. So frigging close.

Laptop close to going out the window......

Share this post


Link to post
Share on other sites

I was looking for a solution to a similar problem - this works:

#include <GuiConstants.au3>

GUICreate("Select User", 250, 66)

$combo = GUICtrlCreateCombo("", 16, 8, 225, 21)
GUICtrlSetData($combo, "")
$selectbutton = GUICtrlCreateButton("Select", 100, 40, 60, 20)

GUISetState()

$userlist = IniReadSection("Userlist.ini", "Users")

If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $userlist[0][0]
        $tmp = $userlist[$i][1] & "|"
        GUICtrlSetData($combo, $tmp)
        
    Next
EndIf

While 1
    
    $msg = GUIGetMsg()
    Select
        
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $selectbutton
        ;;;;;
            
    EndSelect
WEnd
Exit

It reads in the User names from an ini such as :

[Users]
User1=Tom
User2=Dick
User3=Harry
User4=George
User5=Fred

Hope this helps...

Share this post


Link to post
Share on other sites

Thanks Stix, I'll give yours a go later today.

Share this post


Link to post
Share on other sites

Stix, I owe you big time for that - just spent 20 mins making my ini [ 434 lines ] file using excel and notepad - [ file and replace etc ] - stuck it in your code and BAM !!

I will now start writing the rest of the code I need - many many thanks. You have saved a laptop from going out the window.... B)

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