BlackFlag

Select a specific radio button, quick exit

6 posts in this topic

My very simple code.

#include <Constants.au3>
#include <GUIConstants.au3>
#include <File.au3>
#Include<Array.au3>
#Include<Date.au3>

$Work = GUICreate("Work Journal", 623, 330, 192, 114)
$Edit1 = GUICtrlCreateEdit("", 8, 16, 505, 265)
;GUICtrlSetData(-1, "Edit1")
$Save = GUICtrlCreateButton("Save", 8, 288, 73, 25)
$Label1 = GUICtrlCreateLabel("Tags", 536, 24, 43, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Vessel = GUICtrlCreateRadio("Vessel Issue", 528, 56, 81, 25)
$Bad = GUICtrlCreateRadio("Bad  News", 528, 88, 89, 25)
$WhattheHell = GUICtrlCreateRadio("Dev Issue", 528, 120, 89, 25)
$Watch = GUICtrlCreateRadio("Watching", 528, 152, 89, 25)
GUISetState(@SW_SHOW)

$TheJournal=fileopen("C:\Documents and Settings\Daniel\My Documents\Work Journal\WorkNotes.txt",1)
While 1

Switch GUIGetMsg()
            

            Case $Save
               $Watching=GUICtrlRead($Watch)
               $BadNews=GUICtrlRead($Bad)
               $Boat=GUICtrlRead($Vessel)
               $What=GUICtrlRead($WhattheHell)
               $TextInfo=GUICtrlRead($Edit1)
               $Today =_NowDate()
               Filewrite($TheJournal,"---------------------------------"&@CRLF)
               FileWrite ($TheJournal,$Today&@CRLF&@CRLF)
               FileWrite($TheJournal,$TextInfo&@CRLF)
               Exit

EndSwitch

WEnd

When I run this it usually works fine.  However, when I click on Dev Issue the program, when ran in SciTE anyway, does an immediate exit.  There are no messages and Exit code= 0.  The rest of the radio button work fine.

A) Does this crash for anyone else?
B) Do I have an error I am just missing?
C) If not B, anyone have a clue what is going on here?

 

Share this post


Link to post
Share on other sites



Don't forget close file handle.  FileClose($TheJournal) maybe for that the app is not Flushing the data.

Saludos

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Works fine for me. In that it doesn't crash on any click anywhere, and that it writes to the defined textfile. Which Windows version are you using, is there any other code in your script, any directives used on top?

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Xp is what it is being tested on.  This is for a couple of my users, one of which has to use xp due to legacy issues.  I will try it on one of our Win 7 machines on Monday.  I should have thought of that myself :)

At the moment, that is the entire script.  I just started the project.

Share this post


Link to post
Share on other sites

Works well on my XP with no crash - and I can't see a reason why it sould crash  :blink:

Share this post


Link to post
Share on other sites

BlackFlag,

I cannot get it to fail either. 

After looking at your code I made some changes...

1 - got rid of intermediate variables

2 - added header formatting from radio button text (the only reason I could see for the vars you were setting)

3 - added a limit to edit control (100000 characters)

4 - changed "exit" to "exitloop"

5 - added a display of the file

6 - changed the filename

See the comments in code....

#include <Constants.au3>
#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Date.au3>

$Work = GUICreate("Work Journal", 623, 330, 192, 114)
$Edit1 = GUICtrlCreateEdit("", 8, 16, 505, 265)
GUICtrlSetLimit(-1, 100000) ; set limit to 100000 characters
$Save = GUICtrlCreateButton("Save", 8, 288, 73, 25)
$Label1 = GUICtrlCreateLabel("Tags", 536, 24, 43, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Vessel = GUICtrlCreateRadio("Vessel Issue", 528, 56, 81, 25)
$Bad = GUICtrlCreateRadio("Bad  News", 528, 88, 89, 25)
$WhattheHell = GUICtrlCreateRadio("Dev Issue", 528, 120, 89, 25)
$Watch = GUICtrlCreateRadio("Watching", 528, 152, 89, 25)
GUISetState(@SW_SHOW)

$TheJournal = FileOpen(@ScriptDir & "\WorkNotes.txt", 1)

Local $hdr, $msg ;  <---- added to get text of radio button and format output header

While 1

    ; set $msg to control actioned so that it can be used in a GuiCtrlRead later
    $msg = GUIGetMsg()

    Switch $msg

        ; sets text of radio button clicked
        Case $Vessel, $Bad, $WhattheHell, $Watch
            $hdr = GUICtrlRead($msg, 1) ; The ", 1" gets the text of the control (advanced mode)

        Case $Save
            ;$TextInfo = GUICtrlRead($Edit1)        ; no need for an intermediate var
            ;$Today = _NowDate()                    ; no need for an intermediate var
            FileWrite($TheJournal, "--------------------------------- " & $hdr & " -------------------------------" & @CRLF)
            FileWrite($TheJournal, _NowDate() & @CRLF & @CRLF)
            FileWrite($TheJournal, GUICtrlRead($Edit1) & @CRLF)
            ExitLoop ;  exit loop will also exit the script if nothing follows the loop / for testing I want to see the file

    EndSwitch

WEnd

ShellExecute(@ScriptDir & "\WorkNotes.txt") ; display the file using the default windows handler for ".txt"

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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