Jump to content

function based on number (easy)


Arclite86
 Share

Recommended Posts

I would like to create multiple function for example

something like this

;I have a number = $number

Funcion1 
Funcion2
Funcion3
Funcion4
Funcion5
Funcion6



If $number = Bellow 100 then Funcion1
If $number = Bellow 200 then Funcion2
If $number = Bellow 300 then Funcion3
If $number = Bellow 400 then Funcion4
If $number = Bellow 500 then Funcion5
If $number = Above 600 then Funcion6

I think this is pretty easy and im very close but im not familiar with this

so could somebody please help me.

Link to comment
Share on other sites

  • Moderators

Arclite86,

Look at Switch or Select - these conditional structures can do what you want. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Local $number = 10


Select
    Case $number <= 100
        Function1()
    Case $number <= 200 > 100
        Function2()
    Case $number <= 300 > 200
        Function3()
    Case $number <= 400 > 300
        Function4()
    Case $number <= 500 > 400
        Function5()
    Case $number >= 600
        Function6()
EndSelect


Func Function1()
    ; do stuff
EndFunc

Func Function2()
    ; do stuff
EndFunc

Func Function3()
    ; do stuff
EndFunc

Func Function4()
    ; do stuff
EndFunc

Func Function5()
    ; do stuff
EndFunc

Func Function6()
    ; do stuff
EndFunc

something like this?

EDIT: see, you still have it ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Local $number = 10


Select
    Case $number <= 100
        Function1()
    Case $number <= 200 > 100
        Function2()
    Case $number <= 300 > 200
        Function3()
    Case $number <= 400 > 300
        Function4()
    Case $number <= 500 > 400
        Function5()
    Case $number >= 600
        Function6()
EndSelect


Func Function1()
    ; do stuff
EndFunc

Func Function2()
    ; do stuff
EndFunc

Func Function3()
    ; do stuff
EndFunc

Func Function4()
    ; do stuff
EndFunc

Func Function5()
    ; do stuff
EndFunc

Func Function6()
    ; do stuff
EndFunc

something like this?

EDIT: see, you still have it ;)

 thank you that looks what i want but i have a question

I want to use this in a function 

Func counter()

Local $number = 10


Select

    Case $number <= 100
; do stuff
    Case $number <= 200 > 100
; do stuff
    Case $number <= 300 > 200
; do stuff
    Case $number <= 400 > 300
; do stuff
    Case $number <= 500 > 400
; do stuff
    Case $number >= 600
; do stuff
        

EndSelect

Endfunc

So is this also possible?

Link to comment
Share on other sites

Arclite86 - try it ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

@MikahS

works nice  :)

Local $number = 250
 
Select
    Case $number <= 100
        Function1()
    Case $number <= 200 > 100
        Function2()
    Case $number <= 300 > 200
        Function3()
    Case $number <= 400 > 300
        Function4()
    Case Else
        Function5()
EndSelect
 
Func Function1()
    msgbox(0,"", "func1")
EndFunc
 
Func Function2()
    msgbox(0,"", "func2")
EndFunc
 
Func Function3()
    msgbox(0,"", "func3")
EndFunc
 
Func Function4()
    msgbox(0,"", "func4")
EndFunc
 
Func Function5()
    msgbox(0,"", "check your syntax")
EndFunc
Edited by mikell
Link to comment
Share on other sites

 

@MikahS

works nice  :)

Local $number = 250
 
Select
    Case $number <= 100
        Function1()
    Case $number <= 200 > 100
        Function2()
    Case $number <= 300 > 200
        Function3()
    Case $number <= 400 > 300
        Function4()
    Case Else
        Function5()
EndSelect
 
Func Function1()
    msgbox(0,"", "func1")
EndFunc
 
Func Function2()
    msgbox(0,"", "func2")
EndFunc
 
Func Function3()
    msgbox(0,"", "func3")
EndFunc
 
Func Function4()
    msgbox(0,"", "func4")
EndFunc
 
Func Function5()
    msgbox(0,"", "check your syntax")
EndFunc

Except your not looking for a number below 500, and your case else will catch this and tell you check your syntax even when its still a number ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Another way to express this...

Local $number = 938

Switch $number
    Case 100 to 199
        Function1()
    Case 200 to 299
        Function2()
    Case 300 to 399
        Function3()
    Case 400 to 499
        Function4()
    Case 500 to 599
        Function5()
    Case 600 to 699
        Function6()
    case else
        ConsoleWrite('no function for number' & @CRLF)
Endswitch


Func Function1()
    ConsoleWrite('Func 1' & @CRLF)
EndFunc

Func Function2()
    ConsoleWrite('Func 2' & @CRLF)
EndFunc

Func Function3()
    ConsoleWrite('Func 3' & @CRLF)
EndFunc

Func Function4()
    ConsoleWrite('Func 4' & @CRLF)
EndFunc

Func Function5()
    ConsoleWrite('Func 5' & @CRLF)
EndFunc

Func Function6()
    ConsoleWrite('Func 6' & @CRLF)
EndFunc

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Or reverse thedirection.

Local $number = 938

