MattX Posted June 2, 2005 Share Posted June 2, 2005 My ultimate aim is to have the selected item [ which will be a PC name ] stuck on the clipboard and then transfered to a WinVnc viewer but to get started I wanted to make sure the $PC returned the correct name - problem I have is that its returning the number 1 all the time. Can someone please tell me where I am going wrong. Also as I have over 100 PCs to put in the combo box would it be easier to have these selected as a txt file ? And if so how would I introduce that into a combo box ? Would you have to read the txt file in as a string first ? Sorry for the questions !! My code - so far: GuiCreate("MyGUI", 347, 123,(@DesktopWidth-347)/2, (@DesktopHeight-123)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) Dim $PC = "" $Combo_1 = GuiCtrlCreateCombo("Combo1", 50, 50, 240, 21) $PC = GUICtrlSetData(-1,"item1|item2|item3|item4|number5|number6", "item1") $ok = GuiCtrlCreateButton("OK", 100, 80, 140, 30) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $ok MsgBox(64, "You selected:", $PC) Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit Link to comment Share on other sites More sharing options...
MattX Posted June 2, 2005 Author Share Posted June 2, 2005 Think I have done it with a:msgbox(0,"list=", GUICtrlRead($Combo_1)) instead of:MsgBox(64, "You selected:", $PC)Still would appreciate some advice on the reading the combo entries from a text file though....My ultimate aim is to have the selected item [ which will be a PC name ] stuck on the clipboard and then transfered to a WinVnc viewer but to get started I wanted to make sure the $PC returned the correct name - problem I have is that its returning the number 1 all the time. Can someone please tell me where I am going wrong.Also as I have over 100 PCs to put in the combo box would it be easier to have these selected as a txt file ? And if so how would I introduce that into a combo box ? Would you have to read the txt file in as a string first ? Sorry for the questions !!My code - so far:GuiCreate("MyGUI", 347, 123,(@DesktopWidth-347)/2, (@DesktopHeight-123)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) Dim $PC = "" $Combo_1 = GuiCtrlCreateCombo("Combo1", 50, 50, 240, 21) $PC = GUICtrlSetData(-1,"item1|item2|item3|item4|number5|number6", "item1") $ok = GuiCtrlCreateButton("OK", 100, 80, 140, 30) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $ok MsgBox(64, "You selected:", $PC) Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
Joel Posted June 2, 2005 Share Posted June 2, 2005 (edited) You could store the entries into a text file, separating them by a comma and then read them into the script using an array. Global $fileread = FileRead("test.txt",10000) ; This reads 10,000 characters of text.txt Global $pc = StringSplit($fileread, ",") ; This splits each of the names at the commas which can be stored in an array. ; ex. james,john,jacob,charlie Global $pcControl[100][1] For $i = 0 To 99 $pcControl[$i][0] = GUICtrlSetData(-1,$pc[$i +1] & "|", $i) Next ; etc. etc. Corrected a mistake. Here ya go. Edited June 2, 2005 by Joel [font="Optima"]"Those who heed life with speculation and contemplation, are the ones stuck home with constipation." - Joel[/font] Link to comment Share on other sites More sharing options...
falconv Posted June 2, 2005 Share Posted June 2, 2005 Or, if you don't know how many characters you want read into the string, you can place each entry on a separate line, and use FileReadLine as so: #include <File.au3>;must have for _FileCountLines $filepath = "C:\Temp\Temp.txt";path to file $file = FileOpen($filepath, 0);opens the file to be read in read-only mode $linecount = _FileCountLines($filepath);count how many lines, so if you add or remove some entries, the script adjusts Dim $line[$linecount + 1];declare how many entries there are, based on the above line. (I use +1 so I can have line1, 2, 3 instead of line0, 1, 2) For $n = 1 to $linecount Step 1;loop $line[$n] = FileReadLine($file);read each line into the array If @error = -1 Then ExitLoop;if it hits EoF, move on (just in case it didn't count lines right) Next For $n = 1 to ($linecount) Step 1 MsgBox(0,"test",$line[$n]);display the results Next FileClose($file) another neat way is to use a .ini file, I've fallen in love with those. Link to comment Share on other sites More sharing options...
MattX Posted June 2, 2005 Author Share Posted June 2, 2005 Thanks for both ideas, I'll get cracking on with those.I know what you mean about .INI files - I miss them so much - [ although some apps still use them instead of the registry these days ]Or, if you don't know how many characters you want read into the string, you can place each entry on a separate line, and use FileReadLine as so:#include <File.au3>;must have for _FileCountLines $filepath = "C:\Temp\Temp.txt";path to file $file = FileOpen($filepath, 0);opens the file to be read in read-only mode $linecount = _FileCountLines($filepath);count how many lines, so if you add or remove some entries, the script adjusts Dim $line[$linecount + 1];declare how many entries there are, based on the above line. (I use +1 so I can have line1, 2, 3 instead of line0, 1, 2) For $n = 1 to $linecount Step 1;loop $line[$n] = FileReadLine($file);read each line into the array If @error = -1 Then ExitLoop;if it hits EoF, move on (just in case it didn't count lines right) Next For $n = 1 to ($linecount) Step 1 MsgBox(0,"test",$line[$n]);display the results Next FileClose($file)another neat way is to use a .ini file, I've fallen in love with those. <{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
falconv Posted June 2, 2005 Share Posted June 2, 2005 If you're interested, here's another dynamic updating script using a .ini file (much shorter and easier!) $ini = "C:\Temp\Temp.ini" ;path to .ini file $entry = IniReadSection($ini, "section") ;put all entries into an array For $n = 1 to $entry[0][0] Step 1 ;go through all entries in the given section MsgBox(0,"test",$entry[$n][1]) ;display the results Next Here's what the .ini looks like: [section] 1=this 2=is 3=only 4=a 5=test and for the fun of it, here's a script that will let you enter the data into the .ini instead of making it manually and worrying about format. $ini = "C:\Temp\Temp.ini" ;path to .ini file #include <File.au3> ;only needed if next line is used _FileCreate($ini) ;only use if you want to clear old entries $n = 1 While 1 $text = InputBox("Entry " & $n, "Enter data for Entry " & $n) If @error = 1 then ExitLoop IniWrite($ini, "section", $n, $text) $n = $n+1 WEnd 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