Results 1 to 11 of 11

Thread: String Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    String Help

    HI guy

    I need some help here what my problem

    i have a set of number in the following formats

    A) 1,2,3,4,5,6,7,8,9,10,12,20,22,23,24,25
    or
    b) 1 2 3 4 5 6 7 8 9 10 12 20 22 23 24 25


    Then i got a string in a text box this string must contain either one or more number that can be found in either A or B.

    i need some way to check this in VB 6 Please help me.

    Thank you
    Attached Images Attached Images  
    Last edited by andrnet2004; May 30th, 2006 at 09:00 PM.

  2. #2
    Lively Member
    Join Date
    Oct 2004
    Posts
    91

    Re: String Help

    Hmm, im not opening VB here or anything, but an obvious (but slow) way to find out would be to set an array with all the search numbers with one element per number, then check them against the master string to see if they are in it. For example, if you would like to know if 15 is in the list then if InStr(0, txtMaster.text, "15", vbTextCompare) <> 0 then it exists. Hoever be careful, because that will recognize 15 even if it is 150.

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: String Help

    VB Code:
    1. Dim NumberA() As String
    2. Dim NumberB() As String
    3. Dim Found() As Boolean
    4. Dim AnyFound As Boolean
    5.  
    6. TextA.Text = Replace(TextA.Text, " ", ",")
    7. NumberA = Split(TextA.Text, ",")
    8.  
    9. TextB.Text = Replace(TextB.Text, " ", ",")
    10. NumberB = Split(TextB.Text, ",")
    11.  
    12. Redim Found(UBound(NumberB)) As Boolean
    13.  
    14. For i = 0 To UBound(NumberB)
    15.   For j = 0 To UBound(NumberA)
    16.     If Val(NumberB(i)) = Val(NumberA(j)) Then
    17.       Found(i) = True
    18.       AnyFound = True
    19.     End If
    20.   Next j
    21. Next i

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    Re: String Help

    Quote Originally Posted by jeroen79
    VB Code:
    1. Dim NumberA() As String
    2. Dim NumberB() As String
    3. Dim Found() As Boolean
    4. Dim AnyFound As Boolean
    5.  
    6. TextA.Text = Replace(TextA.Text, " ", ",")
    7. NumberA = Split(TextA.Text, ",")
    8.  
    9. TextB.Text = Replace(TextB.Text, " ", ",")
    10. NumberB = Split(TextB.Text, ",")
    11.  
    12. Redim Found(UBound(NumberB)) As Boolean
    13.  
    14. For i = 0 To UBound(NumberB)
    15.   For j = 0 To UBound(NumberA)
    16.     If Val(NumberB(i)) = Val(NumberA(j)) Then
    17.       Found(i) = True
    18.       AnyFound = True
    19.     End If
    20.   Next j
    21. Next i
    please help me a little more not too good at this

  5. #5
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: String Help

    All you need two textboxes, named NumbersA and NumbersB.
    NumbersA will contain the long list of numbers.
    NumbersB will contain the short list of numbers, which will be looked for in NumbersA.

    AnyFound will be true if any numbers in NumbersB are found in NumbersA.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    Re: String Help

    Hi

    i would like when it does not have one or more number message must pop up and say does not contain or if it contain a number that the long does not has message box pop and say does not contain.


    Plese help me
    Attached Images Attached Images  
    Last edited by andrnet2004; May 30th, 2006 at 11:18 PM.

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: String Help

    You can also add space to the beginning and end of the temp copy of the long string

    That way you only have to loop fewer times and check the long string with If InStr(1, " " & longstr & " ", " " & Nums(arrayindex) & " ") > 0

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    Re: String Help

    Guy Guy

    Thank for the help but i do not know if you got what i mean i know you got most of it.


    What is my main aim is that i has a text box with lot number like 1,2,3,4,5,10,12,14 (master text box)

    and i want a to check a second text box that contain number too again the first text box(master text box).

    if the second text does not contain one or more number then i want a message to popup.

    if it find some number in the second box that does not contain in the first box(master) message box much pop up

  9. #9
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: String Help

    Your looping through the numbers in your short "nums to check" string, right?

    Everytime you determine that the number is not in the long list (through my implementation or jeroen79's) then you append this number to a string named as strErrNums.

    strErrNums = strErrNums & "," & YourNumArray(currentIndex)

    Later on, if Len(strErrNums) > 0 then there was an error. Prompt that to the user.

    MsgBox "Wrong Input!! The numbers " & strErrNum & " are not in the master list"

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    17

    Re: String Help

    Can you please write the code for me.

    Thank you

  11. #11
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: String Help

    andrnet2004 , writing the code for you might not be much of a problem. I am assuming you are new to programming or vb. That being the case you won't be learning much if we write the code for you. Post the code that you have written, then people here will let you know what modifications need to be made. That way you will be able to learn better and more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width