Results 1 to 15 of 15

Thread: split function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86

    Resolved split function

    why doesn't this work

    VB Code:
    1. Private Sub Command1_Click()
    2. On Error Resume Next
    3. Text2.Text = Split(ophalen, "seta")(Text3.Text - 1)
    4. End Sub
    5.  
    6. Private Sub Form_Load()
    7. Dim ophalen As String
    8. Open "C:\Program Files\Call of Duty\Main\config_mp.cfg" For Input As #1
    9. Input #1, ophalen
    10. Text1.Text = ophalen
    11. Close #1
    12. End Sub

    and i have an other problem
    i want to split it with a gign that looks like an empty square
    if i copy it and paste than i begin the next rule

    how can i let cbscript know tht he must split it with this sign

    he must get info from this file

    http://www.davyquyo.be/config_mp.cfg

    but when i try he give error
    out of range
    because of the empty squares
    he only can read //generate by call of duty
    Last edited by davyquyo; Oct 4th, 2004 at 09:46 AM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: split function

    Originally posted by davyquyo
    why doesn't this work

    VB Code:
    1. Private Sub Command1_Click()
    2. On Error Resume Next
    3. [b]Text2.Text = Split(ophalen, "seta")(Text3.Text - 1)[/b]
    4. End Sub
    Highlighted line is not a valid syntax.
    Also, when some text is splitted it becomes an array of values "located" between that character that you're splitting on.
    Here is a quick sample for you:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. '==========================
    5. Dim strFile As String
    6. Dim varAllValues As String
    7. Dim MyValues() As String
    8. Dim i&
    9.  
    10.     'provide full and valid path and file name
    11.     strFile = "c:\temp\test.txt"
    12.     Open strFile For Input As #1
    13.         'load entire file into a string variable
    14.         varAllValues = Input(LOF(1), #1)
    15.     Close #1
    16.     'in my test file delimeter is a carriage return, so
    17.     'I will split string based on it
    18.     MyValues() = SplitStringOnDelimiter(varAllValues, vbNewLine)
    19.    
    20.     'you may now do anything you need to do with your data.
    21.     For i = 0 To UBound(MyValues) - 1 'this array is ZERO based
    22.         List1.AddItem MyValues(i)
    23.     Next i
    24.  
    25. End Sub
    26.  
    27. Public Function SplitStringOnDelimiter(varValues As Variant, _
    28.                                        varDelimiter As Variant) As Variant
    29.     SplitStringOnDelimiter = Split(varValues, varDelimiter, , vbTextCompare)
    30. End Function

  3. #3
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    eek.. what is this Rhino.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    rhino
    youre code shows now error but
    but there are no values in list box

    it's empty

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: split function

    Originally posted by davyquyo
    ... a gign that looks like an empty square ...
    This could be a NULL character Chr(0) or Carriage Return Chr(13) or Linefeed Chr(10) or combination of char 10+13 ...

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Originally posted by davyquyo
    rhino
    youre code shows now error but
    but there are no values in list box

    it's empty
    ??? That's just a sample for you that demonstrates HOW split() function works and NOT soomething that you can copy/paste. Be a little more creative in adapting someoneelse's code in your programs.

    Cheers

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    ok with chr(10) it worked

    so i'think i can move on now

    thanx a lot

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Originally posted by Deepak Sakpal
    eek.. what is this Rhino.
    I usually don't respond to such useless posts but I will in this case:

    OTHER THAN YEEEEEKING DO YOU HAVE TO OFFER ANYTHING AT ALL ???

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Originally posted by davyquyo
    ok with chr(10) it worked

    so i'think i can move on now

    thanx a lot
    No problem.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    Originally posted by RhinoBull
    ??? That's just a sample for you that demonstrates HOW split() function works and NOT soomething that you can copy/paste. Be a little more creative in adapting someoneelse's code in your programs.

    Cheers
    i did copy past so i can see how it workbut i will change it little by little so i can go on with what i want so
    i won't be using exactly the same script don't worry about that

    thanx for the help
    i appreciate it

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    only one little question

    how is this been written in vb "
    i want to replace this to something else but i know i can't say

    test=replace(ophalen, """, "something else")

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Sure ...
    Something like this will do the job:
    VB Code:
    1. Private Sub Command1_Click()
    2.    
    3.     MsgBox "Good Monday Morning!"
    4.     MsgBox StrConv(Replace(UCase("Good Monday Morning!"), "MONDAY", ""), vbProperCase)
    5.    
    6. End Sub

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    86
    no i

    i talking about this sign "

    how do i replace this

  14. #14
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Oh, sorry - it's a character 34 ... so here we go again:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strMsg$
    3.  
    4.     strMsg = "Hello " & Chr(34) & "davyquyo" & Chr(34)
    5.     MsgBox Replace(strMsg, Chr(34), "'")
    6.  
    7. End Sub

  15. #15

    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