I am writing the code in the class to create the strings. I want the value to returns as true if the strings in the class are matched with two numbers or more, but if the if the strings in the class are not matched with first two numbers or not then returns the value as false.
Here it is the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c As New TestStrings.Strings
If Not c.Strings(Textbox1.Text) Then
MessageBox.Show("strings not found")
Dim a() As String = Textbox1.Text.Split(".", "."c)
If a.Length < 6 OrElse String.IsNullOrEmpty(a(2)) Then
And the strings in the class.
Function Strings(ByVal s As String) As Boolean
Const Strings1 As String = "6."
Const Strings2 As String = "7."
Const Strings3 As String = "11."
Const Strings4 As String = "142.15"
If s.IndexOf(Strings1) >= 0 Then
ElseIf s.IndexOf(Strings2) >= 0 Then
ElseIf s.IndexOf(Strings3) >= 0 Then
ElseIf s.IndexOf(Strings4) >= 0 Then
What I am trying to do: input the strings in the textbox "22.214.171.124" and check the strings in the class, if the strings is matched in the class by "6." then displaying the messagebox that says the strings is found. Input the different strings in the textbox like "126.96.36.199" and check the strings in the class, if the strings in the class is not found by the first few two numbers or more, then displaying the messagebox that says the strings is not found.
When I clicked the button by input the strings in the textbox "188.8.131.52", it returns the value as true, but when I input the strings in the textbox "184.108.40.206" which it does not exist in the class, it returns the value as true which it should returns as false.
sounds like you need to test all of them before you return a true value and retunr false if any fail.
In each if else you should check to see if the value is not there and if so then return false then at the bottom return true which will only execute when all of the strings are found.
You could also create a boolean var defaulted to True at the top and set it to False if any item is not found then at the bottom return the boolean var which would give you just one exit point rather than the 5 you now have.
btw the way it is currently coded 67537342623478611.234786542 would be true as it contains 11.
Yep upon looking again testing to see if all of them were there would not work as your samples contain 3 sets of 11 and not all of the numbers there.
Best bet is to split the string on the . and check each element of the resulting array to see if the value is valid according to your needs. Then only if ALL elements are valid should you return true otherwise you would return false.