|
-
Feb 1st, 2006, 02:52 PM
#1
Thread Starter
Addicted Member
[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:
Plots = Plots & " - "
NoPts = NoPts - 1
For i = 0 To NoPts
PosN = InStr(1, Plots, "-")
Points(i) = Left$(Plots, PosN - 2)
Length = Len(Plots)
Plots = Right$(Plots, Length - (PosN + 1))
Next i
-
Feb 1st, 2006, 02:55 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 1st, 2006, 03:00 PM
#3
Thread Starter
Addicted Member
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
-
Feb 1st, 2006, 03:09 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 1st, 2006, 03:10 PM
#5
Thread Starter
Addicted Member
Re: String manipulation
yea so I have a list like
501918N
0053042W
502400N
0053900W
503200N
0053400W
503930N
0052400W
504300N
0051230W
503830N
0050430W
501918N
0053042W
-
Feb 1st, 2006, 03:11 PM
#6
New Member
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.
-
Feb 1st, 2006, 03:12 PM
#7
Re: String manipulation
Here is for them together.
VB Code:
Option Explicit
'Text2 is a multi-line textbox...
Private Sub Command1_Click()
Dim ar() As String
Dim i As Integer
Text1.Text = "501918N 0053042W - 502400N 0053900W - 503200N 0053400W - 503930N 0052400W - 504300N 0051230W - 503830N 0050430W - 501918N 0053042W"
ar = Split(Text1.Text, "-")
For i = 1 To UBound(ar)
Text2.Text = Text2.Text & ar(i) & vbNewLine
Next
Erase ar
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Feb 1st, 2006, 03:13 PM
#8
Re: String manipulation
And here is separated.
VB Code:
Option Explicit
'Text2 is a multi-line textbox...
Private Sub Command1_Click()
Dim ar() As String
Dim i As Integer
Text1.Text = "501918N 0053042W - 502400N 0053900W - 503200N 0053400W - 503930N 0052400W - 504300N 0051230W - 503830N 0050430W - 501918N 0053042W"
ar = Split(Text1.Text, "-")
For i = 1 To UBound(ar)
Text2.Text = Text2.Text & Mid$(ar(i), 1, InStr(1, ar(i), " ")) & vbNewLine & Mid$(ar(i), InStr(1, ar(i), " "))
Next
Erase ar
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|