coco86 0 Light Poster

let's say i want to read the substring and compare so i make a function

Public Function tracingFNHdr(h As String)

Left(h, 2) = Spid
Mid(h, 3, 5) = Loc
Mid(h, 6, 6) = TermType
Mid(h, 7, 8) = TermNo
Mid(h, 9, 13) = BatchNo
Mid(h, 14, 15) = BatchType
Mid(h, 16, 29) = DateCreated
Mid(h, 30, 37) = RecordCount
Mid(h, 38, 47) = DP
Mid(h, 48, 57) = CP
Mid(h, 58, 67) = DNMid(h, 68, 77) = CN
Mid(h, 78, 87) = HTPurse
Mid(h, 88, 97) = HTNPurse
Right(h, 8) = TotalQty
End Function

Do you think it's appropriate ? to get the function like this? plss help , im new in VB ...... your help will b great....

Do While Not ts.AtEndOfStream
a = ts.ReadAll
tracingFNHdr (h)
line = line + 1
Loop
Debug.Print (h)

Dani AI

Generated

— good instinct to put parsing into a routine. A couple of quick corrections before an example: assign the substring result to your variables (variable = substring), not the other way around; choose a Sub if you only want to populate variables passed ByRef or a Function if you want a returned value; and read the file one line at a time inside the loop instead of loading the entire file into a single string.

A concise, reusable pattern is to parse fixed-width fields with a widths array and return an array of trimmed values. This keeps the parsing logic in one place and makes the caller map fields to names, which is safer and easier to test.

Function ParseFixedFields(line As String, widths As Variant) As Variant
    Dim out() As String
    Dim pos As Long, i As Long
    pos = 1
    ReDim out(0 To UBound(widths) - LBound(widths))
    For i = LBound(widths) To UBound(widths)
        out(i - LBound(widths)) = Trim$(Mid$(line, pos, widths(i)))
        pos = pos + widths(i)
    Next i
    ParseFixedFields = out
End Function

Usage sketch: set up widths = Array(...), call fields = ParseFixedFields(aLine, widths), then map fields(0), fields(1), etc. Extra tips: verify Len(line) is at least the sum of widths before parsing; use Option Explicit; validate numeric fields with IsNumeric before converting; and add minimal error handling to detect malformed lines. This approach is clearer, easier to debug, and scales when field layouts change.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.