Jump to content
kjpolker

No less than and no greater than (number)

Recommended Posts

kjpolker

Hello,

I have been digging through the help file and I can't find anything related to what I want.

I have in my code:

$i = 255

;blah blah

Func item1()
    WinSetTrans($hWnd, "", $i)
    $i -= 51
EndFunc

The point is to cycle through a new transparency with each call of the function. However, I need to set limits on $i to never be less than 0 or greater than 255. How is this achieved?

I am sure it's easy but I just don't see anything on it.

Edited by kjpolker

Share this post


Link to post
Share on other sites
Rex

This might work

If $i <= 0 or $i => 255 then

Cheers

/Rex

Share this post


Link to post
Share on other sites
kjpolker

I think you meant

If $i <= 255 And >= 0 Then

For some reason I get an error in expression dialogue on the $i.

I previously had tried

While $i <= 255 And >= 0

but got a similar error.

Share this post


Link to post
Share on other sites
Rex

You need to ad $i after the And operator, else the statement won't work

Cheers

/Rex

Share this post


Link to post
Share on other sites
Somerset

"operators" is what you need to look up in the help file


 

Spoiler

 

Share this post


Link to post
Share on other sites
kjpolker

Thank you! I didn't catch that. Final code works fine for what I am doing.

$i = 255

;Blah blah

Func Transparency1()
    If $i <= 255 And $i > 0 Then
    $i -= 51
    EndIf
    WinSetTrans($hWnd, "", $i)
EndFunc

Func Transparency2()
    If $i < 255 And $i >= 0 Then
    $i += 51
    EndIf
    WinSetTrans($hWnd, "", $i)
EndFunc
Edited by kjpolker

Share this post


Link to post
Share on other sites
kjpolker

@Somerset I was checking that out and figured it would be related to that, I just was having trouble thinking of the logic. I couldn't think of how to implement a variable in a function that didn't loop (I initially was thinking on the lines of For To Step). Thank you for the help!

Share this post


Link to post
Share on other sites
Rex

Thinks that most of had made that mistake once  :)

Glad it worked :)

Another way it could be done is using switch

$i = 255

;Blah blah

Func Transparency1()
    Switch $i
    case 1 to 255
    WinSetTrans($hWnd, "", $i)
    Endswitch
EndFunc

Func Transparency2()
    WinSetTrans($hWnd, "", $i)
    If $i < 255 And $i >= 0 Then $i += 51
EndFunc

Cheers

/Rex

 

Edited by Rex

Share this post


Link to post
Share on other sites
badcoder123

I know this isn't what you're looking for but I think it will lead you the right way.

 

For $i = 255 To 0 Step - 1
   WinSetTrans($hWnd, "", $i)
   $i -= 1
   Sleep(20)
   If $i = 0 Then WinSetTrans($hWnd, "", 255)
Next

 

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

×