Jump to content

In a pickle with my loops


Recommended Posts

I'm in a right pickle with my loops here - on the Button3 everything works fine and I'm getting the data I want into outlook however I don't want the whole script to exit / quit if you click cancel [ Button2a ] or quit / exit after the E-mail body has been filled - I just want it to continue as part of the original loop. Also if you click on the 'X' in the $Edit2 box the whole script ends and quits which I don't want it to do. - Any pointers ?

While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $Button1
                _ScreenCapture_Capture($helpdesk_screenshots & "\helpdesk_Image1.jpg")
                Sleep(2000)
                _IECreate($portalsite)

            Case $nMsg = $Button2
                _IECreate($portalsite)
            Case $nMsg = $Button3

                $Form2 = GUICreate("Help Desk E-mail Input", 633, 447, 192, 124)
                $Edit2 = GUICtrlCreateEdit("", 32, 24, 569, 353, $ES_MULTILINE)
                GUICtrlSetData(-1, "Default text")
                $Button1a = GUICtrlCreateButton("OK", 32, 400, 113, 25, $WS_GROUP)
                $Button2a = GUICtrlCreateButton("Cancel", 480, 400, 121, 25, $WS_GROUP)
                GUISetState(@SW_SHOW)
                While 1
                    $nMsg = GUIGetMsg()
                    Switch $nMsg
                        Case $GUI_EVENT_CLOSE
                            Exit
                        Case $Button1a
                            $ClipBoardFile = @MyDocumentsDir & '\file.dat'
                            $s_MailBody = (GUICtrlRead($Edit2)) & @CRLF & @CRLF & FileRead($ClipBoardFile)
                            _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)

                        Case $Button2a
                            Exit
                    EndSwitch
                WEnd

                _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
            Case $nMsg = $infoitem
                MsgBox(0, "Portal v1.3B", "Written By Matt ." & @CRLF & "Comments & Suggestions to:" & @CRLF & "matt@place.com")
            Case $nMsg = $GUI_EVENT_CLOSE
                GUIDelete($Form1)
                Return
        EndSelect
    WEnd
Edited by MattX
Link to comment
Share on other sites

How about getting rid of the Exit codes and using ExitLoop instead?

Does not make any difference I'm afraid - I stuck one in after Outlook opens up and but now it just fails to open up at all. Or outlook does it stuff but the edit box remains.

Edited by MattX
Link to comment
Share on other sites

Right I have my function which I know works:

Func Outlook()

