# Confused... "If" etc

## Recommended Posts

Heya! Yes, i'm back, with another question.

I'm creating a script (duh!) and i'm having alot of trouble figuring out If/EndIf/Then/Next etc If this is an easy part, please slap me as hard as you can.

I've made some of my script (Works fine), but I need an If entering in it. I need it to check if "[CLASSNN:TStaticText1]" has the Text "1", and if it does; Give a MsgBox and stop the bot. And if it isn't "1", then to send a few keys then repeat. Just helping me with the layout of this would be extremely appreciated

Now, i'm not asking for all the script to be written, but the fundementals of If/EndIf/Then/Next so I can be on my way to make more advanced scripts in the future.

Thank you ever so much if you take your time to help me!

##### Share on other sites

ok how it works is

you start out with an If statement and after you put your If you put a Then ---> If \$x = 1 Then

now you can put an Else or ElseIf. Else is just if the If is not true.

ElseIf requires a second statement. for example ----------------------------------> ElseIf \$x = 2 Then

you can use as many ElseIf's as you want.

when all of your ElseIf's are added, you end with a EndIf -------------------------> EndIf

so for example you could say

```\$x = random(1, 2, 1)
If \$x = 1 Then
MsgBox(0, "hi", "Autoit is cool and your result is " & \$x)
ElseIf \$x = 2 Then
MsgBox(0, "hi", "AUTOIT F*CKING OWNS.  RESULT IS " & \$x)
EndIf```
Edited by Tomb616

##### Share on other sites

ok how it works is

you start out with an If statement and after you put your If you put a Then ---> If \$x = 1 Then

now you can put an Else or ElseIf. Else is just if the If is not true.

ElseIf requires a second statement. for example ----------------------------------> ElseIf \$x = 2 Then

you can use as many ElseIf's as you want.

when all of your ElseIf's are added, you end with a EndIf -------------------------> EndIf

so for example you could say

```\$x = random(1, 2, 1)
If \$x = 1 Then
MsgBox(0, "hi", "Autoit is cool and your result is " & \$x)
ElseIf \$x = 2 Then
MsgBox(0, "hi", "AUTOIT F*CKING OWNS.  RESULT IS " & \$x)
EndIf```
Hey, I get it! That's awesome, thank yooooouuuu

Is there anyway to get the MsgBox to Display what text is in TStaticText2 & TStaticText3 also? What make an excellent addition.

##### Share on other sites

sure no problem

actually yes you can change MsgBox text

```Local \$ChangeText[4] = ['', 'Enable', 'Disable', 'Quit']
\$iMsg = _MsgBoxEx(3, 'nothing', 'something', 0, \$ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & \$iMsg)

Func _MsgBoxEx(\$iFlag, \$sTitle, \$sText, \$iTime = 0, \$sCIDChange = '')
Local \$_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & \$iFlag & ', ""' & \$sTitle & '"", ""' & \$sText & '"", ' & \$iTime & '"))'
Local \$iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & \$_MsgBox_, '', @SW_SHOW, 6)
Do
Sleep(10)
Until WinExists(\$sTitle)
If IsArray(\$sCIDChange) Then
For \$iCC = 1 To UBound(\$sCIDChange) - 1
ControlSetText(\$sTitle, '', 'Button' & \$iCC, \$sCIDChange[\$iCC])
Next
Else
ControlSetText(\$sTitle, '', 'Button1', \$sCIDChange)
EndIf
While ProcessExists(\$iPID)
If Number(\$iStdOut) Then Return \$iStdOut
Sleep(10)
WEnd
If IsArray(\$sCIDChange) Then Return SetError(1, 0, 2)
Return SetError(1, 0, 1)
EndFunc```

##### Share on other sites

sure no problem

actually yes you can change MsgBox text

```Local \$ChangeText[4] = ['', 'Enable', 'Disable', 'Quit']
\$iMsg = _MsgBoxEx(3, 'nothing', 'something', 0, \$ChangeText)
MsgBox(64, 'Info', 'The Return Was: ' & \$iMsg)

Func _MsgBoxEx(\$iFlag, \$sTitle, \$sText, \$iTime = 0, \$sCIDChange = '')
Local \$_MsgBox_ = '"' & "ConsoleWrite(MsgBox(" & \$iFlag & ', ""' & \$sTitle & '"", ""' & \$sText & '"", ' & \$iTime & '"))'
Local \$iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & \$_MsgBox_, '', @SW_SHOW, 6)
Do
Sleep(10)
Until WinExists(\$sTitle)
If IsArray(\$sCIDChange) Then
For \$iCC = 1 To UBound(\$sCIDChange) - 1
ControlSetText(\$sTitle, '', 'Button' & \$iCC, \$sCIDChange[\$iCC])
Next
Else
ControlSetText(\$sTitle, '', 'Button1', \$sCIDChange)
EndIf
While ProcessExists(\$iPID)
If Number(\$iStdOut) Then Return \$iStdOut
Sleep(10)
WEnd
If IsArray(\$sCIDChange) Then Return SetError(1, 0, 2)
Return SetError(1, 0, 1)
EndFunc```
Is there no other way? That's looks way out of my league. Lol

##### Share on other sites

a way to change message box text?

or something else?

##### Share on other sites

a way to change message box text?

or something else?

ControlGetText I was/am using. The Text inside TStaticTextX I would like displayed inside the MsgBox? :/

##### Share on other sites

Nevermind! I found out by trail and error!

Thank you Tomb for your help. Hugely appreciated!

##### Share on other sites

sure no problem

now im curious, how did you do it.

##### Share on other sites

sure no problem

now im curious, how did you do it.

Kinda like:

```\$x = ControlGetText ("Window","","[CLASSNN:TStaticTextX]")
MsgBox (46,"Window Name","X=" & \$x,0)```

##### Share on other sites

A tip when you're looking for help is to post the actuall code you have, it will be alot easier to understand what you're having problems with.

## Create an account

Register a new account