Sign in to follow this  
Followers 0
crest

If ... Then question

10 posts in this topic

Hey guys

for some reason "If .. Then" can only handle a single statement after the "Then" like explained in the helpfile

Conditionally run a single statement.

If <expression> Then statement

Is there any way to have two or more statements?

in c++ you can simply put as many statements as you want, you just need to bracket them like:

if (expression)
{ statement1; statement2; ...}

My own Code looks like this:

#include <GUIConstants.au3>
Global $amount
GUICreate ( "Conjure Water v1.2b", 300, 200)

$slider = GUICtrlCreateSlider (10, 30, 280, 20)
GuiCtrlSetLimit (-1, 20, 10)
$button = GUICtrlCreateButton ( "OK", -1 , 100 , 80, 20) 
GuiSetState()
GuiCtrlSetData ($slider, 0)

While 1
    $tempvar = GUiGetMsg()
    
    If  $tempvar = $button Then $amount = GuiCtrlRead ($slider)

    
    

Wend

I actually wanted the "IF ... Then" to save the Slider Position into $amount and then exit the While-Loop

Yet i cant think of a way to do this :lmao: (damn i suck)

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>
Global $amount
GUICreate ( "Conjure Water v1.2b", 300, 200)

$slider = GUICtrlCreateSlider (10, 30, 280, 20)
GuiCtrlSetLimit (-1, 20, 10)
$button = GUICtrlCreateButton ( "OK", -1 , 100 , 80, 20)
GuiSetState()
GuiCtrlSetData ($slider, 0)

While 1
    $tempvar = GUiGetMsg()
    
    If $tempvar = $button Then
        $amount = GuiCtrlRead ($slider)
        ExitLoop
    EndIf
Wend

Share this post


Link to post
Share on other sites

hmpf :ph34r:

ive tried that already and it didnt work, some error msg appeared xD

now that ive copy / pasted it, it works :lmao:

strange, since i dont see any difference

Anyways, thanks for the fast help :geek:

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

hmpf :ph34r:

ive tried that already and it didnt work, some error msg appeared xD

now that ive copy / pasted it, it works :lmao:

strange, since i dont see any difference

Anyways, thanks for the fast help :geek:

It was probably a Syntax error. Recreate the script the way you had it and see if it gives you the same error. A syntax error just means that something was not in the correct order or something was misplaced. Its kinda like rearranging a sentence like 'Crest walks the dog'. You can write it this way or 'The dog Crest walks" and both ways communicate the same thing to you, however when scripting, if it is not EXACTLY the way it SHOULD appear, you will just get an error.

As a general sytax rule when using If statements in AutoIt put the stuff after Then on the next line, not the same line. This small Change can be the difference in your script working or not.

So always make this:

If $tempvar = $button Then $amount = GuiCtrlRead ($slider)oÝ÷ غ(X¤zØb±«­¢+Ø)%ÀÌØíѵÁÙÈôÀÌØíÕÑѽ¸Q¡¸(ÀÌØíµ½Õ¹ÐôÕ¥
ÑɱI ÀÌØíͱ¥È¤
Edited by litlmike

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So always make this:

If $tempvar = $button Then $amount = GuiCtrlRead ($slider)
oÝ÷ غ(X¤zØb±«­¢+Ø)%ÀÌØíѵÁÙÈôÀÌØíÕÑѽ¸Q¡¸(ÀÌØíµ½Õ¹ÐôÕ¥
ÑɱI ÀÌØíͱ¥È¤(
Edited by dandymcgee

- Dan [Website]

Share this post


Link to post
Share on other sites

Hi,

you can check those things on your own. Like:

#include <GUIConstants.au3>
Global $amount
GUICreate ( "Conjure Water v1.2b", 300, 200)

$slider = GUICtrlCreateSlider (10, 30, 280, 20)
GuiCtrlSetLimit (-1, 20, 10)
$button = GUICtrlCreateButton ( "OK", -1 , 100 , 80, 20)
GuiSetState()
GuiCtrlSetData ($slider, 0)

While 1
    $tempvar = GUiGetMsg()
    ToolTip(GuiCtrlRead ($slider))
    If $tempvar = $button Then
        $amount = GuiCtrlRead ($slider)
        ConsoleWrite($amount & @LF)
        ExitLoop
    EndIf
Wend

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Did I understand you correctly there litlmike ? Are you saying that this code doesn't work :

If $tempvar = $button Then $amount = GuiCtrlRead ($slider)

If so, you're wrong, as it does work.

Share this post


Link to post
Share on other sites

Did I understand you correctly there litlmike ? Are you saying that this code doesn't work :
If $tempvar = $button Then $amount = GuiCtrlRead ($slider)oÝ÷ Øì£*.ßÚÞº'«"µÚ³
+ú®¢×°zYa{§µçm¢Æ²¶­Ê¬¥v{p®+^r^)¶¬jëh×6If $tempvar = $button Then $amount = GuiCtrlRead ($slider)oÝ÷ Ù»­¶+×¢¶X¤zØZµ«­¢+Ø)%ÀÌØíѵÁÙÈôÀÌØíÕÑѽ¸Q¡¸(ÀÌØíµ½Õ¹ÐôÕ¥
ÑɱI ÀÌØíͱ¥È¤

just to reduce errors and make it more clearly

Thx for the advanced help btw :lmao:

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Reduce errors? Shouldn't ? Well, actually that one-liner doesn't produce any errors while

the second does, because of a missing EndIf. Personally I always use one-liners when I

only need it to execute one statement...oh, well that's me.

Edited by Helge

Share this post


Link to post
Share on other sites

Reduce errors? Shouldn't ? Well, actually that one-liner doesn't produce any errors while

the second does, because of a missing EndIf. Personally I always use one-liners when I

only need it to execute one statement...oh, well that's me.

I agree with you :lmao:

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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