Jump to content
Sign in to follow this  
RogerDat

Running While in While?

Recommended Posts

RogerDat

Hello and thank you for good forum!

I've have been scripted AutoIt about one week and working on my first project. Im doing some automated installation script. Before I have used only .bat files which are working great but looks horrible and installs allways same set.

So, now I have GUI look like this:

() XP () VISTA (radiobuttons)

And when I choose XP, I want some checkboxes, eg. [] 7zip [] Adobe Reader [] doPDF or If I check Vista, it could be like [] 7zip [] doPDF.

I got this radiobutton-thing work and with my own two functions I can get the right content for lower tab. (Yeah, its Tab because it was only thing what I can make clear all stuff before putting a new content).

Now the problem is that, If I put a new While...WEnd code with checkboxes and "Go" button, those radiobuttons wont work anymore. Any ideas? Or maybe any ideas to do this smarter?

Thank you!!

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>

;Opt('MustDeclareVars', 1)
Local $hTab

Interface()

Func Interface()
    
    GUICreate("Installer", 400, 600)
    $hTab = GUICtrlCreateTab(10, 50, 380, 540)
    $xp = GUICtrlCreateRadio("Windows XP", 10, 10)
    $vista = GUICtrlCreateRadio("Windows Vista", 100, 10)

    GUISetState()

    While 1
        $vastaus = GUIGetMsg()
        Select
            Case $vastaus = $GUI_EVENT_CLOSE
                ExitLoop
            Case $vastaus = $xp And BitAND(GUICtrlRead($xp), $GUI_CHECKED) = $GUI_CHECKED
                XP()
                
            Case $vastaus = $vista And BitAND(GUICtrlRead($vista), $GUI_CHECKED) = $GUI_CHECKED
                Vista()
        EndSelect
    WEnd 


EndFunc   ;==>Interface


Func XP()
    _GUICtrlTab_DeleteItem($hTab, 0)
    _GUICtrlTab_InsertItem($hTab, 0, "Windows XP")

    GUICtrlCreateLabel("Choose for XP", 30, 90)
    $seiskazip = GUICtrlCreateCheckbox("7zip", 30, 120)
        GUICtrlSetState($seiskazip, $GUI_CHECKED)
    $adobereader = GUICtrlCreateCheckbox("Adobe Reader", 30, 140)
        GUICtrlSetState($adobereader, $GUI_CHECKED)
    $dopdf = GUICtrlCreateCheckbox("doPDF", 30, 160)
        GUICtrlSetState($dopdf, $GUI_CHECKED)
    
    $asenna = GUICtrlCreateButton("GO", 30, 300)

    While 1
        $vastaus2 = GUIGetMsg()
                
            If $vastaus2 = $GUI_EVENT_CLOSE Then ExitLoop
                
            If $vastaus2 = $asenna Then
                If BitAND(GUICtrlRead($seiskazip), $gui_checked) Then
                    seiskazip()
                EndIf
                If BitAND(GUICtrlRead($adobereader), $gui_checked) Then
                    adobereader()
                EndIf
                If BitAND(GUICtrlRead($dopdf), $gui_checked) Then
                    dopdf()
                EndIf
            EndIf
    WEnd

EndFunc

Func Vista()
    _GUICtrlTab_DeleteItem($hTab, 0)
    _GUICtrlTab_InsertItem($hTab, 0, "Windows Vista")

        GUICtrlCreateLabel("Choose for Vista", 30, 90)
    $seiskazip = GUICtrlCreateCheckbox("7zip", 30, 120)
        GUICtrlSetState($seiskazip, $GUI_CHECKED)

    $dopdf = GUICtrlCreateCheckbox("doPDF", 30, 160)
        GUICtrlSetState($dopdf, $GUI_CHECKED)
    
    $asenna = GUICtrlCreateButton("GO", 30, 300)

    
    While 1
        $vastaus2 = GUIGetMsg()
            If $vastaus2 = $GUI_EVENT_CLOSE Then ExitLoop
                
            If $vastaus2 = $asenna Then
                If BitAND(GUICtrlRead($seiskazip), $gui_checked) Then
                    seiskazip()
                EndIf
                If BitAND(GUICtrlRead($dopdf), $gui_checked) Then
                    dopdf()
                EndIf
            EndIf
    WEnd        
EndFunc

Func seiskazip()
        RunWait(@COMSPEC & " /c 7zip.bat", @WorkingDir)
EndFunc
    
Func adobereader()
EndFunc
    
Func dopdf()
EndFunc

Share this post


Link to post
Share on other sites
GEOSoft

This whole thing can be done very simply without tabs but I have some questions. Do you want the Radio Controls to to always show or do you want them hiddedn when in either XP Mode or Vista Mode?

Is there a need for those Radios at all or can it be set automaticly by using @OSVersion?

There is no need for all the control manipulation you are using now when a few lines can handle it all. Also you only need to create the Go button once, what it does can be chosen by the Mode it's running in.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
RogerDat

Oh, I didnt try to search thing like that (OSversion) and I think it would be great idea!

Can you give a example how to use controls easier? I've read AutoIt Help and Forum so much and somehow I thought everyone does those like that.

I'll make that OSversion-script and I'll let you know.

Share this post


Link to post
Share on other sites
GEOSoft

Oh, I didnt try to search thing like that (OSversion) and I think it would be great idea!

Can you give a example how to use controls easier? I've read AutoIt Help and Forum so much and somehow I thought everyone does those like that.

I'll make that OSversion-script and I'll let you know.

Well you didn't explicitly answer my questions so I can throw something together in a while that

  • Does not use the Radio controls
  • sets the checkboxes according to @OSVersion
  • Uses only one Window with no Tab controls

