Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Databases (VB 6)

    Hi! I hope someone can help or point me in the right direction here. I am working on a vb app and I need to import a text file into the program(database) and I don't have a clue as to how to do this. My app has a database named layouts that contains 4 fields one of which is a part number field. I need to match that part number field up to the part number field in a text file (the text file is generated by a proprietary system and there's no other way of getting the info out.) and only display those matching records. (If theres a part number in the layouts database, I need only the matching records from the text file.)
    The text file is a +-sign delimited file and the user needs to be able to press an Update button and have this file imported into the program and displayed in a table-like fashion or grid. The info in the text file is read only and does not need to be edited.
    I am a vb newbie and really have no idea where to even begin on this. ALL help is VERY much appreciated! Thank You!
    Kris

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Databases (VB 6)

    Are you actually using a table in a Jet/Access database as the back end for this, or are you storing the data in a file named layouts or somewhere else?
    Charlotte

  3. #3
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Databases (VB 6)

    Yes. I created a database using Visdata within VB6. (Microsoft Jet 4.0 OLE DB Provider)

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Databases (VB 6)

    Since it is just a text file, I would not use OLE to read it. I would use an Open statement, Line Input statements, and the Split function.

    To give more information than that, I would need to know more about the text file, especially what you mean by +- sign deliminated. Can you put several lines into Word, change any words/data that are proprietary, and attach it to a reply to this post? Thanks! --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Databases (VB 6)

    You might find <!post=this thread, 138394>this thread<!/post> on importing an Excel worksheet into Access using VB of interest. It presumes you have a copy of Access so you can use the Transfer command, but would save you hours of grief in trying to write an import process that would convert your text to an Access table.
    Wendell

  6. #6
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Databases (VB 6)

    Ok, attached is a sample of the data I need to import. Thanks for the help!

  7. #7
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Databases (VB 6)

    I would love to just do this in Access since I already have the database with 2 tables setup and made Access do the SQL queries for me, but the Boss wants a VB app...sigh...Thanks for the link though. (P.S. This project did begin as an Excel spreadsheet.)

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Databases (VB 6)

    Actually the thread I pointed you to is doing the transfer from VB, but is using the Access command under the covers. That might just satisfy your boss - unless you ultimately have to run it on a PC that does not have Access 2000 or 2002 installed.
    Wendell

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Databases (VB 6)

    (I see no attachment to your post)

    To summarize what Sam and Wendell have been telling you:
    1. <LI>If you users have Access, you can use Automation to let Access do things for you from within your VB6 application. An advantage of this is that Access can import a text file into a table using the DoCmd.TransferText method; you don't have to read the text file line by line.
      <LI>If your users don't have Access or if if using Access (even "under cover") is not an option:
      <UL><LI>Use the Open instruction to open the text file, and read it line by line using the Input or Line Input instructions.
      <LI>Use ADODB (or DAO) to open the appropriate table in the database as a recordset, append a record for each line read from the text file, and write the values to the fields of the record.
    It's more work than using Access, but it shouldn't be too hard. Look up "Open statement", "Input statement" and "Line input statement" in the help index to see how you can open and read a text file. Look up "AddNew method" to see how you can add a record to a recordset.[/list]

  10. #10
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Databases (VB 6)

    Try the attachment again. Preview your message, then Browse for the attachment, then immediately Post It. If you preview again, you loose the attachment. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  11. #11
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Databases (VB 6)

    Thanks for the help. Maybe this time I can get the attachment here [img]/forums/images/smilies/smile.gif[/img]
    Using Access is completely out of the question unfortunately. This all has to be done in VB.

    Kris
    Attached Files Attached Files

  12. #12
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Databases (VB 6)

    That is VERY UGLY. Do they really have variable length fields, missing months, missing dollar signs, etc? What do the + signs mean? You originally said it was plus/minus sign deliminated? Do they throw in minus signs also? Are the numbers ever negative?

    Except for the missing month, it seems that, if you ignore $ signs and plus signs, then the file is space deliminated. Is this true? --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  13. #13
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Databases (VB 6)

    Yep, sure is ugly! The fields are fixed length and I don't know why the + signs show up several spaces after unless the program thats exporting the data is setup to do that. (No minus signs - I misinterpreted the file wrong, my mistake.)There can be no negative numbers in any of the fields.
    I have no clue how to parse the fields out either! [img]/forums/images/smilies/sad.gif[/img]

    Kris

  14. #14
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Databases (VB 6)

    Well, if they are really fixed-length, then it's easy. Check to see if they are really fixed length by trying to open the file in Excel and selecting fixed length records. Can you adjust the widths so that all of the fields come in OK. If so, record the lengths and post them. --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  15. #15
    Lounger
    Join Date
    Apr 2002
    Location
    Ohio US
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Databases (VB 6)

    Ok, now I'm slightly confused. Anyway, I could not get Excel to import the data as fixed length, I had to change it to delimited using the plus sign as the delimiter. If you import as fixed length it seperates all the plus signs into their own columns. (Attached is the spreadsheet)

    Kris
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Posting Permissions

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