Select
    Case $number > 599
        Function1()
    Case $number > 499
        Function2()
    Case $number > 399
        Function3()
    Case $number > 299
        Function4()
    Case $number > 199
        Function5()
    Case $number > 99
        Function6()
    Case else
        ConsoleWrite('no function for number' & @CRLF)
EndSelect


Func Function1()
    ConsoleWrite('Func 1' & @CRLF)
EndFunc

Func Function2()
    ConsoleWrite('Func 2' & @CRLF)
EndFunc

Func Function3()
    ConsoleWrite('Func 3' & @CRLF)
EndFunc

Func Function4()
    ConsoleWrite('Func 4' & @CRLF)
EndFunc

Func Function5()
    ConsoleWrite('Func 5' & @CRLF)
EndFunc

Func Function6()
    ConsoleWrite('Func 6' & @CRLF)
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

True masochist would do it like this:

#AutoIt3Wrapper_Run_AU3Check=n ; if you use AutoIt3Wrapper

Local $number = 251


$number <= 100 ? _
    Function1() : _
        $number <= 200 ? _
            Function2() : _
                $number <= 300 ? _
                    Function3() : _
                        $number <= 400 ? _
                            Function4() : _
                                Function5()

Func Function1()
    MsgBox(0, "", "func1")
EndFunc

Func Function2()
    MsgBox(0, "", "func2")
EndFunc

Func Function3()
    MsgBox(0, "", "func3")
EndFunc

Func Function4()
    MsgBox(0, "", "func4")
EndFunc

Func Function5()
    MsgBox(0, "", "func5")
EndFunc

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Here another variant:
 

$iNumber = 500
For $i = 100 To 700 Step 100
    If ($iNumber / $i) <= 1 Then
        Call("Func" & $i / 100)
        ExitLoop
    EndIf
Next

Func Func1()
    MsgBox(0, "Function1", "< 100")
EndFunc
Func Func2()
    MsgBox(0, "Function2", "> 100 to <= 200")
EndFunc
Func Func3()
    MsgBox(0, "Function3", "> 200 to <= 300")
EndFunc
Func Func4()
    MsgBox(0, "Function4", "> 300 to <= 400")
EndFunc
Func Func5()
    MsgBox(0, "Function5", "> 400 to <= 500")
EndFunc
Func Func6()
    MsgBox(0, "Function5", "> 500 to <= 600")
EndFunc
Func Func7()
    MsgBox(0, "Function6", ">= 600")
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

variant of trancexx'

Local $number = 251
Local $aFunc = [Function1, Function2, Function3, Function4, Function5]
$val = $number <= 100 ? 0 : $number <= 200 ? 1 : $number <= 300 ? 2 : $number <= 400 ? 3 : 4

$aFunc[$val]()

Func Function1()
    MsgBox(0, "", "func1")
EndFunc

Func Function2()
    MsgBox(0, "", "func2")
EndFunc

Func Function3()
    MsgBox(0, "", "func3")
EndFunc

Func Function4()
    MsgBox(0, "", "func4")
EndFunc

Func Function5()
    MsgBox(0, "", "func5")
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

variant of UEZ' variant

$number = 500
$number < 700 ? Call("Func" & Ceiling($number / 100)) : Msgbox(0,"", "off limit")

Func Func1()
    MsgBox(0, "Function1", "< 100")
EndFunc
Func Func2()
    MsgBox(0, "Function2", "> 100 to <= 200")
EndFunc
Func Func3()
    MsgBox(0, "Function3", "> 200 to <= 300")
EndFunc
Func Func4()
    MsgBox(0, "Function4", "> 300 to <= 400")
EndFunc
Func Func5()
    MsgBox(0, "Function5", "> 400 to <= 500")
EndFunc
Func Func6()
    MsgBox(0, "Function5", "> 500 to <= 600")
EndFunc
Func Func7()
    MsgBox(0, "Function6", ">= 600")
EndFunc
Link to comment
Share on other sites

$i7b = number(14)


Select
    Case $i7b == 1
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 2
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 3
        MsgBox("Title", "test","Good!!!" ,5000)
    Case $i7b == 14
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 26
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 80
        MsgBox("Title", "test","not good" ,5000)
    
EndSelect

I want something like this: if $i7b is equal to (for example) 14 then MsgBox("Title", "test","Good!!!" ,5000)

Link to comment
Share on other sites

Nobody seems to have frown on this:

Local $number = 250
...
    Case $number <= 300 > 200

While this is valid syntax, the outcome differs from what the author intends.

This will evaluate as:

($number <= 300) > 200

that is

True > 200

giving

False

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

$i7b = number(14)


Select
    Case $i7b == 1
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 2
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 3
        MsgBox("Title", "test","Good!!!" ,5000)
    Case $i7b == 14
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 26
        MsgBox("Title", "test","not good" ,5000)
    Case $i7b == 80
        MsgBox("Title", "test","not good" ,5000)
    
EndSelect

I want something like this: if $i7b is equal to (for example) 14 then MsgBox("Title", "test","Good!!!" ,5000)

im sorry i placed the MsgBox("Title", "test","Good!!!" ,5000)  bellow he wrong case

It works

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