# Variable Help

## Recommended Posts

I have

```\$a = "A"
\$b = "B"
\$c = "C"
\$d = "D"
\$1 = "1"
\$2 = "2"
\$3 = "3"
\$4 = "4"

\$letter = \$a Or \$b Or \$c Or \$d
\$number = \$1 Or \$2 Or \$3 Or \$4

\$input1 = InputBox("", "1")
\$input2 = InputBox("", "2")

If \$input1 = \$letter Then
MsgBox(0, "", "Yay")
EndIf

If \$input2 = \$number Then
MsgBox(0, "", "Boo")
EndIf```

No matter what i put in each box i get the message boxes.

Any ideas on how i only get the "Yay" message box if a letter is typed in the first input box and only the "Boo" message box if a number is typed in the second?

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

##### Share on other sites

```\$input1 = InputBox("", "1")
\$input2 = InputBox("", "2")

If \$input1 >= Asc("A") And \$input1 <= Asc("Z") Or \$input1 >= Asc("a") And \$input1 <= Asc("z") Then
MsgBox(0, "", "Yay")
EndIf

If \$input1 >= Asc("1") And \$input1 <= Asc("0") Then
MsgBox(0, "", "Boo")
EndIf```

*** Nt tested.

#)

##### Share on other sites

Sorry this was just a demonstration to illustrate my point.

My real script uses Elements from the periodic table

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

##### Share on other sites

Try this, maybe...

```\$input1 = InputBox("", "1")
\$input2 = InputBox("", "2")

If StringRegExp(\$input1, '(?i)[A-D]') Then  ;remove (?i) if you want case sensitive
MsgBox(0, "", "Yay")
EndIf

If StringRegExp(\$input2, '([1-4])') Then
MsgBox(0, "", "Boo")
EndIf```

##### Share on other sites

thanks it work nicely so far (subed in in my variables in for the '(?i)[A-D]')

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

##### Share on other sites

Sorry it didn't work have no idea i thought it did.

Yours worked but when i sub in my variables it doesn't.

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

##### Share on other sites

Sorry it didn't work have no idea i thought it did.

Yours worked but when i sub in my variables it doesn't.

You should do yourself a favor, and post the actual code that is giving you problems... You're only prolonging getting the right answer by trying to shortcut something you obviously don't know how to do.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

I am just starting, i don't want to put in too many elements if i can't get this to work

as you can see i was hoping to group the elements into various groups to make my life easer.

```; Elements
\$H = "H" ; Hyodregen
\$He = "He" ; Helium
\$Li = "Li" ; Lithium
\$Be = "Be" ; Beryllium
\$B = "B" ; Boron
\$C = "C" ; Carbon
\$N = "N" ;  Nitrogen
\$O = "O" ; Oxygen
\$F = "F" ; Fluorine
\$Ne = "Ne" ; Neon
\$Na = "Na" ; Sodium
\$Mg = "Mg" ; Magnesium
\$Al = "Al" ; Aluminum
\$Si = "Si" ; Silicone
\$P = "P" ; Phosphate
\$S = "S" ; Sulfur
\$Cl = "Cl" ; Chlorine
\$Ar = "Ar" ; Argon
\$K = "K" ; Potassium
\$Ca = "Ca" ; Calcium

\$Metals = \$Al Or \$Ar ; gonna be more here testing purposes

\$Rnumber = InputBox("Chemical Equation Completor", "Please enter the number of reactants", 2)
; 1 reactant
If \$Rnumber = 1 Then
\$Reactant1 = InputBox("Chemical Equation Completor", "Enter the chemical formula of your reactant")
EndIf

; 2 reactants
If \$Rnumber = 2 Then
\$Reactant1 = InputBox("Chemical Equation Completor", "Enter the chemical formula of your first reactant")
\$Reactant2 = InputBox("Chemical Equation Completor", "Enter the chemical formula of your second reactant")
If \$Reactant1 = \$Metals Then
MsgBox(0, "yay", "test1")
Else
MsgBox(0, "Error", "dam")
EndIf
EndIf

; >2 reactants
If \$Rnumber >2  Then
MsgBox(0, "Error", "This simulator can not simulate " & \$Rnumber & " reactants")
EndIf```

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

##### Share on other sites

See if this can give you some ideas:

```\$input = _findstuff(InputBox('', ''))

If @error Then
MsgBox(0, '', 'nothing found')
Else
MsgBox(0, '', \$input)
EndIf

Func _findstuff(\$var)
Local \$stuff[2][20] = _
[["H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", _
"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca"], _
['Hyodregen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen', 'Oxygen', 'Fluorine', 'Neon', _
'Sodium', 'Magnesium', 'Aluminum', 'Silicone', 'Phosphate', 'Sulfur', 'Chlorine', 'Argon', 'Potassium', 'Calcium']]
For \$i = 0 To 19
If \$var = \$stuff[0][\$i] Then
Return \$stuff[0][\$i] & ' - ' & \$stuff[1][\$i]
EndIf
Next
SetError(1)
EndFunc```
Edited by xcal

## Create an account

Register a new account

×

• Wiki

• Back

• Git