Sign in to follow this  
Followers 0
Diana (Cda)

3 buttons - Func doesn't work in this way; what else could be used?

4 posts in this topic

Good Morning!

I have 2 scripts that I need to integrate together somehow.  The first part are 3 buttons and they worked when I had message boxes there (taken from an example on this forum, not written by me).

Then I'm trying to integrate components of 3 separate scripts that work when invoked individually in individual au3 files.  I've included them at the bottom even though Func don't seem to work outside Func, nor do they work within and I don't know how to fix:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

MainGUI()

Func MainGUI()
  Local $Button1, $Button2, $Button3, $msg
  GUICreate("Week Dates to the Clipboard:")

  Opt("GUICoordMode", 2)
  $Button1 = GUICtrlCreateButton("LAST Week", 10, 30, 129)     ; left, top, width, height
  $Button2 = GUICtrlCreateButton("TWO Weeks Ago", 0, -1)     ; left, top, width, height
  $Button3 = GUICtrlCreateButton("THREE Weeks Ago", 0, -1)     ; left, top, width, height
  

  GUISetState()

    ; Run the GUI until the window is closed
  While 1
    $msg = GUIGetMsg()
    Select
     Case $msg = $GUI_EVENT_CLOSE
       ExitLoop
;----------------------------------------------------------
     Case $msg = $Button1
        ;===============================================================
        ClipPut("twclog.txt - " & _Date_String_from_THIS_Week() & "- ")
        ;===============================================================
       MsgBox(0, "THIS Week:", "THIS week's dates were sent to the clipboard.")
;----------------------------------------------------------
    Case $msg = $Button2
        ;===============================================================
        ClipPut("twclog.txt - " & _Date_String_from_LAST_Week() & "- ")
        ;===============================================================
       MsgBox(0, "LAST Week:", "LAST week's dates were sent to the clipboard.")
;----------------------------------------------------------
     Case $msg = $Button3
        ;===============================================================
        ClipPut("twclog.txt - " & _Date_String_from_TWO_Weeks_Ago() & "- ")
        ;===============================================================
       MsgBox(0, "LAST Week:", "Dates from TWO WEEKS ago were sent to the clipboard.")
;----------------------------------------------------------
    EndSelect
  WEnd
EndFunc



Func _Date_String_from_THIS_Week()
    Local $iWeekStart = 0, $iWeekEnd = 6, $sDateStart, $sDateEnd
    Switch @WDAY
        Case 3 To 7 ;tue-sat
            $iWeekStart = 2-@WDAY
            $iWeekEnd = 8-@WDAY
        Case 1 ;sun
            $iWeekStart = -6
            $iWeekEnd = 0
    EndSwitch
    $sDateStart = StringReplace(_DateAdd('d', $iWeekStart, _NowCalcDate()), "/", ".")
    $sDateEnd = StringReplace(_DateAdd('d', $iWeekEnd, _NowCalcDate()), "/", ".")
    Return $sDateStart & '.Mn-' & $sDateEnd & '.Sn'
EndFunc



Func _Date_String_from_LAST_Week()
    Local $iWeekStart = 0, $iWeekEnd = 6, $sDateStart, $sDateEnd
    Switch @WDAY
        Case 3 To 7 ;tue-sat
            $iWeekStart = 2-@WDAY
            $iWeekEnd = 8-@WDAY
        Case 1 ;sun
            $iWeekStart = -6
            $iWeekEnd = 0
    EndSwitch
    $sDateStart = StringReplace(_DateAdd('d', $iWeekStart-7, _NowCalcDate()), "/", ".")
    $sDateEnd = StringReplace(_DateAdd('d', $iWeekEnd-7, _NowCalcDate()), "/", ".")
    Return $sDateStart & '.Mn-' & $sDateEnd & '.Sn'
EndFunc



Func _Date_String_from_TWO_Weeks_Ago()
    Local $iWeekStart = 0, $iWeekEnd = 6, $sDateStart, $sDateEnd
    Switch @WDAY
        Case 3 To 7 ;tue-sat
            $iWeekStart = 2-@WDAY
            $iWeekEnd = 8-@WDAY
        Case 1 ;sun
            $iWeekStart = -6
            $iWeekEnd = 0
    EndSwitch
    $sDateStart = StringReplace(_DateAdd('d', $iWeekStart-14, _NowCalcDate()), "/", ".")
    $sDateEnd = StringReplace(_DateAdd('d', $iWeekEnd-14, _NowCalcDate()), "/", ".")
    Return $sDateStart & '.Mn-' & $sDateEnd & '.Sn'
