Sign in to follow this  
Followers 0
controlledchaos

radio buttons and filewritelog

2 posts in this topic

#1 ·  Posted (edited)

hi!

i have a gui that records when a user logs in/out of an online class, and i was wondering how do i get which radio button was clicked to be recorded into the log file? the script records the students name, time and date but i have radio buttons that say entered or exited class and i wanted to have that info also record to the log file to show what the user did and when. any ideas?

thanks, melanie :whistle:

;Include constants
#include <GUIConstants.au3>
#include <file.au3>
#include <date.au3>

;Initialize variables
Global $GUIWidth
Global $GUIHeight
Global $Edit_1

$GUIWidth = 300
$GUIHeight = 250

;Create window
GUICreate("Classroom Attendance Monitor", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it
;$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

;$input1 = GUICtrlCreateInput("Notes: ",10,50,120,15,-1,)
$radio1 = GUICtrlCreateRadio ("Entered Class",10, 10, 120, 15)
$radio2 = GUICtrlCreateRadio ("Exited Class",10, 30, 120, 15)
GUICtrlCreateLabel("Notes: ",10,50,30,15,-1,)
$Notes=GUICtrlCreateInput("",45,50,120,20,-1,)

$StudentName=GUICtrlCreateCombo ("Student1", 10,70) 
GUICtrlSetData(-1,"Student2|Student3","Student3") 
;$input = InputBox("Name?", "Enter Your Name Here")
;$input2 = GUICtrlCreateInput

;Create an "OK" button
$OK_Btn = GUICtrlCreateButton("OK", 75, 210, 70, 25)

;Create a "CANCEL" button
$Cancel_Btn = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)

;Show window/Make the window visible
GUISetState(@SW_SHOW)

;Loop until:
;- user presses Esc
;- user presses Alt+F4
;- user clicks the close button
While 1
 ;After every loop check if the user clicked something in the GUI window
   $msg = GUIGetMsg()

   Select
   
    Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
           ;MsgBox(64, 'Info:', 'You clicked the Radio 1 and it is Checked.')
            $radiovalue=GUICtrlRead($radio1)
    Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
           ;MsgBox(64, 'Info:', 'You clicked on Radio 2 and it is Checked.')
            $radiovalue=guictrlread($radio2)

   
    ;Check if user clicked on the close button
      Case $msg = $GUI_EVENT_CLOSE
       ;Destroy the GUI including the controls
        ;GUIDelete()
       ;Exit the script
        ;Exit
         
    ;Check if user clicked on the "OK" button
      Case $msg = $OK_Btn
        ;MsgBox(64, "New GUI", "You clicked on the OK button!")
         $input = GUICtrlRead($Notes)
         $input2=GUICtrlRead($StudentName)
         
         
         GUIDelete()
         ExitLoop
               
    ;Check if user clicked on the "CANCEL" button
      Case $msg = $Cancel_Btn
         MsgBox(64, "New GUI", "Now Quitting")
         GUIDelete
         Exit
         
         
   EndSelect

WEnd

;MsgBox(0,$Input,$Input)
$file = FileOpen("text.txt", 2)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$write_me=chr(9)&$input&chr(9)&$input2&chr(9)&$radiovalue

_FileWriteLog("text.txt", $input)
_FileWriteLog("text.txt",chr(9))
_FileWriteLog("text.txt",$input2)
_FileWriteLog("text.txt",$write_me)
_FileWriteLog($file,@MON&"-"@MDAY&"-"&@YEAR& "/" @HOUR&":"&@MIN&":"&@SEC&)

FileClose($file)

also, if someone can take a look at this code and tell me what i am doing wrong? it gives me an error but it does save the log file. i just want one line of information tho. date/time student and whether they entered or exited a class. any ideas?

Edited by controlledchaos

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

;MsgBox(0,$Input,$Input)
$file = FileOpen("text.txt", 2)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$write_me=chr(9)&$input&chr(9)&$input2&chr(9)&$radiovalue

