Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Parse String into Variables

I need to parse a string like:

732:1:29:18457:3

Into an array of variables:
DIM ntach(513) AS LONG

So ntach(1) would contain 732
ntach(2) would contain 1
ntach(3) would contain 29
ntach(4) would contain 18457 and
ntach(5) would contain 3

Each string can contain between 1 and 513 multi-digit numbers.
Each number can have between 1 and 6 digits.

If I was in a worksheet and if there were less than 256 numbers per string,
I would use Text to Columns€¦

What should I do in VBA?

--
Gary''s Student
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Parse String into Variables

Hi

SPLIT does that. But you have to convert every datatype afterwards I
believe:

Sub test()
Dim s As String
Dim t() As String
Dim ntach() As Long
Dim i As Long

s = "732:1:29:18457:3"
t = Split(s, ":")
ReDim ntach(LBound(t) To UBound(t))

For i = LBound(t) To UBound(t)
ntach(i) = Val(t(i))
Next

For i = LBound(ntach) To UBound(ntach)
MsgBox ntach(i), , i
Next

End Sub

HTH. Best wishes Harald

"Gary''s Student" skrev i melding
...
I need to parse a string like:

732:1:29:18457:3

Into an array of variables:
DIM ntach(513) AS LONG

So ntach(1) would contain 732
ntach(2) would contain 1
ntach(3) would contain 29
ntach(4) would contain 18457 and
ntach(5) would contain 3

Each string can contain between 1 and 513 multi-digit numbers.
Each number can have between 1 and 6 digits.

If I was in a worksheet and if there were less than 256 numbers per

string,
I would use Text to Columns.

What should I do in VBA?

--
Gary''s Student



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Parse String into Variables


InStr is your best bet. Don't really have time to throw together how to
do this in code, but suffice to say Instr(1,MyString,":") should get
you started.


--
xander1987
------------------------------------------------------------------------
xander1987's Profile: http://www.excelforum.com/member.php...o&userid=27236
View this thread: http://www.excelforum.com/showthread...hreadid=469520

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Parse String into Variables

Thnk you very much.
--
Gary''s Student


"Harald Staff" wrote:

Hi

SPLIT does that. But you have to convert every datatype afterwards I
believe:

Sub test()
Dim s As String
Dim t() As String
Dim ntach() As Long
Dim i As Long

s = "732:1:29:18457:3"
t = Split(s, ":")
ReDim ntach(LBound(t) To UBound(t))

For i = LBound(t) To UBound(t)
ntach(i) = Val(t(i))
Next

For i = LBound(ntach) To UBound(ntach)
MsgBox ntach(i), , i
Next

End Sub

HTH. Best wishes Harald

"Gary''s Student" skrev i melding
...
I need to parse a string like:

732:1:29:18457:3

Into an array of variables:
DIM ntach(513) AS LONG

So ntach(1) would contain 732
ntach(2) would contain 1
ntach(3) would contain 29
ntach(4) would contain 18457 and
ntach(5) would contain 3

Each string can contain between 1 and 513 multi-digit numbers.
Each number can have between 1 and 6 digits.

If I was in a worksheet and if there were less than 256 numbers per

string,
I would use Text to Columns.

What should I do in VBA?

--
Gary''s Student




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse A String into Two xlmate Excel Worksheet Functions 11 February 21st 09 04:06 AM
Parse this string David Excel Discussion (Misc queries) 2 February 20th 07 04:57 AM
Q: parse string JIM.H. Excel Discussion (Misc queries) 3 October 22nd 05 01:45 AM
Parse String Geoff Murley Excel Programming 9 February 3rd 05 02:02 AM
String Parse J Excel Programming 3 August 10th 04 10:27 PM


All times are GMT +1. The time now is 11:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"