$s_MailTo = 'it.helpdesk@place.com'
$s_MailSubject = 'DAT File from ' & @UserName

    $Form2 = GUICreate("place Help Desk E-mail Input", 633, 447, 192, 124)
    $Edit2 = GUICtrlCreateEdit("", 32, 24, 569, 353, $ES_MULTILINE)
    GUICtrlSetData(-1, "Default text")
    $Button1a = GUICtrlCreateButton("OK", 32, 400, 113, 25, $WS_GROUP)
    $Button2a = GUICtrlCreateButton("Cancel", 480, 400, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button1a
                $ClipBoardFile = @MyDocumentsDir & '\place.dat'
                $s_MailBody = (GUICtrlRead($Edit2)) & @CRLF & @CRLF & FileRead($ClipBoardFile)

                _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
                ExitLoop

            Case $Button2a
                ExitLoop
        EndSwitch
    WEnd
    EndFunc

And I want this to fit in or call it from this loop / function where it states: Case $nMsg = $Button3

Can someone inform me how to do this ? Would appreciate it.

Func ShowMessage()

    $Form1 = GUICreate("Portal Launcher", 330, 110, 348, 309)
    $helpmenu = GUICtrlCreateMenu("Help")
    $infoitem = GUICtrlCreateMenuItem("About", $helpmenu)
    GUISetBkColor(0x0066FF)
    $Button1 = GUICtrlCreateButton("Screen Shot", 10, 20, 89, 49)
    $Button2 = GUICtrlCreateButton("To Portal", 120, 20, 89, 49)
    $Button3 = GUICtrlCreateButton("E-Mail DAT", 230, 20, 89, 49)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $Button1
                _ScreenCapture_Capture($helpdesk_screenshots & "\helpdesk_Image1.jpg")
                Sleep(2000)
                _IECreate($portalsite)

            Case $nMsg = $Button2
                _IECreate($portalsite)

Case $nMsg = $Button3


            Case $nMsg = $infoitem
                MsgBox(0, "Place Portal v1.3B", "Written By Matt." & @CRLF & "Comments & Suggestions to:" & @CRLF & "matt.@place.com")
            Case $nMsg = $GUI_EVENT_CLOSE
                GUIDelete($Form1)
                Return
        EndSelect
    WEnd

EndFunc   ;==>ShowMessage
Edited by MattX
Link to comment
Share on other sites

I don't have any time to do testing right now, but it should go:

Case $Button 3
     call("ShowMessage")

Thanks - will give it a go later - I'm a bit drunk at the moment - Friday night and all that..... I think it may be call ("outlook") Edited by MattX
Link to comment
Share on other sites

I've put the function into the original script [ and calling it works a treat ] but it still does not finish properly - if I change the 'exitloop' to just exit - it still quits the original script whcih I don't want it to - this is driving me nuts - how can I come out of this function once it's run, how can I quit the function if the user clicks on cancel and the 'X' is pressed without it killing the entire script it's been called from ?

Also what I don't understand is that if I run the function as a completely different script, all the exit loops etc work fine !!??

Func Outlook()

$s_MailTo = 'it.helpdesk@place.com'
$s_MailSubject = 'DAT File from ' & @UserName

    $Form2 = GUICreate("Marken Help Desk E-mail Input", 633, 447, 192, 124)
    $Edit2 = GUICtrlCreateEdit("", 32, 24, 569, 353, $ES_MULTILINE)
    GUICtrlSetData(-1, "Default text")
    $Button1a = GUICtrlCreateButton("OK", 32, 400, 113, 25, $WS_GROUP)
    $Button2a = GUICtrlCreateButton("Cancel", 480, 400, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button1a
                $ClipBoardFile = @MyDocumentsDir & '\file.dat'
                $s_MailBody = (GUICtrlRead($Edit2)) & @CRLF & @CRLF & FileRead($ClipBoardFile)

                _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
                ExitLoop

            Case $Button2a
                Exitloop
        EndSwitch
    WEnd
    EndFunc
Edited by MattX
Link to comment
Share on other sites

OK, I finally played with it a little and this worked:

Func Outlook()

$s_MailTo = 'it.helpdesk@place.com'
$s_MailSubject = 'DAT File from ' & @UserName

    $Form2 = GUICreate("Marken Help Desk E-mail Input", 633, 447, 192, 124)
    $Edit2 = GUICtrlCreateEdit("", 32, 24, 569, 353)
    GUICtrlSetData(-1, "Default text")
    $Button1a = GUICtrlCreateButton("OK", 32, 400, 113, 25, $WS_GROUP)
    $Button2a = GUICtrlCreateButton("Cancel", 480, 400, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg2 = GUIGetMsg()
        Switch $nMsg2
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
            Case $Button1a
                $ClipBoardFile = @MyDocumentsDir & '\file.dat'
                $s_MailBody = (GUICtrlRead($Edit2)) & @CRLF & @CRLF & FileRead($ClipBoardFile)

                _INetMail($s_MailTo, $s_MailSubject, $s_MailBody)
                ExitLoop

            Case $Button2a
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
    EndFunc

#include <ByteMe.au3>

Link to comment
Share on other sites

Note: I didn't know what to #include for $ES_MULTILINE, so I left that out. I changed the nMsg to nMsg2 so that it will distinguish it from the first form. And finally, the GuiDelete was necessary to get rid of the windows.

#include <ByteMe.au3>

Link to comment
Share on other sites

Brilliant - works a treat - I added the GUIDelete($Form2) after the main input box too so that closes after the text has been added and outlook opens up - many thanks - I can now finish this off and hopefully roll it out properly.

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