Iznogoud Posted March 15, 2006 Share Posted March 15, 2006 I am trying to make a script for some logging of informatie before starting a application. You must select the employee, fill in the customer name and if needed a remark. This is my code for start. expandcollapse popup#include <GuiConstants.au3> ; GUI GuiCreate("Netviewer", 499, 458) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; BACKGROUND GUISetBkColor (0xFFFFFF) ; VARIABLES $kantlijn = "70" ; LOGO $n1 = GUICtrlCreatePic("C:\company\logo1.jpg",0,0, 499,160) $n2 = GUICtrlCreatePic("C:\company\logo2.jpg",0,370, 499,88) ; LABELS GUICtrlCreateLabel ("Medewerker :",$kantlijn ,202 ,65 ,20) GUICtrlCreateLabel ("Klantnaam :",$kantlijn ,242 ,65 ,20) GUICtrlCreateLabel ("Opmerking :",$kantlijn ,282 ,65 ,20) ; COMBO BOX $medewerker=GuiCtrlCreatecombo("<medewerker>",$kantlijn+100 , 200, 200, 100) GUICtrlSetData(-1,"Marcel|Rutger|Remco") ; INPUT FIELD $klantnaam=GuiCtrlCreateInput("<klantnaam>",$kantlijn+100, 240, 200, 20) $opmerking=GuiCtrlCreateInput("<opmerking>",$kantlijn+100, 280, 200, 20) ; START BUTTON $start = GUICtrlCreateButton ("Start Netviewer",$kantlijn+125,340,150,20) ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $start ExitLoop EndSelect Wend What i want to do is filling the COMBO BOX with customers names wich must be read from a file. For an example i got a text file: Customers.txt test1 test2 test3 test4 Then the combo box will show in the pull down menu these values test1, test2, test3 and test4. Is this possible? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 15, 2006 Moderators Share Posted March 15, 2006 _FileReadToArray() Or IniRead() << Better Choice it seems GUICtrlRead() GUICtrlSetData() Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
SkyFox Posted March 15, 2006 Share Posted March 15, 2006 What i want to do is filling the COMBO BOX with customers names wich must be read from a file.For an example i got a text file:Customers.txttest1test2test3test4Then the combo box will show in the pull down menu these values test1, test2, test3 and test4.Is this possible?You could open the file for reading then FileReadLine each name then GUICtrlSetData it into the combo box. Link to comment Share on other sites More sharing options...
Iznogoud Posted March 15, 2006 Author Share Posted March 15, 2006 (edited) I was already trying with the iniread, but if i want to add this in my own script i get alot of errors. Now i come to the point of not knowing how to accomplish this yet, because of the experience with programming. I found this example in the help file $var = IniReadSection("C:\Temp\myfile.ini", "section2") If @error Then MsgBox(4096, "", "Error occured, probably no INI file.") Else For $i = 1 To $var[0][0] MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf As far as i can think off, i have to replace the Msgbox.... with GUICtrlSetData(-1, $i) But this doesn't work. Filereadline does work with msgbox but i got the same problem as with the ini. Edited March 15, 2006 by Iznogoud Link to comment Share on other sites More sharing options...
nfwu Posted March 15, 2006 Share Posted March 15, 2006 (edited) expandcollapse popup#include <GuiConstants.au3> ; GUI GuiCreate("Netviewer", 499, 458) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; BACKGROUND GUISetBkColor (0xFFFFFF) ; VARIABLES $kantlijn = "70" ; LOGO $n1 = GUICtrlCreatePic("C:\company\logo1.jpg",0,0, 499,160) $n2 = GUICtrlCreatePic("C:\company\logo2.jpg",0,370, 499,88) ; LABELS GUICtrlCreateLabel ("Medewerker :",$kantlijn ,202 ,65 ,20) GUICtrlCreateLabel ("Klantnaam :",$kantlijn ,242 ,65 ,20) GUICtrlCreateLabel ("Opmerking :",$kantlijn ,282 ,65 ,20) ; COMBO BOX $medewerker=GuiCtrlCreatecombo("<medewerker>",$kantlijn+100 , 200, 200, 100) $wood_data = "" While 1 $line = FileReadLine("customers.txt") If @error = -1 Then ExitLoop $wood_data &= "|"&$line Wend GUICtrlSetData($medewerker, $wood_data) ; INPUT FIELD $klantnaam=GuiCtrlCreateInput("<klantnaam>",$kantlijn+100, 240, 200, 20) $opmerking=GuiCtrlCreateInput("<opmerking>",$kantlijn+100, 280, 200, 20) ; START BUTTON $start = GUICtrlCreateButton ("Start Netviewer",$kantlijn+125,340,150,20) ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $start ExitLoop EndSelect Wend #) Edited March 15, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Iznogoud Posted March 15, 2006 Author Share Posted March 15, 2006 (edited) expandcollapse popup#include <GuiConstants.au3> ; GUI GuiCreate("Netviewer", 499, 458) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; BACKGROUND GUISetBkColor (0xFFFFFF) ; VARIABLES $kantlijn = "70" ; LOGO $n1 = GUICtrlCreatePic("C:\company\logo1.jpg",0,0, 499,160) $n2 = GUICtrlCreatePic("C:\company\logo2.jpg",0,370, 499,88) ; LABELS GUICtrlCreateLabel ("Medewerker :",$kantlijn ,202 ,65 ,20) GUICtrlCreateLabel ("Klantnaam :",$kantlijn ,242 ,65 ,20) GUICtrlCreateLabel ("Opmerking :",$kantlijn ,282 ,65 ,20) ; COMBO BOX $medewerker=GuiCtrlCreatecombo("<medewerker>",$kantlijn+100 , 200, 200, 100) $wood_data = "" While 1 $line = FileReadLine("customers.txt") If @error = -1 Then ExitLoop $wood_data &= "|"&$line Wend GUICtrlSetData($medewerker, $wood_data) ; INPUT FIELD $klantnaam=GuiCtrlCreateInput("<klantnaam>",$kantlijn+100, 240, 200, 20) $opmerking=GuiCtrlCreateInput("<opmerking>",$kantlijn+100, 280, 200, 20) ; START BUTTON $start = GUICtrlCreateButton ("Start Netviewer",$kantlijn+125,340,150,20) ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $start ExitLoop EndSelect Wend #) I got this error "Expected a "=" operator in assignment statement.: " at this line " $wood_data &= "|"&$line" Must it not between " " ? I am still trying to understand that part At syntax check i got no errors. Edited March 15, 2006 by Iznogoud Link to comment Share on other sites More sharing options...
SkyFox Posted March 15, 2006 Share Posted March 15, 2006 ; Replace this $wood_data &= "|"&$line ; With this $wood_data = $wood_data & "|" & $line Try that Link to comment Share on other sites More sharing options...
Iznogoud Posted March 15, 2006 Author Share Posted March 15, 2006 (edited) ; Replace this $wood_data &= "|"&$line ; With this $wood_data = $wood_data & "|" & $line Try that The script does start now, but it hangs. Edited the post because i was so stupid as i could ever be. Finally there was a and i understand a little bit more of this code. I keep trying, trying, trying in the mean while. -=Edit=- I have adjusted the code with a msgbox $line = FileReadLine("C:\Mareco\customers.txt") If @error = -1 Then ExitLoop MsgBox(4096, "Test", $line) $wood_data = $wood_data & "|" & $line It keeps saying test1 Edited March 15, 2006 by Iznogoud Link to comment Share on other sites More sharing options...
SkyFox Posted March 15, 2006 Share Posted March 15, 2006 $line = FileReadLine("C:\Mareco\customers.txt") If @error = -1 Then ExitLoop MsgBox(4096, "Test", $line) $wood_data = $wood_data & "|" & $line It keeps saying test1You have to create a handle to the file before you read any lines from it, otherwise it will just keep reading the first line in the file. $File = FileOpen("C:\Mareco\customers.txt", 0) If $File = -1 Then Exit $medewerker=GuiCtrlCreatecombo("<medewerker>",$kantlijn+100 , 200, 200, 100) $wood_data = "" While 1 $line = FileReadLine($File) If @error = -1 Then ExitLoop $wood_data = $wood_data & "|" & $line Wend GUICtrlSetData($medewerker, $wood_data) Link to comment Share on other sites More sharing options...
Iznogoud Posted March 15, 2006 Author Share Posted March 15, 2006 (edited) You have to create a handle to the file before you read any lines from it, otherwise it will just keep reading the first line in the file. $File = FileOpen("C:\Mareco\customers.txt", 0) If $File = -1 Then Exit $medewerker=GuiCtrlCreatecombo("<medewerker>",$kantlijn+100 , 200, 200, 100) $wood_data = "" While 1 $line = FileReadLine($File) If @error = -1 Then ExitLoop $wood_data = $wood_data & "|" & $line Wend GUICtrlSetData($medewerker, $wood_data) Ah man, i finally understood the code and tried it first on a new script. $klantenbestand = FileOpen("C:\Mareco\customers.txt", 0) $wood_data = "" ; Check if file opened for reading OK If $klantenbestand = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($klantenbestand) If @error = -1 Then ExitLoop $wood_data = $wood_data & "|" & $line MsgBox(0, "Line read:", $line) Wend MsgBox(0, "Line read:", $wood_data) FileClose($klantenbestand) And yes i have finally found the problem and that was exact the same as you described. Getting proud on myself Thanks for your great help, you guys are the man Edited March 15, 2006 by Iznogoud Link to comment Share on other sites More sharing options...
SkyFox Posted March 15, 2006 Share Posted March 15, 2006 Way to go, glad I could help out Link to comment Share on other sites More sharing options...
Iznogoud Posted March 15, 2006 Author Share Posted March 15, 2006 You guys are GREAT I got one more question: Is it possible to add a non excisting customer to the customers.txt if it does not already excits? For an example: The customer AUTOIT does not excist, i type the name in the field and it will add its own to the list of customers.txt or if we add a name like OTHER and change the code if value is OTHER then a box will open where you can fill in the name of the new customer wich will be displayed next time you start the program. I think this is possible but you have to check what kind of value is selected in the pulldown menu. And so we are coming to my other part of my question. Is it possible to check if the user has filled in all the fields wich are required? All the fields must be filled with information, names, etc. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 15, 2006 Moderators Share Posted March 15, 2006 You guys are GREAT I got one more question: Is it possible to add a non excisting customer to the customers.txt if it does not already excits? For an example: The customer AUTOIT does not excist, i type the name in the field and it will add its own to the list of customers.txt or if we add a name like OTHER and change the code if value is OTHER then a box will open where you can fill in the name of the new customer wich will be displayed next time you start the program.FileWriteLine() I think this is possible but you have to check what kind of value is selected in the pulldown menu. And so we are coming to my other part of my question. Is it possible to check if the user has filled in all the fields wich are required? All the fields must be filled with information, names, etc.#include <guiconstants.au3> Local $ComboData = '' $Main_GUI = GUICreate('Test', 200, 100) $Combo = GUICtrlCreateCombo('', 10, 10, 180, 100) For $i = 1 To 100 $ComboData = $ComboData & $i & '|' Next GUICtrlSetData($Combo, $ComboData) GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE Exit Case $Msg = $Combo MsgBox(0, 'Value', 'The Value in the Combo Box is = ' & GUICtrlRead($Combo)) EndSelect WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Iznogoud Posted March 15, 2006 Author Share Posted March 15, 2006 Good thing that your head wont grow as big as your knowledge is Thx, i will try it tomorrow. First thing first NN Link to comment Share on other sites More sharing options...
Iznogoud Posted March 16, 2006 Author Share Posted March 16, 2006 (edited) In addition to this topic i got one more questionThis is my code now:expandcollapse popup#include <GuiConstants.au3> ; GUI Breedte x Hoogte GuiCreate("Netviewer", 499, 558) ; BACKGROUND GUISetBkColor (0xFFFFFF) ; VARIABLES $kantlijn = "70" $Datum = (@MDAY & "-" & @MON & "-" & @YEAR) $Gebruiktetijdinmin=0 $Klanten="" $Medewerkers="" ; CHECKING FILES $logfile = FileOpen("C:\company\Log.csv", 1) If $logfile = -1 Then MsgBox(0, "Error - (Log bestand)", "Kan het bestand niet openen.") Exit EndIf $klantfile = FileOpen("C:\companyKlanten.txt", 0) If $klantfile = -1 Then MsgBox(0, "Error - (Klanten bestand)", "Kan het bestand niet openen.") Exit EndIf $medewerkersfile = FileOpen("C:\company\Medewerkers.txt", 0) If $medewerkersfile = -1 Then MsgBox(0, "Error - (Medewerkers bestand)", "Kan het bestand niet openen.") Exit EndIf ; LOGO GUICtrlCreatePic("C:\company\logo1.jpg",0,0, 499,160) GUICtrlCreatePic("C:\company\logo2.jpg",0,470, 499,88) ; LABELS GUICtrlCreateLabel ("Medewerker :",$kantlijn ,202 ,65 ,20) GUICtrlCreateLabel ("Klantnaam :",$kantlijn ,242 ,65 ,20) GUICtrlCreateLabel ("Opmerking 1 :",$kantlijn ,282 ,66 ,20) GUICtrlCreateLabel ("Opmerking 2 :",$kantlijn ,322 ,66 ,20) ; COMBO BOX $medewerker=GuiCtrlCreatecombo("<medewerker>",$kantlijn+100 , 200, 200, 100) While 1 $Wline = FileReadLine($Medewerkersfile) If @error = -1 Then ExitLoop $Medewerkers = $Medewerkers & "|" & $Wline WEnd GUICtrlSetData(-1, $Medewerkers) $klantnaam=GuiCtrlCreatecombo("<klantnaam>",$kantlijn+100, 240, 200, 20) While 1 $Kline = FileReadLine($klantfile) If @error = -1 Then ExitLoop $Klanten = $Klanten & "|" & $Kline WEnd GUICtrlSetData(-1, $Klanten) ; INPUT FIELD $opmerking1=GuiCtrlCreateInput("<opmerking>",$kantlijn+100, 280, 200, 20) $opmerking2=GuiCtrlCreateInput("<opmerking>",$kantlijn+100, 320, 200, 20) ; START BUTTON $start = GUICtrlCreateButton ("Start Netviewer",$kantlijn+125,380,150,20) ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $start ; BEGINTIJD $BegintijdUur=(@HOUR) $BegintijdMin=(@MIN) $Begintijd=($BegintijdUur & ":" & $BegintijdMin) ExitLoop EndSelect Wend ; START APPLICATION Run("notepad.exe") ProcessWaitClose("notepad.exe") ; EINDTIJD $EindtijdUur=(@HOUR) $EindtijdMin=(@MIN) $Eindtijd=($EindtijdUur & ":" & $EindtijdMin) ; GEBRUIKTETIJD $Gebruiktetijd=(($EindtijdUur-$BegintijdUur) & " uur en " & ($EindtijdMin-$BegintijdMin) & " minuten" ) ; GEBRUIKTETIJDINMIN $Gebruiktetijdinmin=(($EindtijdUur-$BegintijdUur)*60+($EindtijdMin-$BegintijdMin)) FileWriteLine($logfile, $Datum & ";" & $Begintijd & ";" & $Eindtijd & ";" & $Gebruiktetijdinmin & ";" & $Gebruiktetijd & ";" & GUICtrlRead($medewerker) & ";" & GUICtrlRead($klantnaam) & ";" & GUICtrlRead($opmerking1) & ";" & GUICtrlRead($opmerking2)) FileClose($logfile) FileClose($klantfile) FileClose($medewerkersfile)After this part of the code ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $start ; BEGINTIJD $BegintijdUur=(@HOUR) $BegintijdMin=(@MIN) $Begintijd=($BegintijdUur & ":" & $BegintijdMin) ExitLoop EndSelect Wend ; START APPLICATION Run("notepad.exe") ProcessWaitClose("notepad.exe")When you close the application it will write somethings to the file. What i am trying to do is before the FileWriteLine and after setting those variables to reactivate the GUI where you can fill in the last INPUT field named $opmerking2 and if its possible that the START button change in EXIT button.To make it more difficult i want to block input from all the fields except the last INPUT field.I have tried this code:; START BUTTON $start=GUICtrlSetState(-1,$GUI_DISABLE) $medewerker=GUICtrlSetState(-1,$GUI_DISABLE) $klantnaam=GUICtrlSetState(-1,$GUI_DISABLE) $opmerking1=GUICtrlSetState(-1,$GUI_DISABLE) ; GUI MESSAGE LOOP While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $start ExitLoop EndSelect WendI put this afther the variables, but only the button is disabled and not the fields.What can i do best? close the GUI and recreat a new one with the variables or is there a way to refresh the original GUI and block some fields and change the button?I hope it is clear and not to long story. Edited March 16, 2006 by Iznogoud Link to comment Share on other sites More sharing options...
Iznogoud Posted March 16, 2006 Author Share Posted March 16, 2006 I have found a solution, this code i have created and put after the first WHILE loop. ; START BUTTON GUICtrlSetState($start, $GUI_HIDE) GUICtrlSetState($medewerker, $GUI_DISABLE) GUICtrlSetState($klantnaam, $GUI_DISABLE) GUICtrlSetState($opmerking1, $GUI_DISABLE) GUICtrlSetState($labelmedewerker, $GUI_DISABLE) GUICtrlSetState($labelklantnaam, $GUI_DISABLE) GUICtrlSetState($labelopmerking1, $GUI_DISABLE) ; START BUTTON $afsluiten = GUICtrlCreateButton ("Afsluiten",$kantlijn+125,380,150,20) ; GUI MESSAGE LOOP While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $afsluiten ExitLoop EndSelect Wend If you close the application, the GUI will be reactivated and you see the changes from active to non active in 1 sec and the button i have hided and recreated you. So you see the changes but if you want to change something that fast you must be superman 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