locked
Error: Expression does not produce a value. RRS feed

  • Question

  • Hello all,

    I need your help. I have a problem of writing the code on if statement. I am trying to read the strings for the textbox from the classlibrary. What I am doing that when I input the strings in the textbox on the form, I want to check in the classlibrary whether if the strings is matched or not.

     

      Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        Dim c As New TestString.Strings
    
    
        If c.TestString(Textbox1) Then
          '....write the code here
        End If

     

    There is an error that are jumping on If c.TestString(Textbox1) Then statement. It suggests that I need to included the value which I doesn't want to write in the long code.

     

    Does anyone know a solve for this?

    Wednesday, September 15, 2010 12:53 AM

Answers

  • Hello Mark,

    You need to write a comparation funtion in the class to do the comparation which returns a True or False, otherwise a non-boolean value cannot be used as a condition in IF statement. You should write the class and form like this:

     In the class:

    Public Class TestString

        Dim sss As String = "aaabbbcccdddeeefffggg"

     

        Public Function StringMatch(ByVal txt As Windows.Forms.TextBox) As Boolean

            If sss.IndexOf(txt.Text) >= 0 Then

                Return True

            Else

                Return False

            End If

     

        End Function

    End Class

     

    In the form:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim c As New TestString

            If c.StringMatch(TextBox1) Then           //it should be a Boolean in the IF statement

                MessageBox.Show("I'm matched")

            Else

                MessageBox.Show("No")

            End If

        End Sub

    Sincerely,
    Helen Zhou


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Helen Zhou Monday, September 20, 2010 7:09 AM
    Wednesday, September 15, 2010 3:35 AM

  • If you only want the function to return true for strings that Start With "6.", "7.", or "11.", then do the following:
     
    Function String (ByVal s AsString) As Boolean
        Const Strings1 As String = "6."
        Const Strings2 As String = "7."
        Const Strings3 As String = "11."
     
        If s.StartsWith(Strings1) Then
            Return True
        ElseIf s.StartsWith(Strings2) Then
            Return True
        ElseIf s.StartsWith(Strings3) Then
            Return True
        End If
       
        Return False
    End Function

    --
    Mike
    • Marked as answer by Mark103 Sunday, September 19, 2010 12:05 PM
    Sunday, September 19, 2010 11:40 AM

