Jump to content
Sign in to follow this  
frew

math statement assistance please, in a Switch Case

Recommended Posts

frew

Hello,

Could somebody please show me how to create a math statements that would achieve the results I describe in the comments.

$x = Random(66, 990, 1)
Switch $x
    Case $x =;any number between 66 and 990 that is a multiple of 24
        MsgBox(0, Default, $x)
    Case $x =;any number between 200 and 400
        MsgBox(0, Default, $x)
    Case $x =;any number NOT between 200 and 400
        MsgBox(0, Default, $x)
    Case Else
        MsgBox(0, Default, $x)
        Exit
EndSwitch

Thank you very much,

frew

Edited by frew

Share this post


Link to post
Share on other sites
MrMitchell

For multiple of 24 you might be able to use:

IsInt(Mod($x, 24))

If it returns a 0 then it's a multiple, otherwise it's not a multiple.

Between 200 and 400:

Case 200 To 400

Never done the third one but should be simple, I'm sure someone will jump in to help

Share this post


Link to post
Share on other sites
smashly

$x = Random(66, 990, 1)
Switch $x
    Case Not Mod($x, 24);$x = any number between 66 and 990 that is a multiple of 24
        MsgBox(0, "any number between 66 and 990 that is a multiple of 24", $x)
    Case 201 To 399;$x = any number between 200 and 400
        MsgBox(0, "any number between 200 and 400", $x)
    Case 66 To 200, 400 To 990;$x = any number NOT between 200 and 400
        MsgBox(0, "any number NOT between 200 and 400", $x)
EndSwitch

Share this post


Link to post
Share on other sites
MrMitchell

Getting closer lol

$x = Random(66, 990, 1)
Switch $x
    Case 200 To 400;any number between 200 and 400
        MsgBox(0, "", "$x = " & $x & ", it is between 200 and 400")
    Case 66 To 199, 401 To 990;any number NOT between 200 and 400
        MsgBox(0, "", "$x = " & $x & " and it is NOT between 200 and 400")
    Case Else
        ;
EndSwitch
    If Mod($x,24) = 0 Then MsgBox(0, "", "$x = " & $x & "and it is a multiple of 24")
Exit

Edit: Another way to write based on Smashly's code. This takes into account the possibility that $x can be a multiple of 24 as well as any of the Cases. I also adjusted the second case.

Edited by MrMitchell

Share this post


Link to post
Share on other sites
frew

I thank you both so much, MrMitchell, and smashly.

I can see these get the results that I asked for help with, but now I need to spend some time figuring out how these things work.

MrMitchell, I'm trying to understand

If NOT IsInt(Mod($x,24))

smashly, I'm trying to understand

Case Not Mod($x, 24)

Thank you for any explanations. I just about get it, but I'm not quite there yet.

frew

Share this post


Link to post
Share on other sites
MrMitchell

Ignore the

If NOT IsInt(Mod($x,24))

It is incorrect. Instead it should be what Smashly gave:

Case Not Mod($x, 24)

Modulus means what is the remainder of $x divided by 24? If the remainder is 0 then it is a multiple of 24. If the result is anything other than 0 then it's not a multiple because you have a remainder ^_^

Share this post


Link to post
Share on other sites
smashly

smashly, I'm trying to understand

Case Not Mod($x, 24)

Thank you for any explanations. I just about get it, but I'm not quite there yet.

frew

Not Mod($x, 24) is the same as Mod($x, 24) = 0

If $x is evenly divided by 24 then Mod will return 0

If $x is not evenly divided by 24 then Mod will return different to 0

Share this post


Link to post
Share on other sites
MrMitchell

$x = Random(66, 990, 1)
Switch $x
    Case Not Mod($x, 24);$x = any number between 66 and 990 that is a multiple of 24
        MsgBox(0, "any number between 66 and 990 that is a multiple of 24", $x)
        ContinueCase               ;<<=== Added this line
    Case 201 To 399;$x = any number between 200 and 400
        MsgBox(0, "any number between 200 and 400", $x)
    Case 66 To 200, 400 To 990;$x = any number NOT between 200 and 400
        MsgBox(0, "any number NOT between 200 and 400", $x)
EndSwitch
Too add to Smashly's code, if the number is a multiple of 24 then the Switch will end and won't tell you what range the number falls under. If you want it to keep going place a ContinueCase statement just before the next case so that it will continue to the next Case. I didn't know this until now ^_^ Edited by MrMitchell

Share this post


Link to post
Share on other sites
frew

If the result is anything other than 0 then it's not a multiple because you have a remainder.

Thanks MrMitchell

Not Mod($x, 24) is the same as Mod($x, 24) = 0

Thanks smashly.

I did not know that. That's good to know. That is a very helpful explanation.

Thank you both so much, that really helped a lot to understand some very interesting and useful uses for the Mod math function.

Thanks again!

frew

Share this post


Link to post
Share on other sites
Valuater

$x = "Valuater"
MsgBox(4096, "", Not Mod($x, 24))

lol

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
frew

MrMitchell,

the Switch will end and won't tell you what range the number falls under

In my case, I do not need to know the range the number is in, as long as the action I put in the case is done.

Thank you very much though MrMitchell, because it's nice to know that the ContinueCase is an option if I ever want it.

That's good to know.

Valuater

That sure looks funny. I wish I could get that but it's coding humor that it over my head at this point.

I tried it and it kept saying true, true,...ha! I don't get it but it's funny still.

Seeya,

frew

Share this post


Link to post
Share on other sites
frew

Not to belabor the point too far, but if anybody cares to do so, would you please give an explanation of what these are doing:

MsgBox(0, Default, Mod(24,24))
MsgBox(0, Default, Not Mod(24,24))
MsgBox(0, Default, Mod(27,24))
MsgBox(0, Default, Not Mod(27,24))

I get the first one...zero because the result of 24 divided by 24 is zero.

The second is "not zero" so it says true, because zero is false.

The third one is 3 because 27 divided by 24 equals 1 with a remainder of 3.

The fourth one I do not get yet. What does that one mean? Why does it say false?

Thanks for any ideas.

frew

Edited by frew

Share this post


Link to post
Share on other sites
MrMitchell

1. It's not the result of 24 divided by 24, it's the remainder of 24 divided by 24 which is 0. The result is 1 remainder 0, so it returns the remainder of 0 or FALSE.

2. Opposite of above, returns TRUE or not zero

3. You are correct, returns 3 because that's the remainder. The fact that it's not zero tells you the number is not an even multiple of 24.

4. It returns 3 which is TRUE, so when you put that NOT there it changes it to False.

I hope that makes sense?

Share this post


Link to post
Share on other sites
frew

I hope that makes sense?

Thanks MrMitchell for going over those details. I really appreciate it.

Yes, it starts to make sense. Takes a little while to get used to thinking in these terms.

By the way, in

MsgBox(0, Default, Not Mod(27,24))

I guess 3 is true because it is not zero.

With your clarifications, I think I'm onto it now.

Thanks again,

frew

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  

×