Sign in to follow this  
Followers 0
quimber

If, then, elseif (variable)

10 posts in this topic

Hello Fellows.

Im stuck here with a problem.

Func DRead()
    if PixelChecksum(319,366, 343,380) = 3424908151 Then
            $d = 11
            
        Elseif  PixelChecksum(361,286, 377,302) = 3788702988 Then
            $d = 10
            
        Elseif  PixelChecksum(361,286, 377,302) = 1899558135 Then
            $d = 9

        Elseif  PixelChecksum(361,286, 377,302) = 1334835615 Then
            $d = 8
            
        Elseif  PixelChecksum(361,286, 377,302) = 3009408268 Then
            $d = 7
            
        Elseif  PixelChecksum(361,286, 377,302) = 2558587799 Then
            $d = 6
            
        Elseif  PixelChecksum(361,286, 377,302) = 691401147 Then
            $d = 5
            
        Elseif  PixelChecksum(361,286, 377,302) = 3552571860 Then
            $d = 4

        Elseif  PixelChecksum(361,286, 377,302) = 3075731130 Then
            $d = 3
            
        Elseif  PixelChecksum(361,286, 377,302) = 4247515403 Then
            $d = 2
        EndIf
            
    sleep(2000)
    WinActivate("Untitled -")
    Send($d)
    sleep(2000)

    
EndFunc

But i get this erro:

(169) : ==> Variable used without being declared.:

Send($d)

Send(^ ERROR

What can i do to fix it?

Share this post


Link to post
Share on other sites



Hello Fellows.

Im stuck here with a problem.

But i get this erro:

(169) : ==> Variable used without being declared.:

Send($d)

Send(^ ERROR

What can i do to fix it?

You need to declare the variable because if none of the conditions is satisfied then the variable won't have been assigned any value.

Maybe this would do what you want

Func DRead()
Local $d = "nothing"
    if PixelChecksum(319,366, 343,380) = 3424908151 Then
            $d = 11
            
        Elseif  PixelChecksum(361,286, 377,302) = 3788702988 Then
            $d = 10
            
        Elseif  PixelChecksum(361,286, 377,302) = 1899558135 Then
            $d = 9

        Elseif  PixelChecksum(361,286, 377,302) = 1334835615 Then
            $d = 8
            
        Elseif  PixelChecksum(361,286, 377,302) = 3009408268 Then
            $d = 7
            
        Elseif  PixelChecksum(361,286, 377,302) = 2558587799 Then
            $d = 6
            
        Elseif  PixelChecksum(361,286, 377,302) = 691401147 Then
            $d = 5
            
        Elseif  PixelChecksum(361,286, 377,302) = 3552571860 Then
            $d = 4

        Elseif  PixelChecksum(361,286, 377,302) = 3075731130 Then
            $d = 3
            
        Elseif  PixelChecksum(361,286, 377,302) = 4247515403 Then
            $d = 2
        EndIf
    if $d <> "nothing" then     
        sleep(2000)
        WinActivate("Untitled -")
        Send($d)
    EndIf
    sleep(2000)

    
EndFunc

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.

Share this post


Link to post
Share on other sites

Hey and thx

But it still dosent work, it will always set $d to "nothing" but there is allways one of the elseif wich should get trigget but it just wont set any of them, what is wrong :S?

Share this post


Link to post
Share on other sites

Hey and thx

But it still dosent work, it will always set $d to "nothing" but there is allways one of the elseif wich should get trigget but it just wont set any of them, what is wrong :S?

Add a debuigging line at the start

ConsoleWrite(PixelChecksum(361,286, 377,302) & @CR)

to see what value is returned and to understand why none of the values tested is true.


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.

Share this post


Link to post
Share on other sites

Great works now, but now i got i new prob. can i set a variable in func 1 and then use it at another func ?

I tryed and it seems like when i go for a new func i forgets the variable

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

well you can do that if you use global keyword see help file about that

and here's a little organizing for your script

MsgBox("", "Result", DRead())

Func DRead()
    $Result = 0
    If PixelChecksum(319, 366, 343, 380) = 3424908151 Then $Result = 11
    Switch PixelChecksum(361, 286, 377, 302)
        Case 3788702988
            $Result = 10

        Case 1899558135
            $Result = 9

        Case 1334835615
            $Result = 8

        Case 3009408268
            $Result = 7

        Case 2558587799
            $Result = 6

        Case 691401147
            $Result = 5

        Case 3552571860
            $Result = 4

        Case 3075731130
            $Result = 3

        Case 4247515403
            $Result = 2
    EndSwitch
    Return $Result
EndFunc ;==>DRead

edited : wrong if statment fixed

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

you can use "And"

Func Move()
    ConsoleWrite('No move for this' & @CR)
    If $p <= 8 And $d = 2 Then ConsoleWrite('1' & @CR)
    If $p = 9 And $d = 3 Then ConsoleWrite('2' & @CR)
EndFunc

but if you want to do more if the first isn't write you can use "if" with "not" like

If Not $p <= 8 Then

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

you can use "And"

Func Move()
    ConsoleWrite('No move for this' & @CR)
    If $p <= 8 And $d = 2 Then ConsoleWrite('1' & @CR)
    If $p = 9 And $d = 3 Then ConsoleWrite('2' & @CR)
EndFunc

but if you want to do more if the first isn't write you can use "if" with "not" like

If Not $p <= 8 Then

Just found out but you were to fast to reply :P (Diddnt read the help thru the fist time) But thx :( Edited by quimber

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

example

Func move($p, $d)
    
    If $p <= 8 Then
        
        If $d = 2 Then
            ConsoleWrite('1' & @CR)
        Else
            ConsoleWrite('0' & @CR)
        EndIf

    ElseIf $p = 9 Then
        If $d = 3 Then
            ConsoleWrite('2' & @CR)
        ElseIf $d = 4 Then
            ConsoleWrite('4' & @CR)
        Else
            ConsoleWrite('Error' & @CR)
        EndIf

    Else
        ConsoleWrite('No move for this' & @CR)
        
    EndIf

EndFunc   ;==>move

8)

Edited by Valuater

NEWHeader1.png

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