Using the "Or" operand on String's?
-
Thursday, September 06, 2012 1:23 PM
I am trying to execute the following command:
If ComboMonth.Text <> (("September") || ("April") || ("June") || ("November")) ThenUnfortunately however the error i recieve is "character is not valid" for the || operand.
How do i go about using an "or" equivalent operand on Strings such as these, or better yet, why am i recieving this error, surely this should work?
Thank you for your help in advance.
- Edited by Kaya Suleyman Thursday, September 06, 2012 1:27 PM
All Replies
-
Thursday, September 06, 2012 1:28 PM
What is the "||" supposed to mean? Logical "Or" is just that ... Or
You might also consider not basing the logic on the text but retrurn the value based on the selected index.
Please call me Frank :)
-
Thursday, September 06, 2012 1:36 PM
Using OR is only possible for boolean values/expressions. So what you can do instead:
If NOT (New String() {"September", "April", "June", "November"}).Contains(ComboMonth.Text ) Then ' 'Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marked As Answer by Kaya Suleyman Thursday, September 06, 2012 1:50 PM
-
Thursday, September 06, 2012 1:38 PMI think there is no other option to do this. you only use 'OR' keyword.
Art Of Living Is Art Of Giving
-
Thursday, September 06, 2012 1:40 PM
Something like this but using <> instead of =
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If TextBox1.Text = "September" OrElse TextBox1.Text = "October" OrElse TextBox1.Text = "November" Then Label1.Text = "Equals" & TextBox1.Text Else Label1.Text = "Not Equal" End If End SubYou've taught me everything I know but not everything you know.
- Marked As Answer by Kaya Suleyman Thursday, September 06, 2012 1:51 PM
-
Thursday, September 06, 2012 1:41 PM
hi,
this being a VB forum, this is also a possibility:
select case ComboMoth.Text case "September", "April", "June", "November" ' some code here case else ' some other code end select
Regards, Nico
- Marked As Answer by Kaya Suleyman Thursday, September 06, 2012 1:51 PM
-
Thursday, September 06, 2012 1:44 PM
Ok,
now you are mixing all together. You check if a string (ComboMonth.Text ) is unequal to a Boolean value ( your SelectedIndex... stuff). And also the SelectedIndex will return an Integer whereas you are comparing to a string.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ -
Thursday, September 06, 2012 1:44 PM
I read that i could substitute || for Or, since Or cannot read string's but only integers, but my source was infactual, as is clear to me now.
I agree with your suggestion, so i tried this:
If ComboMonth.Text <> ((ComboMonth.SelectedIndex = "8") 0r (ComboMonth.SelectedIndex = "3") or (ComboMonth.SelectedIndex = "5") or (ComboMonth.SelectedIndex = "10")) Then
However the error i recieve, which i cannot quiet understand, is :Error 1 ')' expected.
You misunderstood what I meant. Pseudocode here but something like this:
Dim userSelection As String = ComboBox1.Items(ComboBox1.SelectedIndex).ToString
If userSelection = "January" OrElse userSelection = "February" Then
' Do something
End IfPlease call me Frank :)
-
Thursday, September 06, 2012 1:50 PMThis link may be of assistance http://msdn.microsoft.com/en-US/library/asfcc119(v=vs.80)
You've taught me everything I know but not everything you know.
-
Thursday, September 06, 2012 1:51 PM
Thank you for everybody who went out of their way to put forward some great solutions for me.
I really appreciate this, enjoy the points!
Kaya