_FileWriteLog("text.txt", $input)
_FileWriteLog("text.txt",chr(9))
_FileWriteLog("text.txt",$input2)
_FileWriteLog("text.txt",$write_me)
_FileWriteLog($file,@MON&"-"@MDAY&"-"&@YEAR& "/" @HOUR&":"&@MIN&":"&@SEC&)

FileClose($file)

also, if someone can take a look at this code and tell me what i am doing wrong? it gives me an error but it does save the log file. i just want one line of information tho. date/time student and whether they entered or exited a class. any ideas?

Maybe something like this. I would use a function for it.

;Include constants
#include <GUIConstants.au3>
#include <file.au3>
#include <date.au3>

;Initialize variables
Global $GUIWidth
Global $GUIHeight
Global $Edit_1
Local  $Status
$GUIWidth = 300
$GUIHeight = 250

;Create window
GUICreate("Classroom Attendance Monitor", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it
;$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

;$input1 = GUICtrlCreateInput("Notes: ",10,50,120,15,-1,)
$radio1 = GUICtrlCreateRadio ("Entered Class",10, 10, 120, 15)
$radio2 = GUICtrlCreateRadio ("Exited Class",10, 30, 120, 15)
GUICtrlCreateLabel("Notes: ",10,50,30,15,-1,)
$Notes=GUICtrlCreateInput("",45,50,120,20,-1,)

$StudentName=GUICtrlCreateCombo ("Student1", 10,70) 
GUICtrlSetData(-1,"Student2|Student3","Student3") 
;$input = InputBox("Name?", "Enter Your Name Here")
;$input2 = GUICtrlCreateInput

;Create an "OK" button
$OK_Btn = GUICtrlCreateButton("OK", 75, 210, 70, 25)

;Create a "CANCEL" button
$Cancel_Btn = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)

;Show window/Make the window visible
GUISetState(@SW_SHOW)

;Loop until:
;- user presses Esc
;- user presses Alt+F4
;- user clicks the close button
While 1
;After every loop check if the user clicked something in the GUI window
   $msg = GUIGetMsg()

   Select
   
    Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
           ;MsgBox(64, 'Info:', 'You clicked the Radio 1 and it is Checked.')
            
    Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
           ;MsgBox(64, 'Info:', 'You clicked on Radio 2 and it is Checked.')
            

   
    ;Check if user clicked on the close button
      Case $msg = $GUI_EVENT_CLOSE
       ;Destroy the GUI including the controls
        ;GUIDelete()
       ;Exit the script
        ;Exit
         
    ;Check if user clicked on the "OK" button
      Case $msg = $OK_Btn
        ;MsgBox(64, "New GUI", "You clicked on the OK button!")
         WriteLog()        
         GUIDelete()
         ExitLoop
               
    ;Check if user clicked on the "CANCEL" button
      Case $msg = $Cancel_Btn
         MsgBox(64, "New GUI", "Now Quitting")
         GUIDelete
         Exit
         
         
   EndSelect

WEnd

;MsgBox(0,$Input,$Input)

Func WriteLog() 
$file = FileOpen("text.txt", 2)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$input = GUICtrlRead($Notes)
$input2=GUICtrlRead($StudentName)
If GuiCtrlRead($radio1) = $GUI_CHECKED Then
$Status = "Entered Class"
ElseIf GuiCtrlRead($radio2) = $GUI_CHECKED Then
$Status = "Exited Class"
EndIf

$write_me=chr(9)&$input&chr(9)&$input2&chr(9)

_FileWriteLog("text.txt", $input)
_FileWriteLog("text.txt",chr(9))
_FileWriteLog("text.txt",$input2)
_FileWriteLog("text.txt",$write_me)
_FileWriteLog("text.txt",$Status)
;_FileWriteLog($file,@MON&"-"@MDAY&"-"&@YEAR& "/" @HOUR&":"&@MIN&":"&@SEC&)

FileClose($file)
EndFunc

Also why to do you tell it to write out the date and time. That function was designed to do that by default.

Also what error message do you get?

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

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