Results 1 to 8 of 8

Thread: [RESOLVED] String manipulation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Resolved [RESOLVED] String manipulation

    The code below is suppose to separate each pair of long and lat. It works fine apart from the last pair.

    Plots textbox = 501918N 0053042W - 502400N 0053900W - 503200N 0053400W - 503930N 0052400W - 504300N 0051230W - 503830N 0050430W - 501918N 0053042W

    VB Code:
    1. Plots = Plots & " - "
    2. NoPts = NoPts - 1
    3.  
    4. For i = 0 To NoPts
    5.     PosN = InStr(1, Plots, "-")
    6.     Points(i) = Left$(Plots, PosN - 2)
    7.    
    8.     Length = Len(Plots)
    9.     Plots = Right$(Plots, Length - (PosN + 1))
    10. Next i

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: String manipulation

    Why not just Split the string into an array? Split on the "-" char. then loop through the array reading each pair.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Re: String manipulation

    Sorry it does work it was my mistake for some reason there was a return at the end of the string in the textbox!

    How would you do that spilt rob? Would it be better

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: String manipulation

    Do you also need to separate the two coordinates?

    Yes, split is better.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Re: String manipulation

    yea so I have a list like

    501918N
    0053042W
    502400N
    0053900W
    503200N
    0053400W
    503930N
    0052400W
    504300N
    0051230W
    503830N
    0050430W
    501918N
    0053042W

  6. #6
    New Member
    Join Date
    Jan 2006
    Posts
    4

    Re: String manipulation

    Code:
    Dim myArray() As String
    Dim sString As String
    sString = "501918N 0053042W - 502400N 0053900W - 503200N 0053400W - 503930N 0052400W - 504300N 0051230W - 503830N 0050430W - 501918N 0053042W"
    
    myArray = Split(sString, "-")
    
    MsgBox myArray(1)
    This wil give you what you want.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: String manipulation

    Here is for them together.
    VB Code:
    1. Option Explicit
    2. 'Text2 is a multi-line textbox...
    3. Private Sub Command1_Click()
    4.     Dim ar() As String
    5.     Dim i As Integer
    6.     Text1.Text = "501918N 0053042W - 502400N 0053900W - 503200N 0053400W - 503930N 0052400W - 504300N 0051230W - 503830N 0050430W - 501918N 0053042W"
    7.     ar = Split(Text1.Text, "-")
    8.     For i = 1 To UBound(ar)
    9.         Text2.Text = Text2.Text & ar(i) & vbNewLine
    10.     Next
    11.     Erase ar
    12. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: String manipulation

    And here is separated.
    VB Code:
    1. Option Explicit
    2. 'Text2 is a multi-line textbox...
    3. Private Sub Command1_Click()
    4.     Dim ar() As String
    5.     Dim i As Integer
    6.     Text1.Text = "501918N 0053042W - 502400N 0053900W - 503200N 0053400W - 503930N 0052400W - 504300N 0051230W - 503830N 0050430W - 501918N 0053042W"
    7.     ar = Split(Text1.Text, "-")
    8.     For i = 1 To UBound(ar)
    9.         Text2.Text = Text2.Text & Mid$(ar(i), 1, InStr(1, ar(i), " ")) & vbNewLine & Mid$(ar(i), InStr(1, ar(i), " "))
    10.     Next
    11.     Erase ar
    12. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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