To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > General > Code It Better

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Jan 23rd, 2004, 10:45 AM   #1
run_GMoney
Addicted Member
 
run_GMoney's Avatar
 
Join Date: May 02
Location: Detroit
Posts: 186
run_GMoney is an unknown quantity at this point (<10)
[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.     Open "F:\Acell\Data.txt" For Input As #1
  3.         lineArray = Split(Input(LOF(1), 1), vbCrLf)
  4.     Close #1
  5.        
  6.     'Stores the data into an array and trims any leading spaces
  7.     For i = 1 To (UBound(lineArray) - 2)
  8.         T(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 1, 8)), 3)
  9.         ax0(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 9, 10)), 3)
  10.         ax1(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 19, 10)), 3)
  11.         ax3(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 29, 10)), 3)
  12.         ay0(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 39, 10)), 3)
  13.         ay2(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 49, 10)), 3)
  14.         ay3(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 59, 10)), 3)
  15.         az0(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 69, 10)), 3)
  16.         az2(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 79, 10)), 3)
  17.         az1(i - 1) = FormatNumber(LTrim(Mid(lineArray(i), 89, 10)), 3)
  18.     Next
  19. End Function
  20. Private Function WriteFile2()
  21.    
  22.     Open App.Path & "\RetrieveData.dat" For Output As #1
  23.         Print #1, "Time(ms) " & Space(3) & "HD-OX" & Space(5) & "HD-YX" & Space(5) & "HD-ZX" & _
  24.                   Space(5) & "HD-OY" & Space(5) & "HD-XY" & Space(5) & "HD-ZY" & Space(5) & _
  25.                   "HD-OZ" & Space(5) & "HD-XZ" & Space(5) & "HD-YZ"
  26.     Close #1
  27.    
  28.     Open App.Path & "\RetrieveData.dat" For Append As #1
  29.         For i = 1 To (UBound(lineArray) - 2)
  30.             Call computeSpaces(ax0(i))
  31.             ax0spaces = numspaces
  32.             Call computeSpaces(ax1(i))
  33.             ax1spaces = numspaces
  34.             Call computeSpaces(ax3(i))
  35.             ax3spaces = numspaces
  36.             Call computeSpaces(ay0(i))
  37.             ay0spaces = numspaces
  38.             Call computeSpaces(ay2(i))
  39.             ay2spaces = numspaces
  40.             Call computeSpaces(ay3(i))
  41.             ay3spaces = numspaces
  42.             Call computeSpaces(az0(i))
  43.             az0spaces = numspaces
  44.             Call computeSpaces(az2(i))
  45.             az2spaces = numspaces
  46.             Call computeSpaces(az1(i))
  47.             az1spaces = numspaces
  48.             Print #1, T(i) & Space(ax0spaces) & ax0(i) & Space(ax1spaces) & ax1(i) & _
  49.                     Space(ax3spaces) & ax3(i) & Space(ay0spaces) & ay0(i) & Space(ay2spaces) & ay2(i) & _
  50.                     Space(ay3spaces) & ay3(i) & Space(az0spaces) & az0(i) & Space(az2spaces) & az2(i) & _
  51.                     Space(az1spaces) & az1(i)
  52.         Next
  53.     Close #1
  54.    
  55. End Function
  56. Private Sub computeSpaces(datapoint)
  57.     If datapoint <= -1000 Then
  58.         numspaces = 1
  59.     ElseIf datapoint <= -100 Then
  60.         numspaces = 2
  61.     ElseIf datapoint <= -10 Then
  62.         numspaces = 3
  63.     ElseIf datapoint < 0 Then
  64.         numspaces = 4
  65.     ElseIf datapoint < 10 Then
  66.         numspaces = 5
  67.     ElseIf datapoint < 100 Then
  68.         numspaces = 4
  69.     ElseIf datapoint < 1000 Then
  70.         numspaces = 3
  71.     ElseIf datapoint < 10000 Then
  72.         numspaces = 2
  73.     ElseIf datapoint < 100000 Then
  74.         numspaces = 1
  75.     End If
  76.    
  77. End Sub
Attached Files
File Type: zip textfiles.zip (98.5 KB, 79 views)
__________________
Place Your VBForums Ad Here

Last edited by run_GMoney; Jan 23rd, 2004 at 11:10 AM.
run_GMoney is offline   Reply With Quote
Reply

Go Back   VBForums > General > Code It Better


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:25 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.