All replies

  • Hello Mark,

    What is TestString? And what does this "c.TestString(Textbox1)" mean?

    Sincerely,
    Helen Zhou


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Wednesday, September 15, 2010 1:49 AM
  • Hello Helen,

    The TestString is actual name of the class in the classlibrary. And the c is a name of the property that I wish to read the strings in the classlibrary, like mystrings.dll.  So, I received an error on the if statement, which I am trying to read the whole strings in the dll. What I am trying to do, when I input the strings in the textbox on the form, click the button and check the strings in the classlibrary whether if they are matched or not.

     

     

    Please can you advice to correct the if statement that I have already wrote in my first post?

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 2:17 AM

  • You have declared the variable c to be of type TestString.Strings.  Do you have a method in the class TestString.Strings that accepts a textbox and returns a boolean confirming a match?  That method is what should be used in the if statement.

    --
    Mike
    Wednesday, September 15, 2010 2:24 AM

  • You have declared the variable c to be of type TestString.Strings.  Do you have a method in the class TestString.Strings that accepts a textbox and returns a boolean confirming a match?  That method is what should be used in the if statement.

    --
    Mike


    Yes, I do.

     

    Here it is:

    Imports System.Windows.Forms
    
    Public Class TestString
    
      Public Sub Strings(ByVal Strings As Windows.Forms.TextBox)
        Strings.Text = "this"
        Strings.Text = "is"
        Strings.Text = "test"
      End Sub
    End Class 

     

    And the form code:

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
      Dim c As New TestString.Strings

        If c.Strings(Textbox1) Then '....write the code here End If
    Wednesday, September 15, 2010 2:33 AM

  • No, reread my question.  You declared c as a type TestString.Strings.  You are now showing a method in a TestString class, named Strings.  Further, the method is a subroutine, so it could not be used in an If statement, as it does not return anthing to test.  Beyond that, the subroutine itself sets a textbox parameter sent into it to three different text values.  That doesn't seem too useful.

    --
    Mike
    Wednesday, September 15, 2010 2:41 AM
  • Look Mike, I am writin the longest strings which I have stored in the class, I doesn't want to write the strings in the project due too much to read on so thats why I prefer to read them on the class. I really need the if statement, because if I input the name of the strings in the textbox and if I click the button, I want the program to check the strings in the class whether if they have matched in the textbox or not...

     

    Please do not argue with me, even that method is my work and would like to use it in the class which will be very useful to work on it.

     

    Please advice me in which situation that I could use to check the strings in the class whether if the textbox have matched the strings in the class...

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 2:49 AM
  • Your Strings() method needs to be a function and needs to return a Boolean in order to be used in an If statement.

    So this:

    Public Sub Strings(ByVal Strings As Windows.Forms.TextBox)

    needs to be this instead:

    Public Function Strings(ByVal Strings As Windows.Forms.TextBox) As Boolean

    So now you need to write the code to perform the string matching and return either True or False. Do you need help with that code?

    Wednesday, September 15, 2010 3:19 AM
  • Hello Mark,

    You need to write a comparation funtion in the class to do the comparation which returns a True or False, otherwise a non-boolean value cannot be used as a condition in IF statement. You should write the class and form like this:

     In the class:

    Public Class TestString

        Dim sss As String = "aaabbbcccdddeeefffggg"

     

        Public Function StringMatch(ByVal txt As Windows.Forms.TextBox) As Boolean

            If sss.IndexOf(txt.Text) >= 0 Then

                Return True

            Else

                Return False

            End If

     

        End Function

    End Class

     

    In the form:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim c As New TestString

            If c.StringMatch(TextBox1) Then           //it should be a Boolean in the IF statement

                MessageBox.Show("I'm matched")

            Else

                MessageBox.Show("No")

            End If

        End Sub

    Sincerely,
    Helen Zhou


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Helen Zhou Monday, September 20, 2010 7:09 AM
    Wednesday, September 15, 2010 3:35 AM
  • Hi Mark -

    What is the Strings method supposed to do? Set the strings into the textbox? Or check the strings from the TextBox?

    In either case, this declaration:

    Dim c As New TestString.Strings

    Should be this:

    Dim c As New TestString

    Use the class name. Then you call the method as you have in your code: c.Strings(TextBox1).

    Hope this helps get you started.

     


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Wednesday, September 15, 2010 4:05 AM
  • Hi Helen,

    Thanks for this, so that is what I wanted. How about if I could use the same name of the strings to add more than one?

     

    As I want to store the strings like this:

     

       sss.Text = "strings 1" 
    sss.Text = "strings 2"
          sss.Text = "strings 3"
          sss.Text = "strings 4"
          sss.Text = "strings 5"
          sss.Text = "strings 6"
          sss.Text = "strings 7" 'etc...

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 3:06 PM
  • Why not just make them constants:

    private const myFirstString As string = "strings 1"
    private const mySecondString As string = "strings 2"


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Wednesday, September 15, 2010 3:23 PM
  • Thanks Deborah, last things I needs your help with the strings. I have input the strings something like private const strings1 As String = "6.". When I input the text in the textbox which something is like "6.11" and so on, it doesn't returns as true. It will returns as true if I input "6." then it will returns as true. I want the strings returns as true, because I have input in the first two letters which it is "6.", so whatever I input that come after "6." will returns as true. As I find it too much to write on the list of the code and it may take me hours to complete, so I have no reason to do a different way to save me the time of writing the shorter but much easy way.

     

    How I can set the strings returns as true when I input "6." or that come after??

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 4:02 PM
  • Hi Mark -

    We seem to be struggling a bit understanding what you are trying to do. Are you trying to validate your entered text to ensure that there is a value after the decimal place?

    If so, there is a validating event you can use:

      Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        ' Divide the contents of the textbox by the "."
        Dim a() As String = TextBox1.Text.Split("."c)
        If a.Length < 2 OrElse String.IsNullOrWhiteSpace(a(1)) Then
          MessageBox.Show("Please enter a value after the decimal place")
        End If
      End Sub
    
    NOTE: This does not ensure that the values are numbers, just that there is an entry after the ".".

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Wednesday, September 15, 2010 4:15 PM
  • Thanks degorah, but there is an error that I can see IsNullOrWhiteSpace is not a member of String. So what property that I should change it to?

     

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 4:29 PM
  • IsNullOrWhiteSpace is in VS 2010. What version do you have?

    Try this instead: IsNullOrEmpty

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Marked as answer by Mark103 Wednesday, September 15, 2010 4:39 PM
    • Unmarked as answer by Mark103 Wednesday, September 15, 2010 4:50 PM
    Wednesday, September 15, 2010 4:35 PM
  • Oh, thanks for this. I am using as VS 2005 as the current version. I do not wish to upgrade at this present moment. Anyway, thanks for your advice, problem solved!
    Wednesday, September 15, 2010 4:39 PM
  • Oh sorry Deborah, I have forgot to ask you a earlier question: How can I check the strings in the class when I I have input the strings in the textbox, something like "6.", "6.11" and so on...

     

    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 Teststring
    
        If c.TestString(Textbox1) Then
          Timer1.Interval = 500
          Timer1.Start()
        Else
          MessageBox.Show("the string is not in the class")
          Timer1.Stop()
        End If
      End Sub

    As my code on above, it doesn't check the strings in the class when I click on the button which it displaying the messagebox without checking the strings in the class. I know that the strings are in the class which it does exist. I hope that it will returns as true if I input "6." or whatever I input that come after "6.11" then returns as true.

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 4:57 PM
  • Sorry Mark, but I *really* don't get what you are trying to do.

    Here is how I am reading your code:

    1) Create an instance of a class called Teststring.

    2) Call a method of the Teststring class, also called TestString. (It is normally a bad idea to name your class and a method in that class the same thing.)

    3) If the return value from the TestString method is true, start a timer.

    4) If the return value from the TestString method is false, display a message and stop the timer.

    I don't see any code that is checking the value of your string. Is that what is in the TestString method from the TestString class?

     


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Wednesday, September 15, 2010 5:13 PM
  • Well, what I am trying to do is to call the class called Teststring, check the strings whether if it matched then start the timer, otherwise if the strings in the class doesn't match then show the messagebox.

     

    Hope you get this.

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 5:18 PM
  • Well, what I am trying to do is to call the class called Teststring, check the strings whether if it matched then start the timer, otherwise if the strings in the class doesn't match then show the messagebox.

     

    Hope you get this.

     

    Thanks,
    Mark

    Wednesday, September 15, 2010 10:06 PM
  • The code you posted is creating a new instance of the TestString object each time the button1 is clicked.  You likely need to keep a single instance around so the list is remembered over each button click.
     
    This is a console application, but it illustrates a solution to what I think you are describing.  Can you look at this and see if it helps, or if not, let me know why not?
     
    Module Module1
     Public Class TestString
      Private _strings As New List(Of String)
      Public Sub AddString(ByVal s As String)
       _strings.Add(s)
      End Sub
      Public Function TestString(ByVal s As String) As Boolean
       If (_strings.IndexOf(s) <> -1) Then Return True
       Return False
      End Function
     End Class

        Sub Main()
      Dim ts As New TestString
     
      ts.AddString("string1")
      ts.AddString("string2")
      ts.AddString("string3")
     
      If (ts.TestString("string2")) Then
       Console.WriteLine("Starting timer.")
      Else
       Console.WriteLine("Stopping timer.")
      End If
     
      Console.ReadKey()
        End Sub
     
    End Module

    --
    Mike
    Wednesday, September 15, 2010 10:26 PM
  • Thanks mike, but I want to use it in the class library only. So, please can you help me as I have a problem with the code. When I input the strings in the textbox, something like "6.11" which it come after the strings I have stored in the class which it is "6.".

     

    When I click on the button, it doesn't read the strings through in the class library. It just went pass and displaying the messagebox. All I want to read the strings in the class and catch it even if I input the text in the textbox which come after "6.", for e.g: I have stored the strings in the class which it is "6.", so I input each random strings in the textbox "6.11.11.11", "6.21.21", "6.156"...etc. Then read the strings in the class and displaying the messagebox thats says the strings is matched (because it still showing the same value of 6. even not 7.).

     

    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 Teststring
    
     If c.TestString(Textbox1) Then
     Timer1.Interval = 15000 
          Timer1.Start() Else MessageBox.Show("the string is not in the class") Timer1.Stop() End If End Sub

     

    I don't really know why it went pass after I have stored the strings in the class. I believes that it would only read the strings in the class if I have store the whole values which it will be too much to do so. I want to use a different way which it will be much quicker and easy to use than writing in the longest list.



    Hope you can help!

     

    Thanks,
    Mark

    Thursday, September 16, 2010 12:09 AM
  • I think I'm joining the others that are confused about your goal, but let me try this...
     
    When you say you have "Stored the strings in the class", what does that mean?  Can you give a code example of how you have done that? 
     
    Also, you say you input "...a random string such as "6.11.11.11", but it is still showing the same value of 6. even not 7.)".  To me, this indicates you might be converting from a string to a numeric value.  If so, then it seems the conversion is being done strangly, as "6.11.11.11" is not a value that can be converted to a numeric without some strange process.

    --
    Mike
    Thursday, September 16, 2010 12:33 AM
  • Sorry for the confusion Mike, but my goal is that I want to checking the value between the textbox and in the class that are "6." and that coming after "6." which it would be like this "6.11.11.11". If numeric value could do the method for me then yes I want to converting them.


    Thanks,
    Mark
    Thursday, September 16, 2010 1:20 AM
  • If you have a string variable s = "6." and another string variable t = "6.11.11.11", then t will be greater than s, or larger as you put it.  The only thing that I can guess is you have a coding problem in TestClass, which you have not posted.

    --
    Mike
    Thursday, September 16, 2010 1:50 AM
  • Oh sorry about that, here it is:

     

    Imports System.Windows.Forms

    Public Class TestClass
    Public Function TestStrings(ByVal txt As Windows.Forms.TextBox) As Boolean Const Strings1 As String = "6." Const Strings2 As String = "7." Const Strings3 As String = "11." If Strings1.IndexOf(txt.Text) >= 0 Then Return True ElseIf Strings2.IndexOf(txt.Text) >= 0 Then Return True ElseIf Strings3.IndexOf(txt.Text) >= 0 Then Return True End if End Sub
    End Class

     

    If you are confused why I have input the "6." in the class without using the strings like "6.11.11.11", then I want you to be awake that I want to reads the "6." in the class even if the textbox have greater than the strings in the class.

     

    Thanks,
    Mark

    Thursday, September 16, 2010 4:20 PM

  • Your function "TestClass" will return true only if the string in the textbox is a part of one of the three strings, "6.", "7.", and "11.".  In other words, the string "6.11.11.11", when passed into the function, will return false, because it is not "inside" any of the three listed strings.  Passing in a string of "6." would return true, but also passing in a string of "." would pass, as it is inside of the Strings1.
     
    I am still not 100% sure what you want the function to return for 6.11.11.11, so if you provide a list of strings, and whether they should return true or false, we should be able to address any code fixes that would be needed.

    --
    Mike
    Thursday, September 16, 2010 9:36 PM
  • Yeah I know that, so how I can make it returns as true when reading the strings in the class ("6.") while the textbox strings has something like "6.11.11.11", so how I can make it returns as true when reading them with the strings in the class?

    I want it returns as true, because "6. 11.11.11" has first two letters of the strings which it has "6. " while the strings in the class has "6. ".

    I hope I can set the strings to returns as true which has few letters while matched with the strings in the class. Perhaps if I should use integer method or something else that could work rather than writing in the longest list.

     

    Thanks,
    Mark

    Friday, September 17, 2010 12:19 AM
  • If that is what you want, then I believe that you have your checks backwards.  You should be testing s.IndexOf(Strings1), for example.  Try this version of the function:
     
     Function test(ByVal s As String) As Boolean
      Const Strings1 As String = "6."
      Const Strings2 As String = "7."
      Const Strings3 As String = "11."
     

      If s.IndexOf(Strings1) >= 0 Then
       Return True
      ElseIf s.IndexOf(Strings2) >= 0 Then
       Return True
      ElseIf s.IndexOf(Strings3) >= 0 Then
       Return True
      End If
     End Function

     

    --
    Mike
    Friday, September 17, 2010 12:31 AM
  • Thanks Mike, and last things I need before it will resolve. I have a little problem with this code, when I click on the button as I have input the strings in the textbox which it aren't in the class, so it should displaying the messagebox that says the strings is not found but it reads the strings straight through in the class and displaying the messagebox that says the strings is found which it isn't.

     

    So in what proper method that I should use to check if the strings is listing in the class then display the messagebox that says the strings is found, otherwise display the messagebox that the strings is not found.

     

    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 TestString.Strings
    
        If Not c.Strings(Textbox1.Text) Then
          MessageBox.Show("strings not found")
        Else
          Dim a() As String = TextBox1.Text.Split("."c)
          If a.Length < 2 OrElse String.IsNullOrEmpty(a(1)) Then
            MessageBox.Show("strings found!")
          End If
        End If

    Friday, September 17, 2010 1:50 AM
  • You have changed from the function TestStrings(txt as Textbox) that was in a class TestClass, to using a function Strings in a class called TestString.Strings.  I am going to assume that these are identical.  If they are not, I don't know why you changed.
     
    Your code looks like it is correct.  Here is a complete console application that illustrates the two pieces of code. 
     
    If this application shows an error in your mind, let me know what the error is.
     
    Namespace TestString
        Public Class Strings
            ' returns true if the string contains "6.", "7." or "11."
            Function Strings(ByVal s As String) As Boolean
                Const Strings1 As String = "6."
                Const Strings2 As String = "7."
                Const Strings3 As String = "11."
     

                If s.IndexOf(Strings1) >= 0 Then
                    Return True
                ElseIf s.IndexOf(Strings2) >= 0 Then
                    Return True
                ElseIf s.IndexOf(Strings3) >= 0 Then
                    Return True
                End If
                Return False
            End Function
        End Class
    End Namespace
    Module Module1
        Sub Main()
            Dim tests = New String() {"6.11.11.11", "7.", "4"}
            For Each s As String In tests
                Console.WriteLine(s)
                Dim c As New TestString.Strings
     
                If Not c.Strings(s) Then
                    Console.WriteLine("strings not found")
                Else
                    Dim a() As String = s.Split("."c)
                    If a.Length < 2 OrElse String.IsNullOrEmpty(a(1)) Then
                        Console.WriteLine("strings found!")
                    Else
                        Console.WriteLine("Strings found, but a.length is wrong.")
                    End If
                End If
            Next
            Console.ReadKey()
        End Sub
     
    End Module

     

    --
    Mike
    Friday, September 17, 2010 2:23 AM
  • Thanks mike, but it doesn't help me there. It still showing the messagebox that says the strings is found when I input a random strings that doesn't exist in the class, like "22.22.22" and whatever I input in the textbox without input "6.", "7." and "11.". I need to check the matched strings correctly, like when I input the strings "6.11.11.11 or whatever I input after with "6.", it is the same for "7. and "11.", so if the strings is unmatched then displaying the messagebox that says it does not match.

     

    On the code you have post, it is still the same by displaying the messagebox that says the strings is found when the strings in the class doesn't exist.

     

    Any idea?

    Friday, September 17, 2010 2:41 PM

  • The code I posted in my last post, at 10:23 PM East coast US time on Thursday, returns false for the string "22.22.22", yet you say you got a return value of true.  I don't know how to help you further, because there must be something different in what you are running.

    --
    Mike
    Friday, September 17, 2010 9:08 PM
  • Well I want the returns value as true or false. If I input the strings in the textbox something like this: "22.22.22.22", "142.22.22.22" which it is "22.22" and "142.22", so the strings in the class has strings that are "6.", "7." and "11." which it doesn't matched so it should returns the value as false. So, if I input the strings in the textbox like "6.11.11.11", "7.11.11.11" and "11.22.22.22" then the value should returns as true, because the strings in the class has "6.", "7." and "11.".

     

    That's what I am doing to check the strings that are matched and if it doesn't matched.

     

    Hope you understand what I am trying to do.

     

    Hope you can help

     

    Thanks,
    Mark

    Saturday, September 18, 2010 3:40 PM

  • When I run the last posted code with "6.11.11.11", "7.11.11.11", "11.22.22.22", I get a return value of true, but, it falls into the code section checking whether the number of parts is more than one.  This means I get the message ""Strings found, but a.length is wrong."

    --
    Mike
    Saturday, September 18, 2010 3:49 PM
  • Ok so what do we needs to change with a.length?
    Saturday, September 18, 2010 4:04 PM

  • Well, why did you put the test in your code in the first place?  Below is your version, which I just modified to make sure there were messages output.  It looks like you wanted to treat those cases where there was a "." in the input differently.  What did you want to do in those cases?
     
        If Not c.Strings(Textbox1.Text) Then
          MessageBox.Show("strings not found")
        Else
          Dim a() As String = TextBox1.Text.Split("."c)
          If a.Length < 2 OrElse String.IsNullOrEmpty(a(1)) Then
            MessageBox.Show("strings found!")
          End If
        End If
     

    --
    Mike
    • Marked as answer by Mark103 Sunday, September 19, 2010 1:29 AM
    • Unmarked as answer by Mark103 Sunday, September 19, 2010 12:05 PM
    Saturday, September 18, 2010 4:13 PM
  • Thanks mike, but I did not get a returns value as true when I input "6.11.11.11", "7.11.11.11", "11.22.22.22" in the textbox. So I have changed this:

     

    Dim c As New TestStrings.Strings
    
    
        If Not c.Strings(Textbox1.Text) Then
          MessageBox.Show("strings not found")
        Else
          Dim a() As String = Textbox1.Text.Split(".", "."c)
          If a.Length < 6 OrElse String.IsNullOrEmpty(a(2)) Then
            MessageBox.Show("strings found!")
          End If
        End If

    I have input the strings of "6.11.11.11" in the textbox, I got a returns value as true, BUT I have tried a different strings of "143.11.11.11" which the strings of "143.11" are not in the class, I got a returns value as true. I think you are confused there and doesn't really understand what I am trying to do. I think it taking me the ____ out of it.

     

    Here it is what I am trying to do:

    Input the strings of "6.11.11.11" in the textbox.

    Read the strings in the class and look for "6."

    If it found, returns the value as true.

    Input a different strings of "153.11.11.11"

    Read the strings in the class and look for "153.11"

    If it not found, returns the value as false.

     

    Now you got this?

    Sunday, September 19, 2010 1:01 AM

  • 143.11.11.11 matches the 11. part of this function, which to the best of my knowledge is what you are using.  This is why you get "true" for 143.11.11.11.
     
            Function Strings(ByVal s As String) As Boolean
                Const Strings1 As String = "6."
                Const Strings2 As String = "7."
                Const Strings3 As String = "11."
     

                If s.IndexOf(Strings1) >= 0 Then
                    Return True
                ElseIf s.IndexOf(Strings2) >= 0 Then
                    Return True
                ElseIf s.IndexOf(Strings3) >= 0 Then
                    Return True
                End If
                Return False
            End Function
     

    --
    Mike
    Sunday, September 19, 2010 1:33 AM

  • If you only want the function to return true for strings that Start With "6.", "7.", or "11.", then do the following:
     
    Function String (ByVal s AsString) As Boolean
        Const Strings1 As String = "6."
        Const Strings2 As String = "7."
        Const Strings3 As String = "11."
     
        If s.StartsWith(Strings1) Then
            Return True
        ElseIf s.StartsWith(Strings2) Then
            Return True
        ElseIf s.StartsWith(Strings3) Then
            Return True
        End If
       
        Return False
    End Function

    --
    Mike
    • Marked as answer by Mark103 Sunday, September 19, 2010 12:05 PM
    Sunday, September 19, 2010 11:40 AM
  • Thanks Mike, we have found the solution for my needs. Thanks for your help!
    Sunday, September 19, 2010 12:06 PM
  • Sorry it took so long.  I just did not realize you might have wanted only the strings starting with the items in your class until this morning.
     

    --
    Mike
    Sunday, September 19, 2010 12:12 PM