| View previous topic :: View next topic |
| Author |
Message |
nysander General User

Joined: 21 Jun 2008 Posts: 11
|
Posted: Fri Jul 04, 2008 10:14 pm Post subject: [solved] dumping multiline string row by row to array |
|
|
Hello, I wanted to as how could I dump unknown length string (char(10) separated)) to array ?
i know function split but I have to define array variable before using it, but i do not know how big this array should be defined. One time it could be 50 lines (char(10) separated) ant the other 200 or more.
is there any function to search for all char(10) to know how many lines are to parse and then redim the array to that number?
Last edited by nysander on Sat Jul 05, 2008 1:59 pm; edited 1 time in total |
|
| Back to top |
|
 |
Mark B Super User


Joined: 16 Feb 2007 Posts: 852 Location: Lincolnshire, UK
|
Posted: Sat Jul 05, 2008 12:12 am Post subject: |
|
|
I assume that you're reading this in from a database. If that's the case then just redim the array every time that a line of data is read in. Something like:
| Code: |
dim holder()
while not rs.EOF
n = ubound(holder) + 1
redim preserve holder(n)
holder(n) = rs!field
wend
|
Mark _________________ Mark B's Articles |
|
| Back to top |
|
 |
nysander General User

Joined: 21 Jun 2008 Posts: 11
|
Posted: Sat Jul 05, 2008 8:55 am Post subject: |
|
|
| i got this string from multiline textbox where user pastes some data which i need to parse. |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Sat Jul 05, 2008 9:51 am Post subject: |
|
|
You don't need to know the dimension of the Split array.
| Code: | Option Explicit
Sub Main
Dim s,aray
s = "a b c"
aray = Split(s)
For s = 0 to ubound(aray())
Print aray(s)
Next
End Sub |
|
|
| Back to top |
|
 |
nysander General User

Joined: 21 Jun 2008 Posts: 11
|
Posted: Sat Jul 05, 2008 1:59 pm Post subject: |
|
|
thank you very much. it worked as I wanted. my parser is now complete  |
|
| Back to top |
|
 |
|