Results 1 to 12 of 12

Thread: search a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Resolved search a string

    search a string

    i creatied thsi code
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim ophalen As String
    3. Dim tekst1 As String
    4. Dim tekst2 As String
    5. Dim splitter As String
    6. Open "c:/program files/call of duty/main/config_mp.cfg" For Input As #1
    7. ophalen = Input(LOF(1), #1)
    8. Close #1
    9. For i = 0 To 200
    10. splitter = Split(ophalen, Chr(10))(i)
    11. [COLOR=red]
    12. if spitter.    = "seta name" then
    13. stop the i
    14. tekst1 = Replace(splitter, "seta name", "")
    15. tekst2 = Replace(tekst1, Chr(34), "")
    16. Text2.Text = tekst2
    17. Else
    18. Next i
    19. End If
    20. [/COLOR]
    21. End Sub

    there are error's offcourse
    the red part shows an if i want to detect the if or the first 9 character = "seta name"

    if not go to next i and else stop the loop
    i already know that there are more characters present in this part

    hope someone can help me with that part
    Last edited by davyquyo; Oct 4th, 2004 at 10:58 AM.

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Use the InStr() function, it'll return 0 if the string wasn't found, and the position of the search string if found.

    An example of its usage:

    VB Code:
    1. Dim sString As String
    2.  
    3. sString = "The life of the wife, was ended by the knife"
    4.  
    5. 'InStr syntax: InStr(Starting point in string, String to search, String to search for)
    6. If InStr(0, sString, "knife") > 0 Then
    7.  MsgBox "There's a knife in the string!"
    8. End If
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    ok and how can i stop the loop

  4. #4
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    I believe 'Exit' does the trick... You could use a GoTo statement, though that is rather messy.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    For i = 0 To 200
    splitter = Split(ophalen, Chr(10))(i)
    If InStr(0, splitter, "seta name") > 0 Then
    exit i
    MsgBox splitter
    tekst1 = Replace(splitter, "seta name", "")
    tekst2 = Replace(tekst1, Chr(34), "")
    Text2.Text = tekst2
    Else
    Next i


    ok when i test it say
    next without loop

    and exit is wrong to

  6. #6
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Please remember to format your code... You have an open If statement:

    VB Code:
    1. For i = 0 To 200
    2.  splitter = Split(ophalen, Chr(10))(i)
    3.  If InStr(0, splitter, "seta name") > 0 Then
    4.   MsgBox splitter
    5.   tekst1 = Replace(splitter, "seta name", "")
    6.   tekst2 = Replace(tekst1, Chr(34), "")
    7.   Text2.Text = tekst2
    8.   Exit For
    9.  Else
    10.   'Do Nothing
    11.  End If
    12. Next

    Try this out, if it doesn't work, play with it - else do a forum search... You gotta be more active if you want problems solved, you need to take on affairs yourself...
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    If InStr(0, splitter, "seta name") > 0 Then

    with this he says

    invalid call or arument

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    ok If InStr(1, splitter, "seta name", vbTextCompare) > 0 Then

    this did the trick

    it's alright

  9. #9
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    That's my bad, change '0' to '1' since a string doesn't have a 0 caracter... This, however, you should've been able to figure out yourself, just goes to show you didn't try any other options...
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    i search on google for the answer but i find always more complicated scripts
    so i ask here to

    i realy try but i don't know so much about vb i'm a flashscrpter but i need a program to run local for my website

    that's why i'm using vb for

  11. #11
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    This board has a very advanced search function, right here:

    http://www.vbforums.com/search.php?s=

    Since the post archives are constantly growing, and are very big at the moment, you should be able to find the code blocks you need.

    If your code is working as it should, please make this thread resolved - if you don't know how, look at the announcement in one of the forum sections.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    ok thanx

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