Results 1 to 1 of 1

Thread: [VB] Data Format

  1. #1

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186

    [VB] Data Format

    I've included 2 text files with this project. The first (Data.txt) is my input data set and the second is how my outputted data is supposed to appear. Here's is the code that I've used to input the data, format it, and output it. My code produces the correct output but I'm sure there's a more optimal way to do this.

    VB Code:
    1. Private Function GetData()
    2.  
    3.     Open "F:\Acell\Data.txt" For Input As #1
    4.         lineArray = Split(Input(LOF(1), 1), vbCrLf)
    5.     Close #1
    6.        
    7.     'Stores the data into an array and trims any leading spaces
    8.     For i = 1 To (UBound(lineArray) - 2)
    9.         T(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 1, 8)), 3)
    10.         ax0(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 9, 10)), 3)
    11.         ax1(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 19, 10)), 3)
    12.         ax3(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 29, 10)), 3)
    13.         ay0(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 39, 10)), 3)
    14.         ay2(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 49, 10)), 3)
    15.         ay3(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 59, 10)), 3)
    16.         az0(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 69, 10)), 3)
    17.         az2(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 79, 10)), 3)
    18.         az1(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 89, 10)), 3)
    19.     Next
    20.  
    21. End Function
    22.  
    23. Private Function WriteFile2()
    24.    
    25.     Open App.Path & "\RetrieveData.dat" For Output As #1
    26.         Print #1, "Time(ms) " & Space(3) & "HD-OX" & Space(5) & "HD-YX" & Space(5) & "HD-ZX" & _
    27.                   Space(5) & "HD-OY" & Space(5) & "HD-XY" & Space(5) & "HD-ZY" & Space(5) & _
    28.                   "HD-OZ" & Space(5) & "HD-XZ" & Space(5) & "HD-YZ"
    29.     Close #1
    30.    
    31.     Open App.Path & "\RetrieveData.dat" For Append As #1
    32.         For i = 1 To (UBound(lineArray) - 2)
    33.             Call computeSpaces(ax0(i))
    34.             ax0spaces = numspaces
    35.             Call computeSpaces(ax1(i))
    36.             ax1spaces = numspaces
    37.             Call computeSpaces(ax3(i))
    38.             ax3spaces = numspaces
    39.             Call computeSpaces(ay0(i))
    40.             ay0spaces = numspaces
    41.             Call computeSpaces(ay2(i))
    42.             ay2spaces = numspaces
    43.             Call computeSpaces(ay3(i))
    44.             ay3spaces = numspaces
    45.             Call computeSpaces(az0(i))
    46.             az0spaces = numspaces
    47.             Call computeSpaces(az2(i))
    48.             az2spaces = numspaces
    49.             Call computeSpaces(az1(i))
    50.             az1spaces = numspaces
    51.             Print #1, T(i) & Space(ax0spaces) & ax0(i) & Space(ax1spaces) & ax1(i) & _
    52.                     Space(ax3spaces) & ax3(i) & Space(ay0spaces) & ay0(i) & Space(ay2spaces) & ay2(i) & _
    53.                     Space(ay3spaces) & ay3(i) & Space(az0spaces) & az0(i) & Space(az2spaces) & az2(i) & _
    54.                     Space(az1spaces) & az1(i)
    55.         Next
    56.     Close #1
    57.    
    58. End Function
    59.  
    60. Private Sub computeSpaces(datapoint)
    61.  
    62.     If datapoint <= -1000 Then
    63.         numspaces = 1
    64.     ElseIf datapoint <= -100 Then
    65.         numspaces = 2
    66.     ElseIf datapoint <= -10 Then
    67.         numspaces = 3
    68.     ElseIf datapoint < 0 Then
    69.         numspaces = 4
    70.     ElseIf datapoint < 10 Then
    71.         numspaces = 5
    72.     ElseIf datapoint < 100 Then
    73.         numspaces = 4
    74.     ElseIf datapoint < 1000 Then
    75.         numspaces = 3
    76.     ElseIf datapoint < 10000 Then
    77.         numspaces = 2
    78.     ElseIf datapoint < 100000 Then
    79.         numspaces = 1
    80.     End If
    81.    
    82. End Sub
    Attached Files Attached Files
    Last edited by run_GMoney; Jan 23rd, 2004 at 11:10 AM.
    Place Your VBForums Ad Here

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