EndFunc

Any help appreciated.

Thanks!

Share this post


Link to post
Share on other sites



Diana (Cda),

You buttons work fine for me - although why have 3 functions when you can just use one and pass the number of days back you need to go as a parameter like this: ;)

#include <GUIConstantsEx.au3>
#include <Date.au3>

Opt('MustDeclareVars', 1)

MainGUI()

Func MainGUI()
    Local $Button1, $Button2, $Button3, $msg, $sRet
    GUICreate("Week Dates to the Clipboard:")

    Opt("GUICoordMode", 2)
    $Button1 = GUICtrlCreateButton("LAST Week", 10, 30, 129) ; left, top, width, height
    $Button2 = GUICtrlCreateButton("TWO Weeks Ago", 0, -1) ; left, top, width, height
    $Button3 = GUICtrlCreateButton("THREE Weeks Ago", 0, -1) ; left, top, width, height

    GUISetState()

    ; Run the GUI until the window is closed
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button1
                $sRet = _Date_String(0)
                ClipPut("twclog.txt - " & $sRet & "- ")
                MsgBox(0, "THIS Week:", "THIS week's dates were sent to the clipboard:" & @CRLF & $sRet)
            Case $Button2
                $sRet = _Date_String(7)
                ClipPut("twclog.txt - " & $sRet & "- ")
                MsgBox(0, "THIS Week:", "LAST week's dates were sent to the clipboard:" & @CRLF & $sRet)
            Case $Button3
                $sRet = _Date_String(14)
                ClipPut("twclog.txt - " & $sRet & "- ")
                MsgBox(0, "THIS Week:", "Dates from TWO WEEKS ago were sent to the clipboard:" & @CRLF & $sRet)
        EndSwitch
    WEnd
EndFunc   ;==>MainGUI

Func _Date_String($iPrevious)
    Local $iWeekStart = 0, $iWeekEnd = 6, $sDateStart, $sDateEnd
    Switch @WDAY
        Case 3 To 7 ;tue-sat
            $iWeekStart = 2 - @WDAY
            $iWeekEnd = 8 - @WDAY
        Case 1 ;sun
            $iWeekStart = -6
            $iWeekEnd = 0
    EndSwitch
    $sDateStart = StringReplace(_DateAdd('d', $iWeekStart - $iPrevious, _NowCalcDate()), "/", ".")
    $sDateEnd = StringReplace(_DateAdd('d', $iWeekEnd - $iPrevious, _NowCalcDate()), "/", ".")
    Return $sDateStart & '.Mn-' & $sDateEnd & '.Sn'
EndFunc   ;==>_Date_String

I also had to add the Date.au3 include file.  Does it work for you now? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Diana (Cda),

You buttons work fine for me - although why have 3 functions when you can just use one and pass the number of days back you need to go as a parameter like this: ;)

 

<lol> That's because you're a genius at this stuff!!  I had 3 separate scripts and was trying to put them together.  I found a 3-button gui that was easy in construction and tried to marry that part with the 3 scripts I pulled from 3 separate autoit files but got stuck there so just dumped them in to show what they were <g>.

 

<snip> 

 

Yup, works like a charm!  You're really good at this stuff! <g>  This works perfectly!

 

------------

Just out of curiousity, what determines the GUI size in this script, pls?  I don't see where that's set out; a smaller height would be nice for this one if at all possible.  Also, perhaps a cancel button.  I use Koda and the code it generates is nothing as simplistic as this.  i.e., I really love how the 3 buttons here are just spaced relative to each other and they didn't needed to be coded in place  Pretty neat.

 

Anyway, thanks and any comments appreciated re this.  I know others like myself would benefit, too.

 

Cheers!  :)

Edited by Melba23
Quote and code removed

Share this post


Link to post
Share on other sites

Diana (Cda),

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unneccessarily. Especially when the quote contains a code box as it is then displayed in full without the scrollbars. ;)

 

what determines the GUI size in this script

As there are no parameters set in the GUICreate call, you get the default values. Just add width & height parameters to that line and you can set your own values. :)

 

I use Koda and the code it generates is nothing as simplistic as this

I could not agree more - I never use Koda as I find it adds all sort of unnecessary lines. I do not dispute its usefulness for beginners, but I prefer to hand code my GUIs. ;)

 

I really love how the 3 buttons here are just spaced relative to each other and they didn't needed to be coded in place Pretty neat

Go and look at Opt("GUICoordMode", 2) in the Help file - a very useful option to use when you have multiple similarly sized controls to locate. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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