Jump to content

Switch


Hobbyist
 Share

Recommended Posts

Admittedly this "Switch" effort has me baffled, as you can tell by my script.

I read the help file for Switch and for Ini files and attempted to make an example.

I'm trying to build the functionality of choosing to have output viewed on screen (as in an array) or choose another output, in this case xls.  You can this much from the "Report" menu. I can make all the other code work (ie array display or read into a file and use shell to open in csv format yada yada yada)

I am considering this "Report" menu to be my setting, that once I choose one, it becomes my default unless I make the other choice at execution time.

So I think my problem is best defined as having issues with the switch and ini   efforts.

Any guidance would be appreciated. Thanks in advance.

Hobbyist

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiTab.au3>
 #include <GuiButton.au3>
 #include <GuiMenu.au3>
 #include <WinAPI.au3>
 #include <Constants.au3>

;just threw in a bunch of stuff above as standard inclusion
; screen shot choice would be #1
;XLS choice would be #2
;either choice should be saved when selected and available at next startup

#Region ### START Koda GUI section ### Form=C:\Users\Steven\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Test Screen", 680, 515, 150, 100)

Local $idViewReport = GUICtrlCreateMenu("&Reports")
local $viewXLS = GUICtrlCreateMenuItem("View XLS Report",  $idViewReport)
local $viewScreen = GUICtrlCreateMenuItem("View Screen Shot",  $idViewReport)

GUISetState(@SW_SHOW)
global $viewswitch
Global $sIni = @LocalAppDataDir & "\Test Settings.ini"
$cEnterPressed = GUICtrlCreateDummy()

_XYZ($viewswitch) ;read ini


While 1


        $iMsg = GUIGetMsg()
         Switch $iMsg
             Case $GUI_EVENT_CLOSE
                 Exit


        Case $GUI_EVENT_PRIMARYUP


        Case  $cEnterPressed  ; Dummy

            Case $viewScreen
            GUICtrlSetState($viewScreen, $GUI_CHECKED)
            Guictrlsetstate($viewxls,$GUI_unCHECKED)
            $viewswitch = 1
            _ABC($viewswitch) ;write ini

        Case $viewXLS
            GUICtrlSetState($viewScreen, $GUI_unCHECKED)
            Guictrlsetstate($viewxls,$GUI_CHECKED)
            $viewswitch = 2
            _ABC($viewswitch) ;write ini



        EndSwitch


        Switch $viewswitch
            case 1
                GUICtrlSetState($viewScreen, $GUI_CHECKED)
                Guictrlsetstate($viewxls,$GUI_unCHECKED)


            case 2

                GUICtrlSetState($viewScreen, $GUI_unCHECKED)
                Guictrlsetstate($viewxls,$GUI_CHECKED)

EndSwitch

WEnd

Func _ABC($viewswitch)
    Iniwrite($sIni, "View", "$viewswitch", $viewswitch)
EndFunc

Func _XYZ($viewswitch)
    Return IniRead($sIni, "View", "View", 1)
    EndFunc
Link to comment
Share on other sites

  • Moderators

What exactly do you want from us Hobbyist?

Edit:

And where should we concentrate our looking (I mean, what exactly is not working as you'd expect)?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Its simply just helping me figure out how to get the switch and Ini code to work so from the menu bar so I can click on one of the two choices and it remains my choice presently and at future start ups and until I click on the alternate one if desired.  After reading the help file it seemed like getting those two to work would produce that capability.  What each choice does after that is not in question, I can script that.

I apologize for it not being clear and hope the above is.  If not I will try again (its not my best talent).

Hobbyist

Link to comment
Share on other sites

  • Moderators

You didn't do a good job editing your functions so we didn't know what they were.  You put things in incorrectly that took time to fix and make work, along with all the unnecessary include files that just make the code stupidly long.  I despise that.

Having said that, and fixing those errors you created trimming the code up, try this.

#include <GUIConstantsEx.au3>

;just threw in a bunch of stuff above as standard inclusion
; screen shot choice would be #1
;XLS choice would be #2
;either choice should be saved when selected and available at next startup

Global $viewswitch
Global $sIni = @LocalAppDataDir & "\Test Settings.ini"

#Region ### START Koda GUI section ### Form=C:\Users\Steven\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Test Screen", 680, 515, 150, 100)

Local $idViewReport = GUICtrlCreateMenu("&Reports")
Local $viewXLS = GUICtrlCreateMenuItem("View XLS Report", $idViewReport)
Local $viewScreen = GUICtrlCreateMenuItem("View Screen Shot", $idViewReport)

_XYZ($viewswitch)
Switch $viewswitch
    Case 1
        GUICtrlSetState($viewScreen, $GUI_CHECKED)
    Case 2
        GUICtrlSetState($viewXLS, $GUI_CHECKED)
EndSwitch
$viewswitch = -1

GUISetState(@SW_SHOW)

While 1


    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $viewScreen
            $viewswitch = 1
            _ABC($viewswitch) ;write ini
        Case $viewXLS
            $viewswitch = 2
            _ABC($viewswitch) ;write ini
    EndSwitch

    Switch $viewswitch
        Case 1
            GUICtrlSetState($viewScreen, $GUI_CHECKED)
            GUICtrlSetState($viewXLS, $GUI_unCHECKED)
        Case 2
            GUICtrlSetState($viewScreen, $GUI_unCHECKED)
            GUICtrlSetState($viewXLS, $GUI_CHECKED)
    EndSwitch

    $viewswitch = -1
WEnd

Func _ABC($viewswitch)
    IniWrite($sIni, "View", "View", $viewswitch)
EndFunc   ;==>_ABC

Func _XYZ(ByRef $viewswitch)
    $viewswitch = Int(IniRead($sIni, "View", "View", 1))
EndFunc   ;==>_XYZ

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thank you for the help. Sorry for all the inclusions - I use a template so I don't have to stop to add them, but can see how they would be a nuisance to others. Any future requests I make, will be cleaned up.

Now to the script - I can now see where you placed the Switch before the "While" - so it knows the state as it loads.  i wasn't even close on that. And the setting of the switch to -1. I get that now, hadn't thought of it.  But I guess you can put a Switch in place of any set of "IF/Then" statements???? A matter of what is more clear and shorter in lines?

My initial writing of the functions were just as yours, but when things weren't working I started changing things around and apparently lost control of it. That's when I hit the forum.

Thanks again. 

Hobbyist

Link to comment
Share on other sites

  • Moderators

I used the -1 because you never changed the value and it constantly held the last value, which constantly set the check/uncheck methods.

Surprised you didn't see the Menu fluttering.

So the -1 allows the switch to be left alone (not really, it's still searched), but it acts as our "IF/Then" as you stated.

I made the parameter in _xyz() func ByRef, this way all you have to do is pass the variable you're working with and it's automatically (global in this state you have it) set.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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