Jump to content

GUI assistance


Recommended Posts

Hi can anyone help. I keep getting a Syntax error Else GUICtrlRead. If I remove the previous (ElseIf) block then it all works fine. I know I'm missing something stupidly obvious here but I cant get past it.

Thanks for looking.

CODE

while 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then Exit

If $msg = $nxt1 then

If GUICtrlRead($blpc) = $GUI_CHECKED Then

$check = MsgBox (4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")

if $check = 6 Then

$file1=FileOpen("c:\blockpc.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "done", "PC has been added to blocked list")

Exit

ElseIf GUICtrlRead($blun) = $GUI_CHECKED Then

$check = MsgBox (4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")

if $check = 6 Then

$file1=FileOpen("c:\blockus.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "done", "user has been added to blocked list")

Exit

Else GUICtrlRead($enable) = $GUI_CHECKED Then

$check = MsgBox(4, "allow Access", "This will allow " & GUICtrlRead($user) & " access to the internet" & @CRLF & "Click OK to continue")

If $check = 6 Then

$file1 = FileOpen("c:\allow.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox (0, "completed", GUICtrlRead($user) & "has been granted access to the internet")

Exit

EndIf

EndIf

EndIf

EndIf

WEnd

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

important: use Tidy (ctrl+t in a saved script in Scite) to indent your code. You can easily see the blocks, and often what's wrong with them.

My guess is that you have Else where you should have ElseIf:

Wrong:

Else GUICtrlRead($enable) = $GUI_CHECKED Then

Right (I guess):

ElseIf GUICtrlRead($enable) = $GUI_CHECKED Then

Else is followed by something to do, and ElseIf by something to check:

If $IWantGoodWeather then
     _LetTheSunShine()
else
     _LetItRain()
endifoÝ÷ Ù«­¢+Ù%ÀÌØí%]¹Ñ½½]Ñ¡ÈÑ¡¸(}1ÑQ¡MÕ¹M¡¥¹ ¤)±Í%ÀÌØí5å]¥]¹Ñͽ½]Ñ¡ÈÑ¡¸(}1ÑQ¡MÕ¹M¡¥¹}  ÕÑ=¹±å1¥Ñѱ    ¥Ð ¤)±Í(}1Ñ%ÑI¥¸ ¤)¹¥
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Hi can anyone help. I keep getting a Syntax error Else GUICtrlRead. If I remove the previous (ElseIf) block then it all works fine. I know I'm missing something stupidly obvious here but I cant get past it.

Thanks for looking.

CODE

while 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then Exit

If $msg = $nxt1 then

If GUICtrlRead($blpc) = $GUI_CHECKED Then

