MattX Posted November 28, 2005 Share Posted November 28, 2005 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. Link to comment Share on other sites More sharing options...
kpu Posted November 28, 2005 Share Posted November 28, 2005 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 http://www.kpunderground.com Link to comment Share on other sites More sharing options...
Bert Posted November 28, 2005 Share Posted November 28, 2005 I did what you want to do doing this. expandcollapse popup ;#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 My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options... MattX Posted November 28, 2005 MattX Active Members 358 Author Share Posted November 28, 2005 Thanks for the advice chaps, I'll get cracking with it tomorrow. I'll let you know how I get on..... Link to comment Share on other sites More sharing options... Zedna Posted November 28, 2005 Zedna MVPs 9.9k 32 AutoIt rulez! Share Posted November 28, 2005 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 User5You can choose what you prefer: TXT or INI Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
MattX Posted November 29, 2005 Author Share Posted November 29, 2005 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 Link to comment Share on other sites More sharing options...
kpu Posted November 29, 2005 Share Posted November 29, 2005 You just forgot to call the function. This should do it! #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 http://www.kpunderground.com Link to comment Share on other sites More sharing options...
MattX Posted November 29, 2005 Author Share Posted November 29, 2005 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. This should do it! #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 Link to comment Share on other sites More sharing options...
MattX Posted November 29, 2005 Author Share Posted November 29, 2005 One thing I don't understand either is the [$x] on the $aRecords[$x] var - can someone explain that to me... Link to comment Share on other sites More sharing options...
MattX Posted November 29, 2005 Author Share Posted November 29, 2005 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 Link to comment Share on other sites More sharing options...
MattX Posted November 29, 2005 Author Share Posted November 29, 2005 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...... Link to comment Share on other sites More sharing options...
Stix Posted November 30, 2005 Share Posted November 30, 2005 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... Link to comment Share on other sites More sharing options...
MattX Posted November 30, 2005 Author Share Posted November 30, 2005 Thanks Stix, I'll give yours a go later today. Link to comment Share on other sites More sharing options...
MattX Posted November 30, 2005 Author Share Posted November 30, 2005 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.... Link to comment Share on other sites More sharing options...
Stix Posted November 30, 2005 Share Posted November 30, 2005 You're welcome. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now