# Biggest noob questions of the day.. sorry

## Recommended Posts

I'm trying to define the varible with 12 different outcomes (depending on user input)

The reason for this is that the actual user input is not part of the formula the input is used in, and the input number is 100x easier for the user to find than the number I use in the formula.

Var1 is the user input

Var2 is the decimal number I need in the formula

```If \$var1 = 1 Then \$var2 =  0.03
If \$var1 = 2 Then \$var2 = 0.7
if \$var1 = 3 Then \$var2 = 1.2```

etc etc,

up to 12 inputs.

The real question is what do I need to add in between the "if" statements? I tried "else" "ElseIf"

To sortof make it check them 1 after 1, and when it finds the correct userinput and the assigns the correct decimal to \$var2.

I'm sorry guys I'm kinda new to coding, and really liking it.. Sorry if I waste your time, I really tried to read up on it.

##### Share on other sites

Is there only 1 user input (that can have 12 outcomes)?

If so you could use the CASE help documentation, but IF/ELSEIF/ELSE/ENDIF would work... assuming I understood your question correctly.

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

##### Share on other sites

```Switch \$var1
Case 1
\$var2 = 0.03
Case 2
\$var2 = 0.7
Case 3
\$var2 = 0.7
EndSwitch```

##### Share on other sites

Is there only 1 user input (that can have 12 outcomes)?

If so you could use the CASE help documentation, but IF/ELSEIF/ELSE/ENDIF would work... assuming I understood your question correctly.

1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 11

So I should read up on CASE and thatwould help me?

Sorry for being unclear

##### Share on other sites

1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 11

So I should read up on CASE and thatwould help me?

Sorry for being unclear

Yep (Geir1983 posted an example of CASE too).

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

##### Share on other sites

```Switch \$var1
Case 1
\$var2 = 0.03
Case 2
\$var2 = 0.7
Case 3
\$var2 = 0.7
EndSwitch```

Thanks man ! Okay I will try my best and get back to you guys <3

__

Yes sorry mrbeatnik I first saw that after I posted that

Edited by Srex

##### Share on other sites

Alright I gave it my best shot, and it seems like it compiles and runs fine. However at this point I'm not able to check if the right value is being assigned to the variable

Am I on the right track?

Also I am Thinking about throwing a Case else in, if the user should enter a value which is not smaller or greater than max/min but doesnt fit the required numbers either, like decimals so  something like:

```Case Else
MsgBox(16, "Error", "Something has gone wrong please check your Windows Sensitivity input number again")```
Edited by Srex

##### Share on other sites

Alright I gave it my best shot, and it seems like it compiles and runs fine. However at this point I'm not able to check if the right value is being assigned to the variable

Thinking about throwing a Case else in something like

```Elseif
MsgBox(16, "Error", "Something has gone wrong please check you Windows Sensitivity input number again")```

Am I on the right track?

Not quite...

You don't need the IFs - the CASE does the IF work for you.

```Switch \$WindowSensInput
Case 1                                                       ;Checks if \$WindowSensInput = 1
\$ActualWindowSens = 0.031
Case 2                                                       ;Checks if \$WindowSensInput = 2
\$ActualWindowSens = 0.222
Case 3                                                       ;Checks if \$WindowSensInput = 3
\$ActualWindowSens = 0.333
; Case n                                                       ;Checks if \$WindowSensInput = n
;   \$ActualWindowSens = whatever
Case Else                                                    ;Checks if \$WindowSensInput = any other value not stated
Msgbox(16,"Error","Your value is outside the range allowed")
EndSwitch```

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

##### Share on other sites

No, your \$ActualWindowsSens is always 0, therefore you do not execute any of the Case.

I think you want to use Switch on \$WindowsSensInput? The Switch Case then evaluates the value of that variable and executes the code below, all your following IF testing is then not needed..

##### Share on other sites

Or you could use an array...it depends on your comfortability level.

```#include <MsgBoxConstants.au3>

Local \$aOutcomes[10] = [1, 2, 100, 24, 8, 90, 76, 65, 7, 99], _
\$iOutcome = 9
If \$iOutcome >= 0 And \$iOutcome < UBound(\$aOutcomes) Then
MsgBox(\$MB_SYSTEMMODAL, '', \$aOutcomes[\$iOutcome])
EndIf```

##### Share on other sites

Not quite...

You don't need the IFs - the CASE does the IF work for you.

```Switch \$WindowSensInput
Case 1                                                       ;Checks if \$WindowSensInput = 1
\$ActualWindowSens = 0.031
Case 2                                                       ;Checks if \$WindowSensInput = 2
\$ActualWindowSens = 0.222
Case 3                                                       ;Checks if \$WindowSensInput = 3
\$ActualWindowSens = 0.333
; Case n                                                       ;Checks if \$WindowSensInput = n
;   \$ActualWindowSens = whatever
Case Else                                                    ;Checks if \$WindowSensInput = any other value not stated
Msgbox(16,"Error","Your value is outside the range allowed")
EndSwitch```

Aaaah so n = the number it checks for? thanks alot!

Or you could use an array...it depends on your comfortability level.

#include <MsgBoxConstants.au3>

Local \$aOutcomes[10] = [1, 2, 100, 24, 8, 90, 76, 65, 7, 99], _

\$iOutcome = 9

If \$iOutcome >= 0 And \$iOutcome < UBound(\$aOutcomes) Then

MsgBox(\$MB_SYSTEMMODAL, '', \$aOutcomes[\$iOutcome])

EndIf

Yeah then I could feel we stepped it up a few levels .

Haha thanks for stopping by.. Maybe one day I'll be more comfortable

And thanks for your help guys really appreciate you being so nice !

Edited by Srex

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...