Results 1 to 3 of 3

Thread: Parse into array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    Parse into array

    Hi!

    I've got this as a string:
    Code:
    200201  +0.600000000000000E+02
    200202  +0.290000000000000E+02
    200203  +0.430000000000000E+02
    200204  +0.760000000000000E+02
    200205  +0.590000000000000E+02
    200206  +0.660000000000000E+02
    200207  +0.500000000000000E+02
    200208  +0.660000000000000E+02
    200209  +0.750000000000000E+02
    200210  +0.880000000000000E+02
    200211  +0.720000000000000E+02
    I want to put this into a 2dim array.
    With [date] and then [value]
    [0][0] = 200201,
    [0][1] = +0.600000000000000E+02

    and so on..

    Thanks for help!

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Parse into array

    VB Code:
    1. 'from the top of my head
    2. 'suppose u already have the result in a string variable called strResult
    3. 'the final 2 dim array will be called fResult
    4.  
    5. dim fResult() as String
    6. dim tmpMainResult() as String
    7. dim tmpBrokenResult() as String
    8.  
    9. dim tmpcnt as integer
    10.  
    11. tmpMainResult=split(strResult,vbcrlf)
    12. redim fResult(ubound(tmpMainResult),1) as String
    13.  
    14. for tmpcnt=0 to ubound(tmpMainResult)
    15.     tmpBrokenResult=split(tmpMainResult(tmpcnt)," ")
    16.     fResult(tmpcnt,0)=tmpBrokenResult(0)
    17.     fResult(tmpcnt,1)=tmpBrokenResult(1)
    18. next tmpcnt

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Parse into array

    or you could use a custom type:
    VB Code:
    1. Private Type MYDATA
    2.     dteDate As Date
    3.     dblValue As Double
    4. End Type
    5.  
    6. Private Sub Command1_Click()
    7.     Dim arrData() As MYDATA, sTemp() As String, N As Long
    8.    
    9.     sTemp = Split(Text1.Text, vbCrLf)
    10.     ReDim arrData(UBound(sTemp))
    11.    
    12.     For N = 0 To UBound(sTemp)
    13.         arrData(N).dteDate = Mid$(sTemp(N), 1, 2) & "/" & _
    14.                              Mid$(sTemp(N), 3, 2) & "/" & _
    15.                              Mid$(sTemp(N), 5, 2)
    16.         arrData(N).dblValue = CDbl(Mid$(sTemp(N), 8))
    17.     Next N
    18. End Sub

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