If statement checking for multiple strings

If statement checking for multiple strings

will_roe
Enthusiast Enthusiast
1,188 Views
4 Replies
Message 1 of 5

If statement checking for multiple strings

will_roe
Enthusiast
Enthusiast

Hi,

 

I feel like this should be simple but I've searched all I can think of to do it correctly but can't find a answer. I just want a if statement to check to see if the first character is correct and show a message box and set a parameter if it's not.

 

I'm getting a 1-dimensional array of String'  error

 

ID_1_CHAR = IDTAG
Dim oID1 = Left((ID_1_CHAR), 1)


If oID1 <> {"H" Or "V" Or "H"} Then
MessageBox.Show("First character must be M, H or V", "Incorrect Input")
IDTAG = "H1234"
End If

 

Thanks in advance.

0 Likes
Accepted solutions (2)
1,189 Views
4 Replies
Replies (4)
Message 2 of 5

dutt.thakar
Collaborator
Collaborator
Accepted solution

@will_roe 

 

When you use {} bracket it is identified as an array inside iLogic or VB.Net, that is why you are getting an error, as in the first-line you are defining a variable not an array, try below code instead and see if this helps you. You need to write like shown in Bold characters, to check multiple strings.

 

ID_1_CHAR = Parameter("IDTAG")
Dim oID1 = Left((ID_1_CHAR), 1)


If (oID1 <> "H" Or oID1 <> "V" Or oID1 <> "H") Then
MessageBox.Show("First character must be M, H or V", "Incorrect Input")
Parameter("IDTAG") = "H1234"
End If

 Hope this helps.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 3 of 5

will_roe
Enthusiast
Enthusiast

@dutt.thakar 

 

It doesn't seem to be working as expected - the message box shows with any input. It seems to work fine if I have a single variable like the below.

if  oID1 <> "H" Then

 

So I think I've misunderstood how the statement will work? Is the below just checking if oID1 doesn't = all of the values (H, V & M) So even if oID1 = H the statement will trip up because it doesn't = V or M?

 

If (oID1 <> "H" Or oID1 <> "V" Or oID1 <> "M") Then

 

This will work for my purposes but I'm wondering if there's a more elegant way to write it?

ID_1_CHAR = Parameter("IDTAG")
Dim oID1 = Left((ID_1_CHAR), 1)


If (oID1 = "H" Or oID1 = "V" Or oID1 = "M") Then
'Insert code here
MessageBox.Show("It worked", "Title")
Else
MessageBox.Show("First character must be M, H or V", "Incorrect Input")
Parameter("IDTAG") = "H1234"
End If
 

 

0 Likes
Message 4 of 5

dutt.thakar
Collaborator
Collaborator
Accepted solution

@will_roe 

 

Ok, I think below is another way which is quite easy to write (Using Select Case) and understand and may serve your purpose as well.

 

ID_1_CHAR = Parameter("IDTAG")
Dim oID1 = Left((ID_1_CHAR), 1)
Select oID1 Case "H", "M", "V" MessageBox.Show("It worked", "Title") Case Else MessageBox.Show("First character must be M, H or V", "Incorrect Input")
Parameter("IDTAG") = "H1234" End Select

 See if this helps.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 5 of 5

will_roe
Enthusiast
Enthusiast

Awesome, thanks @dutt.thakar !

0 Likes