dcsimg
Results 1 to 12 of 12

Thread: [RESOLVED] VB6 string separation, Left, Mid,Right?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    27

    Resolved [RESOLVED] VB6 string separation, Left, Mid,Right?

    Hi,


    I have a string:
    MyString = "falsetruefalsefalsefalsetruefalsefalsetruefalsetruetruefalsetrue"
    which can change from true to false or viceversa depending on a selection.
    How can I use the functions left, mid, etc to retrive the 1st word in this case false, then 2nd word true and so on until the last word and taking into account that the words could change from true to false or remain de same depending on a selection?
    I have tried on a form with:
    Code:
    MyString = "falsetruefalsefalsefalsetruefalsefalsetruefalsetruetruefalsetrue"
        Form1.Print Left(StrProducts, 1)
        Form1.Print Mid(StrProducts, 2, 1)
        Form1.Print Mid(StrProducts, 3, 1)
        Form1.Print Mid(StrProducts, 4, 1)
        Form1.Print Mid(StrProducts, 5, 1)
        Form1.Print Mid(StrProducts, 6, 1)
        Form1.Print Mid(StrProducts, 7, 1)
        Form1.Print Mid(StrProducts, 8, 1)
        Form1.Print Mid(StrProducts, 9, 1)
        Form1.Print Mid(StrProducts, 10, 1)
        Form1.Print Mid(StrProducts, 11, 1)
        Form1.Print Mid(StrProducts, 12, 1)
        Form1.Print Mid(StrProducts, 13, 1)
        Form1.Print Mid(StrProducts, 14, 1)
    but got nowhere

    thanks

    luta

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,510

    Re: VB6 string separation, Left, Mid,Right?

    there is no good way... not with that string... it would have been better to at least have some kind of delimiter between each one, like a space or a pipe, comma, ANYTHING, then you could use the split() command...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    27

    Re: VB6 string separation, Left, Mid,Right?

    Ok, say that I put a delimitar between each word or space how would I use the split() command?
    MyString = "false true false false false true false false true false true true false true"
    Sorry give me an example as I am not familiar with the split()command.

    Thanks
    luta

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,510

    Re: VB6 string separation, Left, Mid,Right?

    Code:
    Dim mySettings() as string
    
    mySettings = Split(myString, " ")
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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

    Re: VB6 string separation, Left, Mid,Right?

    It all depends on context.
    What is the meaning of this string?
    Where does it come from?
    What could it possibly contain?

    Will it only contain "true" and "false" and nothing else?
    In that case "e" can be your delimiter.

    Using a seperate delimiter would be needed if it can contain other things and would be a better overall method.

    Another option is to run a replace to turn all "false" into "f" and all "true" into "t" and then work the string per character.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    27

    Re: VB6 string separation, Left, Mid,Right?

    with the above code, I get a type mismatch error.

    thanks
    luta

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    27

    Re: VB6 string separation, Left, Mid,Right?

    it only contain true and false, nothing else.

    luta

  8. #8
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: VB6 string separation, Left, Mid,Right?

    Try splitting on the letter e. Then adding an e onto the end of each.

  9. #9
    Member
    Join Date
    Jul 2007
    Posts
    51

    Re: VB6 string separation, Left, Mid,Right?

    Yeah, I would use array for this one.
    Code:
    string= "false,true,false,true,bla,bla,bla" ' one string
    splited = Split(string,",") ' becames now array
    splited(0) = "false" ' counter starts with zero
    splited(6) = "bla"' ' and in this case it ends with 6
    You should study about Split(), Join() and Array() functions
    my suggestion
    Last edited by RapidBuster; Oct 8th, 2007 at 06:08 PM.

  10. #10
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: VB6 string separation, Left, Mid,Right?

    I still think my method is better... *grins* Lol.
    Code:
    Private Sub Form_Load()
    Dim str As String
    Dim myarr() As String
    Dim i As Integer
    
    str = "falsetruefalsefalsefalsetruefalsefalsetruefalsetruetruefalsetrue"
    myarr = Split(str, "e")
    
    For i = 0 To (UBound(myarr) - 1)
    myarr(i) = myarr(i) & "e"
    Next i
    
    For i = 0 To UBound(myarr)
    Debug.Print myarr(i)
    Next i
    
    End Sub

  11. #11
    Member
    Join Date
    Jul 2007
    Posts
    51

    Re: VB6 string separation, Left, Mid,Right?

    You might have point but I don't like that code...

  12. #12
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: VB6 string separation, Left, Mid,Right?

    Unfortunately the list of true and false, is not separated by commas and so your code will not work.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width