Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 14th, 2005, 03:22 PM
Registered User
 
Join Date: Aug 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Table operations

Hello Everybody,
This is my first posting to the group after joining this forum a short while ago. I hope that my problem will be addressed by somebody. I am quite new to coding in VBA under Excel environment. I have a data file saved in txt format. It is comma delimited file and has data from GPS and another sensor. Each row of GPS data has information recorded in 15 columns($GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e, q,ss,y.y,a.a,z,g.g,z,t.t,iii*CC). Corresponding to each GPS data, 5 rows of data is logged by the sensor. The data from the sensor spans 5 columns.

Now, i want to use Excel macro to do the following:
(i) Navigate to the folder containing the data,
(ii)Read the text file,
(iii) Find the average of five readings of the sensor and assign to each GPS observation.

Since i have limited exposure to writing codes, so could have been successful in writing only the folowing that help me navigate to the folder and load the data:

Sub opentextfiles()
Dim fName As String ' Defines that the file name is a string variable
fName = Application.GetOpenFilename(filefilter:="Text Files (*.txt),*.txt") ' select a textfile to be opened
If fName = "False" Then ' in case user cancels the subroutine
Exit Sub
End If
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fName, Destination:=Range("A1"))
        .Name = "fName"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 65000
        .TextFileStartRow = 16
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileOtherDelimiter = ")"
        .TextFileColumnDataTypes = Array(1, 1, 1, 1,1,1,1,1,1,1,1,1,1,1,1)
        .TextFileTrailingMinusNumbers = False
        .Refresh BackgroundQuery:=False
    End With

End Sub

The above results in importing the code that is in following order
GPS data1 col1 col2 ...........col15
Sensor data1 Col1 ............col5
sensor data2 Col1...............col5
.
.
Sensor data5 col1..........col5
GPS data2 Col1..............col15

Whereas, i want the data to look like the following
GPSCOl1..............GPScol15 SensorCol1(avg of 5 values)...SensorCol5(average of 5 values)

Please provide me the code to implement this. Thanks for your kind help in advance.
Paaji

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
File I/O Operations in C++ code_lover C++ Programming 1 August 10th, 2008 12:16 PM
timespan operations marclena General .NET 1 February 25th, 2005 07:08 AM
How to perform set related operations? hualin_yip Javascript 1 November 9th, 2004 08:00 AM
2 ListBox operations melvik C# 1 August 19th, 2003 06:51 AM
string operations Moharo Pro PHP 2 August 18th, 2003 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.