Results 1 to 2 of 2

Thread: Read fixed width text file *resolved/open to tips*

Threaded View

  1. #1

    Thread Starter
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Read fixed width text file *resolved/open to tips*

    I'm starting a task where I'm going to need to read a fixed length text file and write it to SQL 2000 which I haven't done before. I don't want to start from scratch and run into the normal pitfalls if I can help it. Can someone point me to some existing code or a good tutorial on it? The SQL part is not a problem. What I'm looking for is a way to predefine the fields and the lengths to read into. I've run across snippets of code in my search but not a working model.

    EDITED ***

    Just in case someone else searches on this topic this is what I did and it seems to work. I'm open to constructive criticism and could use some tips on error handling for this. I just grabbed pieces from here and there to put it together. This is just the basic starting point to my task so if any one does have some tips now is the time.

    VB Code:
    1. Private strBWCClaimNumber As String
    2. Private strMCONumber As String
    3. Private strNoteCreateDate As String
    4. Private strNoteTitle As String
    5. Private strAuthorUserid As String
    6. Private strAuthorLastName As String
    7. Private strAuthorFirstName As String
    8. Private strNoteID As String
    9. Private strNotePrimary As String
    10. Private strNoteContinuation As String
    11.  
    12. Public Type NotesExport
    13.     BWCClaimNumber As String * 10     'BWCClaimNum
    14.     MCONumber As String * 5           '10005
    15.     NoteCreateDate As String * 10     'mm/dd/yyyy format
    16.     NoteTitle As String * 40          'Subject or Category of Note
    17.     AuthorUserid As String * 30       'Note Creator Userid
    18.     AuthorLastName As String * 30     'Last Name from refUserInfo
    19.     AuthorFirstName As String * 20    'First Name from refUserInfo
    20.     NoteID As String * 50             '10005 + pkNote
    21.     NotePrimary As String * 4012      'Primary text of note
    22.     NoteContinuation As String * 4012 'Continuation text of note
    23. End Type
    24.  
    25. Private NR As NotesExport
    26.  
    27. Public Sub ImportNotes()
    28.     Dim iFile As Integer
    29.     Dim L As Long
    30.    
    31.     iFile = FreeFile()
    32.    
    33.    
    34.     Open frmMain.txtImport.Text & frmMain.lvImport.SelectedItem.SubItems(1) For Random As #iFile Len = Len(NR)
    35.  
    36.     For L = 1 To Int(LOF(iFile) / Len(NR))
    37.         Get #iFile, L, NR
    38.         strBWCClaimNumber = NR.BWCClaimNumber
    39.         strMCONumber = NR.MCONumber
    40.         strNoteCreateDate = NR.NoteCreateDate
    41.         strNoteTitle = NR.NoteTitle
    42.         strAuthorUserid = NR.AuthorUserid
    43.         strAuthorLastName = NR.AuthorLastName
    44.         strAuthorFirstName = NR.AuthorFirstName
    45.         strNoteID = NR.NoteID
    46.         strNotePrimary = NR.NotePrimary
    47.         strNoteContinuation = NR.NoteContinuation
    48.         DoEvents
    49.     Next
    50.    
    51.     Close #iFile
    52.  
    53. End Sub
    Last edited by TysonLPrice; Jul 27th, 2006 at 10:20 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width