473,769 Members | 4,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help With Tab Delimited File

29 New Member
I would like some expert advice. I am writing in VB6. I am opening a tab delimited file, deleting the first 50 lines, and rewriting the file to a temp file. The temp file has about 20 columns with x number of lines. What I am trying to do, is open the tab delimited file, and read each column into a named variable, ex. depth<column1>m pf<column2>tg<c olumn3>,etc. I have written a function to take the variable from column2(mpf) & create another variable(fph) to insert back into the file, at column2. This would move everything from column2(mpf) on, up one column. The columns and variables are as follows:
depth(column1), mpf(column2),tg (column3),c1(co lumn4),etc. with the variables. I need to create the variable fph and insert it into column2, where the new file will read as follows:
depth(column1), fph(column2),mp f(column3),tg(c olumn4),c1(colu mn5),etc to the end of the line. The code I have is as follows:
Expand|Select|Wrap|Line Numbers
  1. Public tFile As String
  2. Public mpf As Double
  3. Public fSave As String
  4.  
  5. Public Function TrimAll(Str)
  6. '***remove all non ASCI chrs and reduce internal whitespace to single
  7.     Dim i, strTemp, strOut, strCh
  8.  
  9.     strTemp = Str
  10.     For i = 1 To Len(strTemp)
  11.         strCh = Mid(strTemp, i, 1) '***look at each character in turn
  12.         '***if the chr is a space and the previous added chr was a space ignore it
  13.         '***otherwise add it on
  14.         If Not (strCh = " " And Right(strOut, 1) = " ") Then
  15.             strOut = strOut & strCh
  16.         End If
  17.     Next
  18.     TrimAll = strOut
  19. End Function
  20.  
  21. Private Sub cmdConvert_Click()
  22.     Dim Script As Object
  23.     Dim ObjStream As Object
  24.     Dim strLine As String
  25.     Dim a As Integer
  26.  
  27.     'check for .las file
  28.     Set Script = CreateObject("Scripting.FileSystemObject")
  29.      If Script.FileExists(tFile) Then
  30.         a = True
  31.         Set ObjStream = Script.opentextfile(tFile, 1, False, 0)
  32.      Else:
  33.         MsgBox "There is no LAS data in file. Please update with new LAS data.", vbInformation + vbOKOnly
  34.         a = False
  35.         Exit Sub
  36.      End If
  37.  
  38.     If tFile > "" Then
  39.     'open file
  40.     Set Script = CreateObject("Scripting.filesystemobject")
  41.     Open tFile For Input As #1 'read from this file
  42.     Open "C:DB_CUETemp.dat" For Output As #2 'write to this file
  43.  
  44.     'delete header and print rest of data to temp file
  45.     If a = True Then
  46.         Dim i As Integer
  47.         i = 0
  48.             Do While i < 50 And Not ObjStream.AtEndOfStream
  49.                 strLine = ObjStream.Readline
  50.         i = i + 1
  51.         Loop
  52.  
  53.         Do While Not ObjStream.AtEndOfStream
  54.           strLine = TrimAll(ObjStream.Readline)
  55.           YourArray = Split(strLine, "  ") '***use the tab key to create space between quotes.***
  56.         Print #2, strLine
  57.         Loop
  58.     End If
  59.  
  60.     Close #1
  61.     Close #2
  62.  
  63.     'save file
  64.     With CommonDialog1
  65.         .Filter = "All Files|*.las*|"
  66.         .InitDir = "C:DB_CUE"
  67.         .DialogTitle = "Save File As"
  68.         .ShowSave
  69.     End With
  70.     fSave = CommonDialog1.FileName
  71.     'copy temp file
  72.     FileCopy "C:DB_CUETemp.dat", fSave '& ".las"
  73.     'delete temp file once copied
  74.     Kill "C:DB_CUETemp.dat"
  75.  
  76.         If MsgBox("File is complete. Would you like to view the file?", vbQuestion + vbYesNo, "LAS iGenerator") = vbYes Then
  77.             Shell ("Explorer.exe tFile"), vbNormalFocus
  78. '            Unload Me
  79.         End If
  80.     Else:
  81.     If MsgBox("You must select a file to convert before you can continue.", vbExclamation + vbOKOnly) = vbOK Then
  82.         Exit Sub
  83.     End If
  84.     End If
  85. End Sub
