Sign in to follow this  
Followers 0
Vu1kan

GUI Code makes my head hurt...

3 posts in this topic

If someone could help me that'd be great. What I'm trying to do is create an autolauncher to streamline my internet needs. I've already made a working version using AutoIt 2 and 3, now I'm trying to integrate the whole thing into a gui. The problem that I've run up against is this:

#include <GuiConstants.au3>

GuiCreate("Internet Automation", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Button_go = GuiCtrlCreateButton("Go!", 240, 280, 60, 30)

GUICtrlSetState(-1, $GUI_Focus)

$Button_nogo = GuiCtrlCreateButton("No Go", 320, 280, 60, 30)

;this is the box for my firewall

$Checkbox_firewall = GuiCtrlCreateCheckbox("Armor2Net", 30, 80, 80, 20)

GUICtrlSetState(-1, $GUI_Checked)

;this is the box for my popupblocker

$Checkbox_killad = GuiCtrlCreateCheckbox("KillAd", 30, 100, 80, 20)

GUICtrlSetState(-1, $GUI_Checked)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_nogo

ExitLoop

Case $msg = $Button_go

GUISetState(@SW_HIDE)

BlockInput(1)

SplashTextOn('Internet Automation---Working','The keyboard and the mouse will be disabled while the computer is automaticly prepared to surf.',300,65)

GUICtrlRead($Checkbox_firewall)

GUICtrlRead($Checkbox_killad)

;I removed the code for my browser and messenger from this line (and the next six)

If GUICtrlRead($Checkbox_firewall) = $GUI_CHECKED Then Run('c:\Program Files\Armor2net\Armor2net Personal Firewall\armor2net.exe') Sleep(5000)

If GUICtrlRead($Checkbox_firewall) = $GUI_UNCHECKED Then

Splashoff()

$f=msgbox(16, 'NO!', 'You cannot surf without a firewall, try again')

IF $f = 1 then exit

EndIf

;Here is where i run into problems:

If GUICtrlRead($Checkbox_killad) = $GUI_CHECKED Then Run('c:\Program Files\killad\killad.exe') AND Sleep(2000)

Splashoff()

ExitLoop

EndSelect

WEnd

Exit

Specifically, the app doesn't want to let me use the 'AND' command to link the 'run' & 'Sleep" and when I put the 'sleep' on the next line, it does the 'sleep' even if the 'if' command isn't activated. this wouldn't be a problem, except that i'm using the 'winwait' command futher down in the script. I'm not even sure if the 'if' command is the best one to use, but it's the only way i could figure out to get the whole thing working how i want it to. If you're interested in the complete script, it's attached.


Moooo...

Share this post


Link to post
Share on other sites



:) Just make it a multiline block, and do not use the And for this instance. This should work, if that problem is the only issue.

#include <GuiConstants.au3>
GUICreate("Internet Automation", 392, 323, (@DesktopWidth - 392) / 2, (@DesktopHeight - 323) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Button_go = GUICtrlCreateButton("Go!", 240, 280, 60, 30)
GUICtrlSetState(-1, $GUI_Focus)
$Button_nogo = GUICtrlCreateButton("No Go", 320, 280, 60, 30)
;this is the box for my firewall
$Checkbox_firewall = GUICtrlCreateCheckbox("Armor2Net", 30, 80, 80, 20)
GUICtrlSetState(-1, $GUI_Checked)
;this is the box for my popupblocker
$Checkbox_killad = GUICtrlCreateCheckbox("KillAd", 30, 100, 80, 20)
GUICtrlSetState(-1, $GUI_Checked)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_nogo
            ExitLoop
        Case $msg = $Button_go
            GUISetState(@SW_HIDE)
            BlockInput(1)
            SplashTextOn('Internet Automation---Working', 'The keyboard and the mouse will be disabled while the computer is automaticly prepared to surf.', 300, 65)
            GUICtrlRead($Checkbox_firewall)
            GUICtrlRead($Checkbox_killad)
        ;I removed the code for my browser and messenger from this line (and the next six)
            If GUICtrlRead($Checkbox_firewall) = $GUI_Checked Then Run('c:\Program Files\Armor2net\Armor2net Personal Firewall\armor2net.exe') Sleep(5000)
            If GUICtrlRead($Checkbox_firewall) = $GUI_UNCHECKED Then
                SplashOff()
                $f = MsgBox(16, 'NO!', 'You cannot surf without a firewall, try again')
                If $f = 1 Then Exit
            EndIf
        ;Here is where i run into problems:
            If GUICtrlRead($Checkbox_killad) = $GUI_Checked Then
                Run('c:\Program Files\killad\killad.exe')
                Sleep(2000)
            EndIf
            SplashOff()
            ExitLoop
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanx...but i solved the problem...right after i disconnected i converted all of the 'if' strings into 'select...case' strings and *poof* the issue dissappeared. I guess i was just getting frustrated and needed a kick in the pants or something. finished script is attached if anyone is interested.(and FYI: The multiline block idea just made autoit skip the first 'if' statement and execute the 'sleep' statment anyway)

Edited by Vu1kan

Moooo...

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