Re: VB6 to convert textfile data

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Al" <Al@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote

I am having difficulty solving a textfile import issue.

Upon completion, I want to covert the VB6 program to an .exe file and
schedule to run through a batch file on a daily basis. I have other files
like this running through a VB6 conversion program and batch file setup but I
have encountered a snag with this one.

See if this will do as you want:

LFS

'[ Form1 code ]
Option Explicit

Private Keys As New Collection

Private Sub Command1_Click()
Const DataFile = "D:\temp\data.txt"
Const FixedFile = "D:\temp\fixed.txt"
Dim src As Long, dst As Long
Dim txt As String

src = FreeFile
Open DataFile For Input Access Read As src Len = 4096
dst = FreeFile
Open FixedFile For Output Access Write As dst Len = 1024

Do While Not EOF(src)
Line Input #src, txt
Print #dst, Adjusted(txt)
Loop
Close

End Sub

Private Function Adjusted(Text As String) As String
Dim cnt As Long, list As Collection
Dim key As String, match As String

' Extract search data
match = Left$(Text, 8)
key = Mid$(Text, 10, 8)

' Find key list
On Error Resume Next
Set list = Keys(key)

If Err.Number Then
' New list
Set list = New Collection
Err.Clear
End If

' Find match in current list
cnt = list(match)

If Err.Number Then
' No match
cnt = list.Count + 1
' Save value for this Key/Match pair
list.Add cnt, match
' Replace old list with new list
Keys.Remove key
Keys.Add list, key
End If

' Adjust text
Mid$(Text, 19, 3) = Format$(cnt, "000")
Adjusted = Text

End Function



.



Relevant Pages

  • Re: VB6 to convert textfile data
    ... only thing I changed was Private Sub Command1_Clickto Private Sub main, ... Dim src As Long, dst As Long ... Private Function Adjusted(Text As String) As String ... Dim cnt As Long, list As Collection ...
    (microsoft.public.vb.general.discussion)
  • Re: Application.FileSearch
    ... Function FilesToCol(sPath As String, sLike As String, c As Collection) As ... Dim sFile As String ... Dim cnt As Long, i As Long ...
    (microsoft.public.excel.programming)
  • Re: string concatenation
    ... > from src to dst to form a string with strlen< size. ... _documented_ to act differently than the OpenBSD versions do. ... Need an efficient and powerful string library for C? ...
    (comp.lang.c)
  • Re: how to determine if files are on same or different file systems
    ... >> appropriate error handling. ... > That's why I'm looking for a way to tell if a particular partition is ... shutil.copy2(src, dst) ... Or use the length of the string and count backwards? ...
    (comp.lang.python)