Jump to content

If Then Endif Infinity


glasglow
 Share

Recommended Posts

I have found myself in a very very very long file with for example:

If 
$something = "something" 
Then
_something($something,$ship)
Endif
If 
$something2 = "something" 
Then
_something($something2,$ship)
Endif
If 
$something3 = "something" 
Then
_something($something3,$ship)
Endif
If 
$something4 = "something" 
Then
_something($something4,$ship)
Endif
If 
$something5 = "something" 
Then
_something($something5,$ship)
Endif

Can I array this? Make it shorter?

Edited by glasglow
Link to comment
Share on other sites

well for starters it would be easier if you gave more info on what your trying to achieve.

and also..

if $something ="what" then

whatever

elseif $something = "what2" then

whatever

elseif $something = "what3" then

whatever

endif

Edited by Aceguy
Link to comment
Share on other sites

dim $something[50]

for $count = 1 to $something[0]

if $something[$count]= "Whatever" then

dosomething

endif

next

Yes this is closer to what I am looking for.. Could I array it? I'm looking for a match for example: (pardon the code but I hope you get the idea)

IF
$something = ("one" OR "two" OR "three" OR "four")
Then
Do Something

I know it's rediculous code but it seems I shoul be able to do it with an array.

Edited by glasglow
Link to comment
Share on other sites

$something = StringSplit("This,That,The other,This way,That way,The other way", ",")
$return = StringSplit("Not,Nat,Nope,Dope,Pope,Rope", ",")

; match found
MsgBox(0x0, "answer", "Something = " & _something("That way"))

; no match
MsgBox(0x0, "answer", "Something = " & _something("Thats way"))


Func _something($info)
    For $x = 1 To $something[0]
        If $something[$x] = $info Then Return $return[$x] ; return what ever you want
    Next
    Return "nada" 
EndFunc   ;==>_something

8)

NEWHeader1.png

Link to comment
Share on other sites

$something = StringSplit("This,That,The other,This way,That way,The other way", ",")
$return = StringSplit("Not,Nat,Nope,Dope,Pope,Rope", ",")

; match found
MsgBox(0x0, "answer", "Something = " & _something("That way"))

; no match
MsgBox(0x0, "answer", "Something = " & _something("Thats way"))


Func _something($info)
    For $x = 1 To $something[0]
        If $something[$x] = $info Then Return $return[$x] ; return what ever you want
    Next
    Return "nada" 
EndFunc   ;==>_something

8)

Man that's a great one. The Return will be written as a DO but it's a nice, very nice thank you. You had a Filesearch on here.. also a very nice example. We can all learn a lot from you.

Edited by glasglow
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...