Jump to content

GUICtrlRead


Recommended Posts

Hi,

having problems getting GUIctrlread to send the proper information to the file. here's my code, any suggestions?

thanks, melanie

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

;Initialize variables
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 300
$GUIHeight = 250

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

;Creates a drop down list of student names.
GUICtrlCreateLabel("Student Name:",10,10) 
$StudentName = GUICtrlCreateCombo ("Student1",10,25) 
GUICtrlSetData(-1,"Student2|Student3")

;Creates radio buttons for classroom state.
$Entered = GUICtrlCreateRadio("Entered Classroom",10,50)
$Exited = GUICtrlCreateRadio("Exited Classroom",10,75)

;Creates a drop down list for classroom state.
;GUICtrlCreateLabel("Enter/Exit Classroom:",10,50)
;$ClassState = GUICtrlCreateCombo ("Entered Classroom",10,65)
;GUICtrlSetData(-1,"Exited Classroom")

;Creates an input box for notes.
GUICtrlCreateLabel("Notes: ",10,95)
$Notes=GUICtrlCreateInput("",10,110,250,75)

;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
   
     ;Check if user clicked on the close button
      Case $msg = $GUI_EVENT_CLOSE
        ;Destroy the GUI including the controls
        GUIDelete()
       
         
     ;Check if user clicked on the "OK" button
      Case $msg = $OK_Btn
         MsgBox(64, "OK", "You clicked the OK button!")
         $input=GUICtrlRead($Notes)
         $input2=GUICtrlRead($StudentName)
         $input3=GUICtrlRead($Entered)
         $input4=GUICtrlRead($Exited)
         
         ExitLoop
               
     ;Check if user clicked on the "CANCEL" button
      Case $msg = $Cancel_Btn
         MsgBox(64, "Cancel", "Now Quitting")
         Exit
         
         
   EndSelect

WEnd

Do
    $msg = GUIGetMsg()
        If $Entered = $GUI_CHECKED  Then MsgBox(4096,"",GUICtrlRead($Entered,1) 
        If $Exited = $GUI_CHECKED  Then MsgBox(4096,"",GUICtrlRead($Exited,1)
   
Until $msg = $GUI_EVENT_CLOSE

$file = FileOpen("text.txt", 1)

; 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)&$input3&chr(9)&$input4

_FileWriteLog("S:/VSA Items/BigBoard/text.txt", $write_me)

FileClose($file)
Link to comment
Share on other sites

If $Entered = $GUI_CHECKED  Then MsgBox(4096,"",GUICtrlRead($Entered,1))
If $Exited = $GUI_CHECKED  Then MsgBox(4096,"",GUICtrlRead($Exited,1))

Don't know if that's what you wanted, but you had two Open parenthesis and only one close.

Edited by Slaiochi
Link to comment
Share on other sites

If $Entered = $GUI_CHECKED  Then MsgBox(4096,"",GUICtrlRead($Entered,1))
If $Exited = $GUI_CHECKED  Then MsgBox(4096,"",GUICtrlRead($Exited,1))

Don't know if that's what you wanted, but you had two Open parenthesis and only one close.

not sure if that made a difference but it returns numeric data, i am assuming the state of the radio button(checked or unchecked). I am trying to get it to return the text of the radio button (entered or exited).

thanks :shocked:

melanie

Link to comment
Share on other sites

not sure if that made a difference but it returns numeric data, i am assuming the state of the radio button(checked or unchecked). I am trying to get it to return the text of the radio button (entered or exited).

thanks :shocked:

melanie

When you use GuiCtrlRead on a radio button you are trying to see what state its in, either Checked or Unchecked which returns a numeric value.

If you know what you want to be there then why not just put that value in the msgbox to begin with instead of trying to read the state. If it were a label then it would tell you what data was in the label. You could also set a var.

Why not do something like

If GuiCtrlRead($Exited) = $GUI_CHECKED  Then MsgBox(4096,"","Exited Classroom")
Edited by EndFunc
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

Whether it helped or not isn't a question as this was a syntax error =P

BTW:

$GUI_UNCHECKED = 4

$GUI_INDETERMINATE = 2

$GUI_CHECKED = 1

so you could do

If GuiCtrlRead($Exited) = 1  Then MsgBox(4096,"","Exited Classroom")
Edited by Slaiochi
Link to comment
Share on other sites

When you use GuiCtrlRead on a radio button you are trying to see what state its in, either Checked or Unchecked which returns a numeric value.

If you know what you want to be there then why not just put that value in the msgbox to begin with instead of trying to read the state. If it were a label then it would tell you what data was in the label. You could also set a var.

Why not do something like

If GuiCtrlRead($Exited) = $GUI_CHECKED  Then MsgBox(4096,"","Exited Classroom")

a message box isnt what i am looking for. the information is being saved to alog file to record who came and went from an online class. i need to keep track of who entered/exited and when. i will give your suggestion a try tho. thanks for the insight!

Link to comment
Share on other sites

a message box isnt what i am looking for. the information is being saved to alog file to record who came and went from an online class. i need to keep track of who entered/exited and when. i will give your suggestion a try tho. thanks for the insight!

Then just set a Variable to it and use that variable in the _FileWriteLog() function.

Maybe something like

Local $nStatus
If GuiCtrlRead($Exited) = $GUI_CHECKED Then
$nStatus = "Exited Classroom"
ElseIf GuiCtrlRead($Entered) = $GUI_CHECKED Then
$nStatus = "Entered Classroom"
EndIf

_FileWriteLog("C:\logfile.log", $nStatus)
Edited by EndFunc
EndFuncAutoIt is the shiznit. I love it.
Link to comment
Share on other sites

Then just set a Variable to it and use that variable in the _FileWriteLog() function.

Maybe something like

Local $nStatus
If GuiCtrlRead($Exited) = $GUI_CHECKED Then
$nStatus = "Exited Classroom"
ElseIf GuiCtrlRead($Entered) = $GUI_CHECKED Then
$nStatus = "Entered Classroom"
EndIf

_FileWriteLog("C:\logfile.log", $nStatus)
thank you thank you! yes, this is what i was trying to do! i really appreciate ur help and input.

melanie

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...