$check = MsgBox (4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")

if $check = 6 Then

$file1=FileOpen("c:\blockpc.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "done", "PC has been added to blocked list")

Exit

ElseIf GUICtrlRead($blun) = $GUI_CHECKED Then

$check = MsgBox (4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")

if $check = 6 Then

$file1=FileOpen("c:\blockus.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "done", "user has been added to blocked list")

Exit

Else GUICtrlRead($enable) = $GUI_CHECKED Then

$check = MsgBox(4, "allow Access", "This will allow " & GUICtrlRead($user) & " access to the internet" & @CRLF & "Click OK to continue")

If $check = 6 Then

$file1 = FileOpen("c:\allow.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox (0, "completed", GUICtrlRead($user) & "has been granted access to the internet")

Exit

EndIf

EndIf

EndIf

EndIf

WEnd

I recommend that you use SciTE for your editor and also then use Ctr T to tidy your code. Then you would find straight away that there is an EndIf missing before the final wend.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks for this but I am using SciTe and there are no missing EndIf's. When I pasted the code into a codebox it removed all the indentations.

the error I get is:

C:\Documents and Settings\woolleyr.RWS\Desktop\Scripts\console1.au3(60,11) : ERROR: syntax error

Else GUICtrlRead

~~~~~^

C:\Documents and Settings\woolleyr.RWS\Desktop\Scripts\console1.au3 - 1 error(s), 0 warning(s)

so I have no idea. If I remove the previous block of code then it works just fine. I'm a bit nonplussed. Would it help if I posted the entire script?

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

Well, did you try my suggestion? I believe your Else should be an ElseIf, since the rest of the line is written as something that belongs after an ElseIf instead of after an Else. (Since it's a new check which decides if some action is done, rather than a rest action after all previous If checks have failed, which is what goes behind an Else.)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Thanks for this but I am using SciTe and there are no missing EndIf's. When I pasted the code into a codebox it removed all the indentations.

the error I get is:

C:\Documents and Settings\woolleyr.RWS\Desktop\Scripts\console1.au3(60,11) : ERROR: syntax error

Else GUICtrlRead

~~~~~^

C:\Documents and Settings\woolleyr.RWS\Desktop\Scripts\console1.au3 - 1 error(s), 0 warning(s)

so I have no idea. If I remove the previous block of code then it works just fine. I'm a bit nonplussed. Would it help if I posted the entire script?

The code you posted in your first post has a missing EndIf. If you don't have a missing EndIf then you didn't post the code you are having trouble with.

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then Exit
    If $msg = $nxt1 Then
        If GUICtrlRead($blpc) = $GUI_CHECKED Then
            $check = MsgBox(4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")
            If $check = 6 Then
                $file1 = FileOpen("c:\blockpc.txt", 1)
                FileWriteLine($file1, GUICtrlRead($user))
                MsgBox(0, "done", "PC has been added to blocked list")
                Exit
            ElseIf GUICtrlRead($blun) = $GUI_CHECKED Then
                $check = MsgBox(4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")
                If $check = 6 Then
                    $file1 = FileOpen("c:\blockus.txt", 1)
                    FileWriteLine($file1, GUICtrlRead($user))
                    MsgBox(0, "done", "user has been added to blocked list")
                    Exit
                Else GUICtrlRead($enable) = $GUI_CHECKED Then
                    $check = MsgBox(4, "allow Access", "This will allow " & GUICtrlRead($user) & " access to the internet" & @CRLF & "Click OK to continue")
                    If $check = 6 Then
                        $file1 = FileOpen("c:\allow.txt", 1)
                        FileWriteLine($file1, GUICtrlRead($user))
                        MsgBox(0, "completed", GUICtrlRead($user) & "has been granted access to the internet")
                        Exit
                    EndIf

                EndIf

            EndIf
        EndIf
;### Tidy Error -> "wend" is closing previous "if"
    WEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi SadBunny

I originally wrote it using ElseIf. When written llike that the script runs, the first 2 radio buttons work but the last one stalls and does nothing.

If it helps here is the entire code. I dont know why the indentations are removed when I paste the code into a codebox :-(

CODE

#include <process.au3>

#include <GuiConstants.au3>

#include <EditConstants.au3>

;$file = "C:\test.txt"

GUICreate("GUI Messaging", 300, 355)

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

;Create labels

GUICtrlCreateLabel("Please select your choice then click OK", 50, 20)

GUICtrlCreateLabel("Block internet access by:", 20, 50)

GUICtrlCreateLabel("Re-enable internet access:", 20, 130)

GUICtrlCreateLabel("Enter computername or username below:", 50, 180)

;Create radio buttons

$blpc = GUICtrlCreateRadio(" by Computername ", 80, 70)

$blun = GUICtrlCreateRadio(" by Username ", 80, 95)

$enable = GUICtrlCreateRadio(" By Username or PC name ", 80, 150)

;Create input box

$user = GUICtrlCreateInput("", 80, 200, 100, 25, $ES_MULTILINE)

$nxt1 = GUICtrlCreateButton("OK", 40, 295, 70, 35)

$exit = GUICtrlCreateButton("Cancel", 180, 295, 70, 35)

;Exit

; GUI MESSAGE LOOP

GUISetState()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then Exit

If $msg = $nxt1 Then

If GUICtrlRead($blpc) = $GUI_CHECKED Then

$check = MsgBox(4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")

If $check = 6 Then

$file1 = FileOpen("c:\blockpc.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "done", "PC has been added to blocked list")

Exit

ElseIf GUICtrlRead($blun) = $GUI_CHECKED Then

$check = MsgBox(4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")

If $check = 6 Then

$file1 = FileOpen("c:\blockus.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "done", "user has been added to blocked list")

Exit

ElseIf GUICtrlRead($enable) = $GUI_CHECKED Then

$check = MsgBox(4, "allow Access", "This will allow " & GUICtrlRead($user) & " access to the internet" & @CRLF & "Click OK to continue")

If $check = 6 Then

$file1 = FileOpen("c:\allow.txt", 1)

FileWriteLine($file1, GUICtrlRead($user))

MsgBox(0, "completed", GUICtrlRead($user) & "has been granted access to the internet")

Exit

EndIf

EndIf

EndIf

EndIf

EndIf

WEnd

Exit

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

Found your problem. Martin and I were both right :)

Actually you seemingly added the Endif on the position that Scite indicated, which was the wrong position. You were forgetting it to finish your If $check = 6 Then block. This is probably how your while loop should work:

While 1
    $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then Exit
        If $msg = $nxt1 Then
        If GUICtrlRead($blpc) = $GUI_CHECKED Then
            $check = MsgBox(4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")
            If $check = 6 Then
                $file1 = FileOpen("c:\blockpc.txt", 1)
                FileWriteLine($file1, GUICtrlRead($user))
                MsgBox(0, "done", "PC has been added to blocked list")
                Exit
            EndIf
        ElseIf GUICtrlRead($blun) = $GUI_CHECKED Then
            $check = MsgBox(4, "#1", "This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue")
            If $check = 6 Then
                $file1 = FileOpen("c:\blockus.txt", 1)
                FileWriteLine($file1, GUICtrlRead($user))
                MsgBox(0, "done", "user has been added to blocked list")
                Exit
            EndIf
        ElseIf GUICtrlRead($enable) = $GUI_CHECKED Then
            $check = MsgBox(4, "allow Access", "This will allow " & GUICtrlRead($user) & " access to the internet" & @CRLF & "Click OK to continue")
            If $check = 6 Then
                $file1 = FileOpen("c:\allow.txt", 1)
                FileWriteLine($file1, GUICtrlRead($user))
                MsgBox(0, "completed", GUICtrlRead($user) & "has been granted access to the internet")
                Exit
            EndIf
        EndIf
    EndIf
WEnd
Exit
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Thanks ever so much guys...your help is very much appreciated and gratefully received.

I said it was something stupidly easy :-)

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

Welcome.

Might I take the liberty to suggest a fundamental change to your code? See, since I'm lazy, I try to avoid having to write (almost) the same code twice (or three times as in your case) and use functions... Making code shorter and better looking, and if you do something wrong have a way easier time troubleshooting. (And the fix doesn't need to be applied three times, leaving 3x as much change of messing up details like you did in the beginning of this thread :) )

Something like the following:

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exit Then Exit
    If $msg = $nxt1 Then
        If GUICtrlRead($blpc) = $GUI_CHECKED Then
            _check("This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue", "c:\blockpc.txt")
        ElseIf GUICtrlRead($blun) = $GUI_CHECKED Then
            _check("This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue", "c:\blockus.txt")
        ElseIf GUICtrlRead($enable) = $GUI_CHECKED Then
            _check("This will allow " & GUICtrlRead($user) & " access to the internet" & @CRLF & "Click OK to continue", "c:\allow.txt")
        EndIf
    EndIf
WEnd
Exit

Func _check($text, $file)
    $check = MsgBox(4, "#1", $text)
    If $check = 6 Then
        $file1 = FileOpen($file, 1)
        FileWriteLine($file1, GUICtrlRead($user))
        MsgBox(0, "done", "Operation performed!")
        Exit
    EndIf
EndFunc   ;==>_check
Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

you can always make suggestions and I'll always be glad to hear them, as you can tell I am not a coder and I only do it occasionally so any help is welcome.

I know there are better ways of doing things but until I find out how they work and how to use them I just bimble along the way I know best (and make hideous mistakes along the way).

I love AutoIt and I've been using it since version 2 (how come there isnt a Text Reveal mode in V3, I still use it as it sometimes makes WinWait commands work where just typing doesn't and the hidden text is invaluable when writing software installation scripts where very often consecutive windows have the same name). I found V2 easier in some ways with the gosub facility (old DOS habits die hard).

I have used your _function in my script... thanks!!

Keep em coming :)

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

So true on the old DOS habits... I am very happy that MS didn't ditch CMD.EXE in Windows Vista :)

I used a lot of GoSub too in the old GWBasic days (damn I'm getting old... already 28 this year :P ) but I never feel the need to revisit that - that's what separate functions are so good for :P

I started on AutoIt v3, so I'm not sure about your question about the text reveal mode... But I do know that in V3 you can just look for hidden text in windows using WinWait and such, only you need to first set Opt("WinDetectHiddenText",1) (the default is 0 meaning hidden text is not looked for by default). After that WinWait should just as easily trigger on hidden text in a window.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

I dont know whether its cos I've been up for about 22hrs or just cos I'm plain stupid... I'm trying to see how your _function writes to the appropriate .txt file. There are 3 seperate files but I cant see where you are specifying which one to write to :)

I have a few years on you (about 16) and I remember struggling with trying to find a way to call the date as a variable in .bat files... never did work that one out, but thats OK cos its a breeze with AutoIt.

I have found with things like WinWait that sometimes you can type the window name and the program stalls, even though the spelling and CAPS status appears to be OK. The reveal mode sits on top of everything, you focus the window you want details of and you get 1. Window name (CTRL+c) all hidden text (CTRL+c) and bingo! it all works.

Being a hoarder I still have the installer for V2 which installs Reveal Mode if you are interested.

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

I dont know whether its cos I've been up for about 22hrs or just cos I'm plain stupid... I'm trying to see how your _function writes to the appropriate .txt file. There are 3 seperate files but I cant see where you are specifying which one to write to :)

As follows:

(...)

_check("This will block " & GUICtrlRead($user) & " from acessing the internet" & @CRLF & "Click OK to continue", "c:\blockpc.txt")

(...)

Func _check($text, $file)

(...)

$file1 = FileOpen($file, 1)

(...)

See:

1 - the 2nd argument of the _check function call is in this case "c:\blockpc.txt".

2 - The 'Func _check($text, $file)' creates the _check function, and makes sure the function will expect TWO pieces of data, and they are stored correspondingly in two local variables calles $text and $file. (Local means the variables will ONLY exist in the function itself, meaning less worries about global variables with the same names in the rest of your script. Say I have another function which ALSO wants to use a variable called '$text' or '$file' but for something else, which isn't hard to imagine, no problem now! Btw, this is one of the reasons why gosubs are bad and functions are good... :P )

3 - The FileOpen function opens a file called $file (meaning the contents of the 2nd parameter, in this case "c:\blockpc.txt").

If the function call pushes other data to the function ("c:\allow.txt" for instance), the FileOpen command opens that.

/edit: By the way, damn, I see my script suggestion only wrote to two different files instead of three - small error on my part :P Updated my example. (Now the second _check call passes "blockus.txt" to the _check function instead of "blockpc.txt" again like the first call).

Being a hoarder I still have the installer for V2 which installs Reveal Mode if you are interested.

Not really - all I need (and also tons I don't need :D ) are in V3. Btw I believe V2 is still on the website.

The reveal mode sits on top of everything, you focus the window you want details of and you get 1. Window name (CTRL+c) all hidden text (CTRL+c) and bingo! it all works.

Do you mean the AU3Info tool perhaps? (Ctrl-F6 in scite from a saved script.) It gives you a sh*tload of information about all kinds of windows. Be sure to give it a try! Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

By the way, from the top off my head, shouldn't the following give you the date as a variable in a batch file?

CODE
@echo off

set var=%date%

echo The date is: %var%

Not tested, and certainly not on dos 3.22 which I actually don't have hanging around any more :) Guess I'm not a hoarder like you... :P (Although I am absolutely sure that it will be hanging around on the web and can be found with a simple Google search... :P)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

I have so much to learn.. but thats a good thing too. Where do you go to learn all this stuff?

I just tried the CTRL +F6.. that is way cool, I'm liking that a lot. I didnt even know it existed and I will sure as hell be using it in the future.

Bed calls... it's 01:30 here and I gotta sleep.

thanks for your help, like I said I have much to learn and your assistance is very much appreciated.

cheers, and I'll certainly be looking for more help in the future

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

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