Could you help shed some light on this, or refer me to someone who may? Thanks for your time.
Dec 29 '09
11 1911
vb5prgrmr
305 Recognized Expert Contributor
try...
Expand|Select|Wrap|Line Numbers
  1. Function CalcFPH(ArrayElement As String) as String 
  2. CalcFPH=60/Int(ArrayElement) 
  3. End Function 
  4.  
and call it thus...
Expand|Select|Wrap|Line Numbers
  1.   OutputText = OutputText & ElementArray(0) & vbTab & CalcFPH(ElementArray(1))
  2.  


Good Luck
Jan 2 '10 #11
kimmelsd33
29 New Member
That works perfectly. Thank you very much for your expertise. Greatly appreciated
Jan 2 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1557
by: waters | last post by:
I seem to have hit a snag. I am trying to add the list (l_local) as an item in the output list (l_output). "l_local" is a modified copy of the format-list "l_format", which will be updated by index position within the function. The problem occurs in the following statement block: def create_apid_list(l_format,l_values): l_output = for t_curr_line in l_values: # ...for each list in the values list
8
5481
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
6
1796
by: Skc | last post by:
I am trying to import a file using a custom VB.net procedure, but the problem is it works on a file with pure comma separation and not inverted commas and commas, i.e. it works for AAA,BBB,CCC,DDD but not for "AAA","BBB","CCC","DDD". Here is an extract from the code which needs to be modified for the """: Sub LoadTextFile(ByVal strFilePath As String) Dim oDS As New DataSet() Dim strFields As String Dim oTable As New DataTable()
3
7033
by: Ben | last post by:
Hi all - I am having a bit of trouble and thought maybe someone in this group could shed some light. Here's the skinny... I am creating an automated process to import a bunch of text files into Access. I want to avoid creating a separate "Spec" for each file (there are over 180 files) and instead want to code my own dynamic importing rules. So far it's been going fine, except for one item...
17
2087
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms created and working. The first form the user fills out and submits. The form properties are set to Send to other: "Custom ISAPI, NSAPI, CGI, OR ASP SCRIPTING. The method is "POST" and the action is "secondpage.asp". I had to go this route because...
0
1681
by: Masa Ito | last post by:
I have pipe delimited (and comma/tab) files that I read with JET using a schema file. Occasionally a field has multiple quotes (") inside a single field - which chokes the line (the rest of the columns get read as nulls). An example of an offending line is: J" Invalid " .... This is a text field that is between the two 'pipes' so I need it read exactly as is. I have reverted to schema files, trying everything I can to overcome this...
6
22565
by: =?Utf-8?B?UmljaA==?= | last post by:
'--this code works but only reads text into one column when contains multiple cols Dim ds1x As New DataSet Dim ConStr As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dir1A\;Extended Properties=""Text;HDR=No;FMT=Delimited\""" Dim conn1x As New OleDb.OleDbConnection(ConStr) Dim dax1 As New OleDbDataAdapter("Select * from testabc1x.txt", conn1x)
5
2331
by: RyanL | last post by:
I'm a newbie! I have a non-delimited data file that I'd like to convert to delimited. Example... Line in non-delimited file: 0139725635999992000010100534+42050-102800FM-15+1198KAIA Should be: 0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
7
3337
by: kimmelsd33 | last post by:
I am using VB6. I want to read a tab delimited file, and assign each column value into a variable. If the variable is "-999.25", I want to make it a "0". I then want to reassemble the values, and write them to a temp text file. Starting with line 64, I have about 28 columns and x number of rows. Ex: 1000<tab>23.3<tab>-999.25<tab> etc. The value of -999.25 can be in any column. I need to replace it before it is stored in the variable. I need to...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.