Problem with User Defined Types and flat file processing

Hi - I am having an issue with reading values out of a flat file accurately. The first record I loop through comes across perfectly and all values are exactly what I am looking for. However the second record appears to be one byte off - causing the refNum (which is stored as a Hex value) to be one byte off. However the second record appears to be one byte off - causing the refNum (which is stored as a Hex value) to be one byte off. I have tried increasing and decreasing the lengths of the fields that are placeholders and don't hold any data, as well as adding an EndOfLine As String * 2, or EndOfLine As String * 1, however this only makes the first record no longer read correctly. I've included the type info below, as well as my code, in case anyone that was involved in this has any helpful ideas.

Thanks!

I have posted my code in the hope that someone can help in some way!

*************** start code ***************'

Type OCAReferralType
dummy As String * 6
refNum As String * 4
drLastName As String * 15
dummy1 As String * 1
drFirstName As String * 15
dummy2 As String * 1
drMiddle As String * 15
dummy3 As String * 1
drAddress As String * 40
dummy4 As String * 1
drZip As String * 9
dummy5 As String * 1
drPhoneArea As String * 4
dummy6 As String * 1
drPhoneNumber As String * 7
dummy7 As String * 1
drPhoneExt As String * 4
dummy7a As String * 1
drTitle As String * 15
dummy8 As String * 1
drDegree As String * 15
dummy9 As String * 1
drGender As String * 1
drProviderId As String * 12
dummy10 As String * 1
drSpecialty As String * 1 ' not used
dummy11 As String * 1
drNotes As String * 40
dummy12 As String * 10
drAddAddress As String * 40
dummy13 As String * 1
drAddZip As String * 9
dummy25 As String * 37

End Type
Public OCAReferral As OCAReferralType

Public Sub ConvertReferrals()
Dim iReferralFile As Integer

'Load the Referring doctors
Status.LblOldFile = referral file"
Status.LblNewFile = "Referral table"

iReferralFile% = FreeFile
Open DataPath$ & "REFDR.DAT" For Binary As iReferralFile%

Get #iReferralFile%, , OCAReferral
lCurPos& = Seek(iReferralFile%)
lRecordCount& = (LOF(iReferralFile%) - lCurPos&) / Len(OCAReferral)
lCounter& = 0

Do Until EOF(iReferralFile%)
Get #iReferralFile%, , OCAReferral

If Not EOF(iReferralFile%) Then
'Process this referring party
Dim lOldId As Long
Dim sDrLastName As String
Dim sDrFirstName As String
Dim sDrMiddleName As String
Dim sDrAddress As String
Dim sDrZip As String
Dim sDrPhoneArea As String
Dim sDrPhoneNumber As String
Dim sDrPhoneExt As String
Dim sDrTitle As String
Dim sDrDegree As String
Dim sDrGender As String
Dim sDrProviderId As String
Dim sDrSpecialty As String
Dim sDrNotes As String
Dim sDrAddAddress As String
Dim sDrAddZip As String

lOldId = CVL(OCAReferral.refNum)
sDrLastName = Trim$(OCAReferral.drLastName)
sDrFirstName = Trim$(OCAReferral.drFirstName)
sDrMiddleName = Trim$(OCAReferral.drMiddle)
sDrAddress = Trim$(OCAReferral.drAddress)
sDrZip = Trim$(OCAReferral.drZip)
sDrPhoneArea = Trim$(OCAReferral.drPhoneArea)
sDrPhoneNumber = Trim$(OCAReferral.drPhoneNumber)
sDrPhoneExt = Trim$(OCAReferral.drPhoneExt)
sDrTitle = Trim$(OCAReferral.drTitle)
sDrDegree = Trim$(OCAReferral.drDegree)
sDrGender = Trim$(OCAReferral.drGender)
sDrProviderId = Trim$(OCAReferral.drProviderId)
'sDrSpecialty = Trim$(OCAReferral.drSpecialty)
sDrNotes = Trim$(OCAReferral.drNotes)
sDrAddAddress = Trim$(OCAReferral.drAddAddress)
sDrAddZip = Trim$(OCAReferral.drAddZip)

'Show the new percentage complete
lCounter& = lCounter& + 1

percentage% = (lCounter& / lRecordCount&) * 100
If percentage% <> HoldPercent% Then
HoldPercent% = percentage%
If HoldPercent% <= 100 Then
Status.PanelStatus.Value = HoldPercent%
Status.Refresh
End If
End If
End If
Loop

Close iReferralFile%
End Sub

Comments

  • You are sure this problem is not caused by a fault in saving?

    As far as I can tell, this code is correct (except for that you don't do anything with the data, especially not with the first record...)

    Could you post your save code? And please put it between [leftbr]code[rightbr]...[leftbr]/code[rightbr] tags!

    Greets...
    Richard

  • : You are sure this problem is not caused by a fault in saving?
    :
    : As far as I can tell, this code is correct (except for that you don't do anything with the data, especially not with the first record...)
    :
    : Could you post your save code? And please put it between [leftbr]code[rightbr]...[leftbr]/code[rightbr] tags!
    :
    : Greets...
    : Richard
    :
    :

    Hi Richard - I am sure it's not caused by not saving the data - I havent even written that code yet because I have so much more to do with the data. Right now I am just looping through the values to see that they are coming across ok. The first record comes across perfectly, but in the second record all values are one character off. I shouldn't need to save the data in order to loop through the record set....
  • : I shouldn't need to save the data in order to loop through the record set....


    Unless you read the Help for the Get statement and realize that it's designed specifically for reading data that was written by a Put statement.

    Since you state that the second record is one byte off, my first guess is that it has something to do with the line termination characters your file uses. Do your lines have only an LF character rather than the two-byte CRLF sequence? That's the first place I would look, other than writing a simple program to write the data using Put to make sure you're working with properly structured data.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Maybe i'm just a bit slow here, but how can you read the data without having saved it once?

    Anyway, where do you ever use the vbCrLf? Must be somewhere at saving, which brings me to my dilemma.
    And, why would you with saving? These records are raw data... if you have seperated them by a CrLf sequence then you should incorporate that into your loading code!

    Greets...
    Richard

  • : Maybe i'm just a bit slow here, but how can you read the data without having saved it once?
    :
    : Anyway, where do you ever use the vbCrLf? Must be somewhere at saving, which brings me to my dilemma.
    : And, why would you with saving? These records are raw data... if you have seperated them by a CrLf sequence then you should incorporate that into your loading code!
    :
    : Greets...
    : Richard
    :
    :
    You can read the data by stepping through the code to see each value as it loops through. I did find the solution to my problem in case anyone else comes across something similar:

    The problem was that the header was only 312 bytes, but every record there after is 313 bytes. How I fixed this in the code was this:

    I changed the last line of my type to read:
    dummy25 As String * 38

    and in my ConvertReferrals() sub I declared a fixed string variable, ie
    Dim dummy As String * 312

    then I used this to read the very first record, eg:
    Get #iReferralFile%, , dummy

    Thanks to everyone for the ideas!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories