Jump to content

GUICtrlRead only works once?


grakker
 Share

Recommended Posts

OK, this is a follow-up to a thread I started over here. Basically I have to write up my students. A lot. I wrote up this little script to save the information in ini files for each class, and save the actual write-ups in a report folder. Now, this is still rough in many places, but I've been using it and it seems to be doing the job.

The problem I have is, I run it the first time and it reads the name of the student and puts it in the report. From that point on, any report I write up uses that first student's name. No matter who is actually in the name field on my report. So everytime I write up a student, I have to exit the script and then start it again. Not show stopping, but this is very annoying.

The function I use is Make_report() and starts on line 240. The first line reads the contents of my student name and should update the $student variable, but it doesn't. I'm a little frustrated at this point.

I have attached a zip of the folder I use. It creates the ini files and entries as they are needed. And I shuffled my student list so no first name is with the last name, if anyone is worried about privacy.

Writing_Up_students.zip

Link to comment
Share on other sites

change the following function as follows:

Func Make_report()
    _SetDefaultText()
    $student = StringLeft(GUICtrlRead($InfStudent), StringLen(GUICtrlRead($InfStudent)) - 4)
    $Infraction_Date = GUICtrlRead($InfDate)
    $large_text = GUICtrlRead($InfText)
    $finished = GUICtrlRead($Task_Closed)
;writing to file here....
    Local $filename = "Reports/" & GUICtrlRead($InfStudent) & "_" & $Infraction & "_" & StringReplace($Infraction_Date, "/", "-") & "-" & Random(1000,9999,1) & ".txt"
    $file = FileOpen($filename, $writing_mode)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.  Exiting Program")
        Exit
    EndIf

    Local $report_file_name = $filename
    $Header = StringReplace($Header, "%%%", $Period)
    $Header = StringReplace($Header, "@@@", GUICtrlRead($InfDate))
    $Header = StringReplace($Header, "STUDENT NAME", $student)
    FileWrite($file, $Header & $large_text)
    FileClose($file)
    If Not FileExists($filename) Then
        MsgBox(0, "WARNING", "Report was not saved.  You really should look into this.", 5)
    Else
        If MsgBox(1, "Print Report", "Do you want to print the report?", 5) = 1 Then
            $tmp = FileRead($filename)
            $tmp_file = _TempFile () & ".txt"
            FileWrite($tmp_file, $tmp)
            FileWrite($tmp_file, @CRLF & @CRLF & "------------------------------------------------------------------------" & @CRLF & @CRLF)
            FileWrite($tmp_file, $tmp)
            _FilePrint($tmp_file)
        EndIf
    EndIf
    
; This is where I update the ini file
    
    $filename = $ClassRoom_Loc & $Period & ".ini"
    If Not FileExists($filename) Then
        MsgBox(0, "Warning", "INI file did not exist for " & $Period & " Period.  File will be created.  You might want to check this...", 5)
    EndIf
    
    Local $iniArray = IniReadSection($filename, $student)
    If @error Then
        MsgBox(0, "First Time", "Seems to be the first time " & $student & " has been written up." & @CRLF & @CRLF & "Adding student to " & $filename, 5)
        IniWrite($filename, $student, "1", "1" & "#" & $finished & "#" & GUICtrlRead($InfDate) & "#" & $Infraction & "#" & StringRight($report_file_name, StringLen($report_file_name) - 8))
        
    Else
        If StringIsInt($report_number) Then
            IniWrite($filename, $student, $report_number, $report_number & "#" & $finished & "#" & GUICtrlRead($InfDate) & "#" & $Infraction & "#" & StringRight($report_file_name, StringLen($report_file_name) - 8))
            $report_number = "not a number"
        Else
            Local $i = 1
            While IniRead($filename, $student, $i, "not") <> "not"
                $i = $i + 1
            WEnd
            IniWrite($filename, $student, $i, $i & "#" & $finished & "#" & GUICtrlRead($InfDate) & "#" & $Infraction & "#" & StringRight($report_file_name, StringLen($report_file_name) - 8))
        EndIf
    EndIf
    $writing_mode = 1
    
            set_listview()
            GUICtrlSetState($InfText, $GUI_HIDE)
            GUICtrlSetState($InfListview, $GUI_SHOW)
    
EndFunc  ;==>Make_report
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

change the following function as follows:

Func Make_report()
    _SetDefaultText()
    $student = StringLeft(GUICtrlRead($InfStudent), StringLen(GUICtrlRead($InfStudent)) - 4)

That did it! Thank you so much. I've never even seen that function before.

Link to comment
Share on other sites

It was in your source file

That's what I get for posting before work, at 5 whatever in the morning. I logged on, saw your post, tried it, it worked, and posted. Then I logged off. Then in the shower I woke up a little more and smacked my head as I realized, yep, I wrote that....

Still don't understand how it resets the student name, but it works so thank you again. I've cleaned it a little more and actually had a fellow teacher ask me if I could put together a similiar thing for him. I guess that he heard about it from some of the students.

I haven't had the time to log back on until now (they block anything with 'forum' in the URL at work. A little too busy there anyway.

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...