As long as that is what you want.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

Here are 2 versions. The first uses 2 Windows (to make it prettier) and the second is a single window

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#Include<WindowsConstants.au3>

Global $Frm_XP, $Frm_Vista, $Gw = 400, $Gh = 600
Opt("GUICoordMode", 2)

$sMode = StringRegExpReplace(@OSVersion, "^.+_(\w+)$", "$1")
Interface()

Func Interface()

    $Frm_Main = GUICreate("Installer", $Gw, $Gh)
    $Lbl_Os = GUICtrlCreateLabel("Select the items to be installed", 10, 10, 380, 20, 0x01)
    GUICtrlSetFont($Lbl_Os, 9, 600)
    GUISetCoord($Gw/2 -30, $Gh -35)
    $asenna = GUICtrlCreateButton("Proceed", -1, -1, 60, 25)
    GUISetState()
    $Frm_Ctrls = GUICreate("Controls",$Gw -20, $Gh -90, 10, 40, $WS_CHILD, -1, $Frm_Main)
    GUISetBkColor(0xdeedfb) ;; Just for demo purposes
    $seiskazip = GUICtrlCreateCheckbox("7zip", 30, 30, 100)
    $dopdf = GUICtrlCreateCheckbox("doPDF", -1, 10)
        ;;;  ADD More checkboxes for items that are common to both OS's here
    $nextstd = GUICtrlCreateCheckbox("Next Std Item", -1, 10)
    $Opts_Start = GUICtrlCreateDummy()
    $adobereader = GUICtrlCreateCheckbox("Adobe Reader", -1, 10)
        ;;;  ADD More checkboxes for items that are specific to non-Vista here
    $nextopt = GUICtrlCreateCheckbox("Next Opt Item", -1, 10)
    $Opts_End = GUICtrlCreateDummy()
    For $i = $seiskazip To $Opts_End
        GUICtrlSetState($i, $GUI_CHECKED)
    Next

    GUISetState()

    If $sMode = "Vista" Then
        For $i = $Opts_Start To $Opts_End
            GUICtrlSetState($i, BitOR($GUI_UNCHECKED, $GUI_HIDE))
        Next
    EndIf

    While 1
        $vastaus = GUIGetMsg()
        Switch $vastaus
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $asenna
                If BitAND(GUICtrlRead($seiskazip), $gui_checked) Then seiskazip()
                If BitAND(GUICtrlRead($adobereader), $gui_checked) Then adobereader()
                If BitAND(GUICtrlRead($dopdf), $gui_checked) Then dopdf()
        EndSwitch
    WEnd


EndFunc   ;==>Interface

Func seiskazip()
        RunWait(@COMSPEC & " /c 7zip.bat", @WorkingDir)
        ;; I would actually change this to ShellExecuteWait("7Zip.bat") but that choice is yours to make
EndFunc

Func adobereader()
    MsgBox(0, "TEST", "Function adobereader")
EndFunc

Func dopdf()
    MsgBox(0, "TEST", "Function dopdf")
EndFunc

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#Include<WindowsConstants.au3>

Global $Frm_XP, $Frm_Vista, $Gw = 400, $Gh = 600
Opt("GUICoordMode", 2)

$sMode = StringRegExpReplace(@OSVersion, "^.+_(\w+)$", "$1")
Interface()

Func Interface()

    $Frm_Main = GUICreate("Installer", $Gw, $Gh)
    $Lbl_Os = GUICtrlCreateLabel("Select the items to be installed", 10, 10, 380, 20, 0x01)
    GUICtrlSetFont($Lbl_Os, 9, 600)
    GUISetCoord($Gw/2 -30, $Gh -35)
    $asenna = GUICtrlCreateButton("Proceed", -1, -1, 60, 25)
    GUISetBkColor(0xdeedfb) ;; Just for demo purposes
    GUISetCoord(10, 40)
    $seiskazip = GUICtrlCreateCheckbox("7zip", -1, -1, 100)
    $dopdf = GUICtrlCreateCheckbox("doPDF", -1, 10)
    ;;;  ADD More checkboxes for items that are common to both OS's here
    $nextstd = GUICtrlCreateCheckbox("Next Std Item", -1, 10)
    $Opts_Start = GUICtrlCreateDummy()
    $adobereader = GUICtrlCreateCheckbox("Adobe Reader", -1, 10)
    ;;;  ADD More checkboxes for items that are specific to non-Vista here
    $nextopt = GUICtrlCreateCheckbox("Next Opt Item", -1, 10)
    $Opts_End = GUICtrlCreateDummy()
    For $i = $seiskazip To $Opts_End
        GUICtrlSetState($i, $GUI_CHECKED)
    Next

    GUISetState()

    If $sMode = "Vista" Then
        For $i = $Opts_Start To $Opts_End
            GUICtrlSetState($i, BitOR($GUI_UNCHECKED, $GUI_HIDE))
        Next
    EndIf

    While 1
        $vastaus = GUIGetMsg()
        Switch $vastaus
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $asenna
                If BitAND(GUICtrlRead($seiskazip), $gui_checked) Then seiskazip()
                If BitAND(GUICtrlRead($adobereader), $gui_checked) Then adobereader()
                If BitAND(GUICtrlRead($dopdf), $gui_checked) Then dopdf()
        EndSwitch
    WEnd


EndFunc   ;==>Interface

Func seiskazip()
        ;RunWait(@COMSPEC & " /c 7zip.bat", @WorkingDir)
        MsgBox(0, "TEST", "Function seiskazip")
EndFunc

Func adobereader()
    MsgBox(0, "TEST", "Function adobereader")
EndFunc

Func dopdf()
    MsgBox(0, "TEST", "Function dopdf")
EndFunc
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  

×