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: -
Public tFile As String
-
Public mpf As Double
-
Public fSave As String
-
-
Public Function TrimAll(Str)
-
'***remove all non ASCI chrs and reduce internal whitespace to single
-
Dim i, strTemp, strOut, strCh
-
-
strTemp = Str
-
For i = 1 To Len(strTemp)
-
strCh = Mid(strTemp, i, 1) '***look at each character in turn
-
'***if the chr is a space and the previous added chr was a space ignore it
-
'***otherwise add it on
-
If Not (strCh = " " And Right(strOut, 1) = " ") Then
-
strOut = strOut & strCh
-
End If
-
Next
-
TrimAll = strOut
-
End Function
-
-
Private Sub cmdConvert_Click()
-
Dim Script As Object
-
Dim ObjStream As Object
-
Dim strLine As String
-
Dim a As Integer
-
-
'check for .las file
-
Set Script = CreateObject("Scripting.FileSystemObject")
-
If Script.FileExists(tFile) Then
-
a = True
-
Set ObjStream = Script.opentextfile(tFile, 1, False, 0)
-
Else:
-
MsgBox "There is no LAS data in file. Please update with new LAS data.", vbInformation + vbOKOnly
-
a = False
-
Exit Sub
-
End If
-
-
If tFile > "" Then
-
'open file
-
Set Script = CreateObject("Scripting.filesystemobject")
-
Open tFile For Input As #1 'read from this file
-
Open "C:DB_CUETemp.dat" For Output As #2 'write to this file
-
-
'delete header and print rest of data to temp file
-
If a = True Then
-
Dim i As Integer
-
i = 0
-
Do While i < 50 And Not ObjStream.AtEndOfStream
-
strLine = ObjStream.Readline
-
i = i + 1
-
Loop
-
-
Do While Not ObjStream.AtEndOfStream
-
strLine = TrimAll(ObjStream.Readline)
-
YourArray = Split(strLine, " ") '***use the tab key to create space between quotes.***
-
Print #2, strLine
-
Loop
-
End If
-
-
Close #1
-
Close #2
-
-
'save file
-
With CommonDialog1
-
.Filter = "All Files|*.las*|"
-
.InitDir = "C:DB_CUE"
-
.DialogTitle = "Save File As"
-
.ShowSave
-
End With
-
fSave = CommonDialog1.FileName
-
'copy temp file
-
FileCopy "C:DB_CUETemp.dat", fSave '& ".las"
-
'delete temp file once copied
-
Kill "C:DB_CUETemp.dat"
-
-
If MsgBox("File is complete. Would you like to view the file?", vbQuestion + vbYesNo, "LAS iGenerator") = vbYes Then
-
Shell ("Explorer.exe tFile"), vbNormalFocus
-
' Unload Me
-
End If
-
Else:
-
If MsgBox("You must select a file to convert before you can continue.", vbExclamation + vbOKOnly) = vbOK Then
-
Exit Sub
-
End If
-
End If
-
End Sub
Could you help shed some light on this, or refer me to someone who may? Thanks for your time.
11 1907
This should be faster and easier to read... -
Dim FName As String, FNumb As Integer
-
Dim InnerForLoopCounter As Integer, OuterForLoopCounter As Integer
-
Dim LineArray() As String, ElementArray() As String
-
Dim InputText As String, OutputText As String
-
-
FName = "InputPathFileName" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Input As #FNumb
-
InputText = Input(FileLen(FName), #FNumb)
-
Close #FNumb
-
-
LineArray = Split(InputText, vbNewLine)
-
-
'Skip First 50
-
For OuterForLoopCounter = 50 To UBound(LineArray)
-
ElementArray = Split(LineArray(ForLoopCounter), vbTab)
-
OutputText = OutputText & ElementArray(0) & vbTab "item to insert"
-
For InnerForLoopCounter = 1 To UBound(ElementArray)
-
OutputText = OutputText & vbTab & ElementArray(InnerForLoopCounter)
-
Next InnerForLoopCounter
-
OutputText = OutputText & vbNewLine
-
Next OuterForLoopCounter
-
-
FName = "OutputPathFileName" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Output As #FNumb
-
Print #FNumb, OutputText
-
Close #FNumb
-
NOTE: Done freehand and so is untested and from memory so if I happened to flip something around, well Oopps! Sorry!
Also, since inner for loop is looping through a constant number of elements you could get the upper bounds of the array prior to entering the outer for loop and thus speed up this algorithm by a considerable amount (upwards of 50% faster).
Good Luck
Thanks for the response. This code is not putting the tab delimited file back together, and I have a function that the data in the second column, needs to run through, thus creating data for another variable and column of data. This new column of data needs to be inserted behind the first column, once the file is being written to the temp file. Does that make sense? If I can place each column of data into certain variable, pertained to each column, then I believe it would be easier to run the named variable through the function, and that value stored in another variable, and inserted into the temp file in a tab delimited text file. ? Not sure, but I think the logic would work. I am having problems creating it as I need it. Does this make sense?
Okay, then... Where I have "item to insert" is where you would put your function that returns a string and I think you said it does its thing from the 2nd colume so it would be... -
OutputText = OutputText & ElementArray(0) & vbTab & MyFunction(ElementArray(1))
-
As for not reassembling the file... It works here for me but if you are wanting the first 50 lines to be reassembled back into the file then you will need another string variable... or... -
ReDim Preserve LineArray(49) As String
-
-
FName = "OutputPathFileName" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Output As #FNumb
-
Print #FNumb, Join(LineArray, vbNewLine) & vbNewLine & OutputText
-
Close #FNumb
-
Not sure about the second vbNewLine...
Good Luck
dear,
I this a solution? see attachment
br,
Thanks again vbprgrmr. I must be doing something wrong. It is giving me an error message. This is what I have:
[code]
Public Sub Perform()
Dim FName As String, FNumb As Integer
Dim InnerForLoopCou nter As Integer, OuterForLoopCou nter As Integer
Dim LineArray() As String, ElementArray() As String
Dim InputText As String, OutputText As String
FName = "C:\DB_CUE\test file.las" 'need to change
FNumb = FreeFile
Open FName For Input As #FNumb
InputText = Input(FileLen(F Name), #FNumb)
Close #FNumb
LineArray = Split(InputText , vbNewLine)
'Skip First 50
For OuterForLoopCou nter = 50 To UBound(LineArra y)
ElementArray = Split(LineArray (ForLoopCounter ), vbTab)
OutputText = OutputText & ElementArray(0) & vbTab & CalcFPH(Element Array(1)) ' "item to insert"
For InnerForLoopCou nter = 1 To UBound(ElementA rray)
OutputText = OutputText & vbTab & ElementArray(In nerForLoopCount er)
Next InnerForLoopCou nter
OutputText = OutputText & vbNewLine
Next OuterForLoopCou nter
FName = "C:\DB_CUE\TEST 1.txt" 'need to change
FNumb = FreeFile
Open FName For Output As #FNumb
Debug.Print OutputText
Print #FNumb, OutputText
Close #FNumb
End Sub
Public Function CalcFPH() As String
CalcFtPerHr = 60 / mpf
End Function
[code]
I don't need it to reassemble adding the first 50 lines of data. I just need it to reassemble adding the extra function variable in column 2. Thanks for all your help. It is coming along though with your great help and patience. Thanks again
Thanks again vbprgrmr. I must be doing something wrong. It is giving me an error message. This is what I have: -
Public Sub Perform()
-
Dim FName As String, FNumb As Integer
-
Dim InnerForLoopCounter As Integer, OuterForLoopCounter As Integer
-
Dim LineArray() As String, ElementArray() As String
-
Dim InputText As String, OutputText As String
-
-
FName = "C:\DB_CUE\testfile.las" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Input As #FNumb
-
InputText = Input(FileLen(FName), #FNumb)
-
Close #FNumb
-
-
LineArray = Split(InputText, vbNewLine)
-
-
'Skip First 50
-
For OuterForLoopCounter = 50 To UBound(LineArray)
-
ElementArray = Split(LineArray(ForLoopCounter), vbTab)
-
OutputText = OutputText & ElementArray(0) & vbTab & CalcFPH(ElementArray(1)) ' "item to insert"
-
For InnerForLoopCounter = 1 To UBound(ElementArray)
-
OutputText = OutputText & vbTab & ElementArray(InnerForLoopCounter)
-
Next InnerForLoopCounter
-
OutputText = OutputText & vbNewLine
-
Next OuterForLoopCounter
-
-
FName = "C:\DB_CUE\TEST1.txt" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Output As #FNumb
-
Debug.Print OutputText
-
Print #FNumb, OutputText
-
Close #FNumb
-
End Sub
-
-
Public Function CalcFPH() As String
-
CalcFtPerHr = 60 / mpf
-
End Function
-
I don't need it to reassemble adding the first 50 lines of data. I just need it to reassemble adding the extra function variable in column 2. Thanks for all your help. It is coming along though with your great help and patience. Thanks again
okay, with this code (which is the same)... -
Option Explicit
-
-
Private Sub Command1_Click()
-
Dim FName As String, FNumb As Integer
-
Dim InnerForLoopCounter As Integer, OuterForLoopCounter As Integer
-
Dim LineArray() As String, ElementArray() As String
-
Dim InputText As String, OutputText As String
-
-
FName = "e:\temp\testfile.txt" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Input As #FNumb
-
InputText = Input(FileLen(FName), #FNumb)
-
Close #FNumb
-
-
LineArray = Split(InputText, vbNewLine)
-
-
'Skip First 50
-
For OuterForLoopCounter = 50 To UBound(LineArray)
-
ElementArray = Split(LineArray(OuterForLoopCounter), vbTab)
-
OutputText = OutputText & ElementArray(0) & vbTab & "item to insert"
-
For InnerForLoopCounter = 1 To UBound(ElementArray)
-
OutputText = OutputText & vbTab & ElementArray(InnerForLoopCounter)
-
Next InnerForLoopCounter
-
OutputText = OutputText & vbNewLine
-
Next OuterForLoopCounter
-
-
FName = "e:\temp\output.txt" 'need to change
-
FNumb = FreeFile
-
-
Open FName For Output As #FNumb
-
Print #FNumb, OutputText
-
Close #FNumb
-
-
End Sub
-
the attached file is the output...
Which looks just fine (NOTE: there was one change in the code on this line (ElementArray = Split(LineArray (OuterForLoopCo unter), vbTab)) the loop counter was previously just ForLoopCounter and needed to be OuterForLoopCou nter and that is what option explicit is for to catch those undeclared variables...Too ls>Options>Requ ire Variable declaration>ok)
Good Luck
dear,
Maybe this tool will do it. see attachment
Please call me if you want any modifications.
br,
The code works great. The problem I am having problems with is the "item to insert". I need the ElementArray(1) to process through a function, and return a value stored in a variable, and reinserted. I have tried a couple of ways to modify your code to make it happen, but it's not working. The function ElementArray(1) needs to go through is: -
Function CalcFPH(ElementArray) as String
-
CalcFPH=60/ElementArray(1)
-
End Function
-
I've tried creating a variable such as FPH to store the value of the function in, and then insert that, but my output is coming up blank. The key is to process the second column through the function and reinsert the value back into the second column when it writes the file. Other than that, it all works well. Thanks for your help
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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()
|
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...
|
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...
| |
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...
|
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)
|
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
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |