Results 1 to 13 of 13

Thread: Opening and reading files, written by an old VB app.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2020
    Posts
    3

    Opening and reading files, written by an old VB app.

    Hello,

    I have been using vb.net for my small applications for my uni research and personal projects. I usually find the questions by googling or reading the microsoft reference, but it is a first time I am stuck.

    I have a question in regards to opening and reading data from the text files, created by an old VB application (app was created in nineties). I am creating a new VB.net app and want to be able to import or somehow convert those old files into the usable format for my new application.

    The issue is that the files seem to be partially readable. Some text is visible in ANSI encoding, yet some are just random characters (mostly where I expect numbers to be). I tried playing with encodings using Notepad++ and Ultraedit, but with no luck.

    How would one go about reusing files in such situations?

    Any feedback is welcome. Thanks

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Opening and reading files, written by an old VB app.

    1-Welcome to the Forum, V-King!

    2-However, you posted in the wrong section of this Forum...as you are using VB.NET (and not VB6), PROBABLY it should be posted in that section (VB.NET). (I'll ask Moderators to move if appropriate.

    3-BUT, what you are saying is that it is possibly not a Visual Basic (Net or Older) issue at all, but what these 'text' files are actually composed of.

    4-Do you have the 'old VB application' and can open it in Visual Basic 5.0 or 6.0? (Do you have either of these tools?) If so, read the code to determine how these files are created.

    5-Other than that, "I" can offer no other suggestions....maybe some much more intelligent than I may chime in soon.

    Sam
    Sam I am (as well as Confused at times).

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Opening and reading files, written by an old VB app.

    My wild guess would be that you have a DOS-style "random access" file which holds records made up of UDTs.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Opening and reading files, written by an old VB app.

    V_King,

    Yes, welcome to VbForums. And yes, I agree with Sam that you're probably better in the VB.net section of the forums.

    However, you did say one thing that maybe I can help with ... "yet some are just random characters (mostly where I expect numbers to be)". V_King, there are many different ways that VB6 could create data files. However, if I had to guess, I'd think that these data files were written from some kind of "structure" (i.e., user-defined-type, or often called a UDT), and opened-and-written with the "As Binary" option. In these UDTs you can easily mix string (i.e., text) and numeric data. The strings can be either fixed or variable length, and it makes a difference which way that is done. (Also, just as a further FYI, UDT padding is removed when they're done this way.)

    For simplicity (and is often the case), I'll assume the strings are fixed length, and that there are also numbers in the UDT. When done this way, the strings are written as ANSI, floating-point numbers are written as IEEE binary, and integers are written as 2s-compliment binary. Let's take a trivial example:

    Code for Form1:
    Code:
    
    Option Explicit
    
    Private Type test
        a As String * 5
        b As Long
        c As String * 5
    End Type
    
    
    Private Sub Form_Load()
        Dim u As test
        u.a = "asdfg"
        u.b = 45
        u.c = "hijkl"
    
    
        Open "C:\Users\Elroy\Desktop\test.txt" For Binary As 1
        Put #1, 1, u
        Close 1
    
    End Sub
    
    And then, the output file in a hex editor:
    Name:  Bin1.jpg
Views: 361
Size:  23.2 KB

    That's an example with a 2s-compliment long (which takes 4 bytes). Your numbers could also be Integers (which take 2 bytes), or Singles (which take 4 bytes), or Doubles (which take 8 bytes). But, in all cases, those numbers will be binary (non-ANSI). And, when a hex editor tries to interpret them (as text, which is what they typically do), they'll just appear as random funny characters.

    Also, I'm not all that well versed with VB.net, but VB.net should be able to easily read these numbers, as it also "thinks" in 2s-compliment and IEEE encoded floating points.

    Hope That Helps,
    Elroy

    EDIT: Ahhh, Dil posted while I was typing, and beat me to the UDT guess. And yeah, could be either opened as "Binary" or opened as "Random".
    Last edited by Elroy; Jul 11th, 2020 at 08:49 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Opening and reading files, written by an old VB app.

    I moved the thread with a bit of reluctance. I think the answers here were probably pretty useful for understanding the odd characters in the files, which has value. Dealing with UDTs in .NET would be a fairly specialized bit of knowledge.
    My usual boring signature: Nothing

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Opening and reading files, written by an old VB app.

    Assuming this is a UDT file.

    Here is an old thread that has some example code dealing with interacting with UDT's saved to a file with VB.NET. Of course, the first key is knowing the UDT structure. If you happen to have access to the code for the original program, then that is a huge help. If you don't have that, then you have to examine the contents of the file to try to work backwards to figure out the UDT structure. And, as pointed out in the below post, the size (in bytes used) of variables have changed from VB (3,4,5,6) to VB.NET, specifically when it comes to variables like Int and Long.

    https://www.vbforums.com/showthread....n-Visual-Basic

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2020
    Posts
    3

    Re: Opening and reading files, written by an old VB app.

    Thank you very much for all the answers. Some very useful information to get me going.

    Unfortunately, the company, which created the old VB application does not exist.

    I had a suspicion that the numbers are probably binary. I will try googling the UDT. I have experience with micro controller programming in C, and it sounds like it might be easy to figure out, as you do mix in micro controllers different data as well.

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Opening and reading files, written by an old VB app.

    How many files are there? Do they all seem to follow the same format?

    If you upload one of the files, I (or someone else) might be able to write some code that will open the file, read each record, and export the contents into something more easily usable, like a .csv file. And then you could just run that same code against each file.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Opening and reading files, written by an old VB app.

    Can you explain what the data actually represents? I suspect that a bit of trial an error will be required so it might help if people had an idea of what to expect.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Opening and reading files, written by an old VB app.

    If you have the vb6 .exe, there are decompilers... It would be much easier if you can read the original code

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: Opening and reading files, written by an old VB app.

    It would be possible to write almost the exact same file reading code and run it in vb.net, but if you know the structure of the data you’re reading, there are improved coding methods in vb.net...

  12. #12

    Thread Starter
    New Member
    Join Date
    Jul 2020
    Posts
    3

    Re: Opening and reading files, written by an old VB app.

    I know roughly the structure of the files. They all follow the same pattern:
    1. there is a block of headers with various saved settings
    2. a large block of data in columns below.

    In the header there is also a few rows of what looks like a list of whole alphabet symbols and then the list of 0-9 numbers.

    If somebody is up for a challenge, I am happy to e-mail one of the files to have a look. Please pm me.

    Quote Originally Posted by .paul. View Post
    If you have the vb6 .exe, there are decompilers... It would be much easier if you can read the original code
    Thank Paul for the info. Do you know where I could get hold of the vb6.exe to run on windows 10? I've never done de-compiling, but willing to give it a go.
    Last edited by V_King; Jul 14th, 2020 at 07:24 AM.

  13. #13
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

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