Home All Groups Group Topic Archive Search About

Read legacy vb5 files with variant declare in vb.net

Author
6 Oct 2006 9:48 PM
Tracks
I have old legacy code from vb5 where data was written to a file with a
variant declaration  (this was actually a coding error?)...

in vb5 the code was:

            Dim thisdata as integer
            Dim thatdata
            Dim someother as integer

            thatdata = ubound( Array1 )

            Put 1, , thisdata
            Put 1, , thatdata
            Put 1, , someother

So "thatdata" was variant by default, then given an integer by ubound?

Now I need to read the old files created from this code using vb.net. I cant
figure out how to declare the variables.

I have tried declaring all the types I know of ie short, integer, single,
tried strings etc.

In vb.net I use:

            Dim thisdata as short
            Dim thatdata as ?????
            Dim someother as integer

            FileOpen(1, FileName$, OpenMode.Binary, OpenAccess.Read)

            FileGet(1, thisdata )
            FileGet(1, thatdata )
            FileGet(1, someother )

The data is good until thatdata, then everything is junk.

What would the old vb5 code have written in this case? Must have choosen
some format? How can I read it now in vb.net?  I realize the variant was
dropped/changed in .net? But I still need to read the old files.

BTW, this is a simplified version of the actual code/file structure where I
have the problem. I have not tried the above code and not sure it will
duplicate the problem exactly.

It is very important to be able to read these old data files.

Thanks in advance,

Tom

Author
6 Oct 2006 10:57 PM
rowe_newsgroups
>             Dim thatdata as ?????

Dim thatdata as Object

In .NET everything is an object, so you could say that "Object" is now
the hold-all type. And if you were wondering, you no longer need to use
the Set keyword when working with objects. You should then be able to
use DirectCast() to attempt to convert "thatdata" to whatever type you
need.

Thanks,

Seth Rowe

Tracks wrote:
Show quoteHide quote
> I have old legacy code from vb5 where data was written to a file with a
> variant declaration  (this was actually a coding error?)...
>
> in vb5 the code was:
>
>             Dim thisdata as integer
>             Dim thatdata
>             Dim someother as integer
>
>             thatdata = ubound( Array1 )
>
>             Put 1, , thisdata
>             Put 1, , thatdata
>             Put 1, , someother
>
> So "thatdata" was variant by default, then given an integer by ubound?
>
> Now I need to read the old files created from this code using vb.net. I cant
> figure out how to declare the variables.
>
> I have tried declaring all the types I know of ie short, integer, single,
> tried strings etc.
>
> In vb.net I use:
>
>             Dim thisdata as short
>             Dim thatdata as ?????
>             Dim someother as integer
>
>             FileOpen(1, FileName$, OpenMode.Binary, OpenAccess.Read)
>
>             FileGet(1, thisdata )
>             FileGet(1, thatdata )
>             FileGet(1, someother )
>
> The data is good until thatdata, then everything is junk.
>
> What would the old vb5 code have written in this case? Must have choosen
> some format? How can I read it now in vb.net?  I realize the variant was
> dropped/changed in .net? But I still need to read the old files.
>
> BTW, this is a simplified version of the actual code/file structure where I
> have the problem. I have not tried the above code and not sure it will
> duplicate the problem exactly.
>
> It is very important to be able to read these old data files.
>
> Thanks in advance,
>
> Tom
Author
7 Oct 2006 7:06 PM
Tracks
Thanks, I see. But, I tried it previously declaring as object as you suggest,
and I still dont read the value correctly in .net. I know the real thatdata
value is 12. But I read 3. etc. And all values following are a jumble.

I or it dont seem to know what length variable to read, or what kind of
object to be. I need to know what vb5 would have written, what kind of object
was the variant in vb5?? then I can tell .net what to read?



Show quoteHide quote
"rowe_newsgroups" wrote:

> >             Dim thatdata as ?????
>
> Dim thatdata as Object
>
> In .NET everything is an object, so you could say that "Object" is now
> the hold-all type. And if you were wondering, you no longer need to use
> the Set keyword when working with objects. You should then be able to
> use DirectCast() to attempt to convert "thatdata" to whatever type you
> need.
>
> Thanks,
>
> Seth Rowe
>
> Tracks wrote:
> > I have old legacy code from vb5 where data was written to a file with a
> > variant declaration  (this was actually a coding error?)...
> >
> > in vb5 the code was:
> >
> >             Dim thisdata as integer
> >             Dim thatdata
> >             Dim someother as integer
> >
> >             thatdata = ubound( Array1 )
> >
> >             Put 1, , thisdata
> >             Put 1, , thatdata
> >             Put 1, , someother
> >
> > So "thatdata" was variant by default, then given an integer by ubound?
> >
> > Now I need to read the old files created from this code using vb.net. I cant
> > figure out how to declare the variables.
> >
> > I have tried declaring all the types I know of ie short, integer, single,
> > tried strings etc.
> >
> > In vb.net I use:
> >
> >             Dim thisdata as short
> >             Dim thatdata as ?????
> >             Dim someother as integer
> >
> >             FileOpen(1, FileName$, OpenMode.Binary, OpenAccess.Read)
> >
> >             FileGet(1, thisdata )
> >             FileGet(1, thatdata )
> >             FileGet(1, someother )
> >
> > The data is good until thatdata, then everything is junk.
> >
> > What would the old vb5 code have written in this case? Must have choosen
> > some format? How can I read it now in vb.net?  I realize the variant was
> > dropped/changed in .net? But I still need to read the old files.
> >
> > BTW, this is a simplified version of the actual code/file structure where I
> > have the problem. I have not tried the above code and not sure it will
> > duplicate the problem exactly.
> >
> > It is very important to be able to read these old data files.
> >
> > Thanks in advance,
> >
> > Tom
>
>
Author
8 Oct 2006 12:40 AM
rowe_newsgroups
So how is this file formatted? Or could you even post a little of the
file so I could see what is going on? Also what code are you using to
parse the file? Maybe you're casting the object improperly.

Thanks,

Seth Rowe


Tracks wrote:
Show quoteHide quote
> Thanks, I see. But, I tried it previously declaring as object as you suggest,
> and I still dont read the value correctly in .net. I know the real thatdata
> value is 12. But I read 3. etc. And all values following are a jumble.
>
> I or it dont seem to know what length variable to read, or what kind of
> object to be. I need to know what vb5 would have written, what kind of object
> was the variant in vb5?? then I can tell .net what to read?
>
>
>
> "rowe_newsgroups" wrote:
>
> > >             Dim thatdata as ?????
> >
> > Dim thatdata as Object
> >
> > In .NET everything is an object, so you could say that "Object" is now
> > the hold-all type. And if you were wondering, you no longer need to use
> > the Set keyword when working with objects. You should then be able to
> > use DirectCast() to attempt to convert "thatdata" to whatever type you
> > need.
> >
> > Thanks,
> >
> > Seth Rowe
> >
> > Tracks wrote:
> > > I have old legacy code from vb5 where data was written to a file with a
> > > variant declaration  (this was actually a coding error?)...
> > >
> > > in vb5 the code was:
> > >
> > >             Dim thisdata as integer
> > >             Dim thatdata
> > >             Dim someother as integer
> > >
> > >             thatdata = ubound( Array1 )
> > >
> > >             Put 1, , thisdata
> > >             Put 1, , thatdata
> > >             Put 1, , someother
> > >
> > > So "thatdata" was variant by default, then given an integer by ubound?
> > >
> > > Now I need to read the old files created from this code using vb.net. I cant
> > > figure out how to declare the variables.
> > >
> > > I have tried declaring all the types I know of ie short, integer, single,
> > > tried strings etc.
> > >
> > > In vb.net I use:
> > >
> > >             Dim thisdata as short
> > >             Dim thatdata as ?????
> > >             Dim someother as integer
> > >
> > >             FileOpen(1, FileName$, OpenMode.Binary, OpenAccess.Read)
> > >
> > >             FileGet(1, thisdata )
> > >             FileGet(1, thatdata )
> > >             FileGet(1, someother )
> > >
> > > The data is good until thatdata, then everything is junk.
> > >
> > > What would the old vb5 code have written in this case? Must have choosen
> > > some format? How can I read it now in vb.net?  I realize the variant was
> > > dropped/changed in .net? But I still need to read the old files.
> > >
> > > BTW, this is a simplified version of the actual code/file structure where I
> > > have the problem. I have not tried the above code and not sure it will
> > > duplicate the problem exactly.
> > >
> > > It is very important to be able to read these old data files.
> > >
> > > Thanks in advance,
> > >
> > > Tom
> >
> >
Author
8 Oct 2006 3:51 AM
Michael D. Ober
You don't by any chance have 1 and 2 as consecutive characters in your
source data file.  If so, the operation 1 + 2 is ambiguous since the
characters are read from the file as strings and adding two strings can be
done via string concatination.  In VB 6 and earlier, 1 + 2 would normally
return 3, but it could, on occassion, return 12.  In VB 2005, the reverse is
true.

Mike Ober.

Show quoteHide quote
>
> Tracks wrote:
> > Thanks, I see. But, I tried it previously declaring as object as you
suggest,
> > and I still dont read the value correctly in .net. I know the real
thatdata
> > value is 12. But I read 3. etc. And all values following are a jumble.
> >
> > I or it dont seem to know what length variable to read, or what kind of
> > object to be. I need to know what vb5 would have written, what kind of
object
> > was the variant in vb5?? then I can tell .net what to read?
> >
> >
> >
> > "rowe_newsgroups" wrote:
> >
> > > >             Dim thatdata as ?????
> > >
> > > Dim thatdata as Object
> > >
> > > In .NET everything is an object, so you could say that "Object" is now
> > > the hold-all type. And if you were wondering, you no longer need to
use
> > > the Set keyword when working with objects. You should then be able to
> > > use DirectCast() to attempt to convert "thatdata" to whatever type you
> > > need.
> > >
> > > Thanks,
> > >
> > > Seth Rowe
> > >
> > > Tracks wrote:
> > > > I have old legacy code from vb5 where data was written to a file
with a
> > > > variant declaration  (this was actually a coding error?)...
> > > >
> > > > in vb5 the code was:
> > > >
> > > >             Dim thisdata as integer
> > > >             Dim thatdata
> > > >             Dim someother as integer
> > > >
> > > >             thatdata = ubound( Array1 )
> > > >
> > > >             Put 1, , thisdata
> > > >             Put 1, , thatdata
> > > >             Put 1, , someother
> > > >
> > > > So "thatdata" was variant by default, then given an integer by
ubound?
> > > >
> > > > Now I need to read the old files created from this code using
vb.net. I cant
Show quoteHide quote
> > > > figure out how to declare the variables.
> > > >
> > > > I have tried declaring all the types I know of ie short, integer,
single,
> > > > tried strings etc.
> > > >
> > > > In vb.net I use:
> > > >
> > > >             Dim thisdata as short
> > > >             Dim thatdata as ?????
> > > >             Dim someother as integer
> > > >
> > > >             FileOpen(1, FileName$, OpenMode.Binary, OpenAccess.Read)
> > > >
> > > >             FileGet(1, thisdata )
> > > >             FileGet(1, thatdata )
> > > >             FileGet(1, someother )
> > > >
> > > > The data is good until thatdata, then everything is junk.
> > > >
> > > > What would the old vb5 code have written in this case? Must have
choosen
> > > > some format? How can I read it now in vb.net?  I realize the variant
was
> > > > dropped/changed in .net? But I still need to read the old files.
> > > >
> > > > BTW, this is a simplified version of the actual code/file structure
where I
> > > > have the problem. I have not tried the above code and not sure it
will
> > > > duplicate the problem exactly.
> > > >
> > > > It is very important to be able to read these old data files.
> > > >
> > > > Thanks in advance,
> > > >
> > > > Tom
> > >
> > >
>
>
Author
8 Oct 2006 2:32 PM
Tracks
Michael,

I dont think so. But there are many data files to read that could have
anything in them.

See my other earlier post from today for an example you can duplicate.






Show quoteHide quote
"Michael D. Ober" wrote:

> You don't by any chance have 1 and 2 as consecutive characters in your
> source data file.  If so, the operation 1 + 2 is ambiguous since the
> characters are read from the file as strings and adding two strings can be
> done via string concatination.  In VB 6 and earlier, 1 + 2 would normally
> return 3, but it could, on occassion, return 12.  In VB 2005, the reverse is
> true.
>
> Mike Ober.
>
> >
> > Tracks wrote:
> > > Thanks, I see. But, I tried it previously declaring as object as you
> suggest,
> > > and I still dont read the value correctly in .net. I know the real
> thatdata
> > > value is 12. But I read 3. etc. And all values following are a jumble.
> > >
> > > I or it dont seem to know what length variable to read, or what kind of
> > > object to be. I need to know what vb5 would have written, what kind of
> object
> > > was the variant in vb5?? then I can tell .net what to read?
> > >
> > >
> > >
> > > "rowe_newsgroups" wrote:
> > >
> > > > >             Dim thatdata as ?????
> > > >
> > > > Dim thatdata as Object
> > > >
> > > > In .NET everything is an object, so you could say that "Object" is now
> > > > the hold-all type. And if you were wondering, you no longer need to
> use
> > > > the Set keyword when working with objects. You should then be able to
> > > > use DirectCast() to attempt to convert "thatdata" to whatever type you
> > > > need.
> > > >
> > > > Thanks,
> > > >
> > > > Seth Rowe
> > > >
> > > > Tracks wrote:
> > > > > I have old legacy code from vb5 where data was written to a file
> with a
> > > > > variant declaration  (this was actually a coding error?)...
> > > > >
> > > > > in vb5 the code was:
> > > > >
> > > > >             Dim thisdata as integer
> > > > >             Dim thatdata
> > > > >             Dim someother as integer
> > > > >
> > > > >             thatdata = ubound( Array1 )
> > > > >
> > > > >             Put 1, , thisdata
> > > > >             Put 1, , thatdata
> > > > >             Put 1, , someother
> > > > >
> > > > > So "thatdata" was variant by default, then given an integer by
> ubound?
> > > > >
> > > > > Now I need to read the old files created from this code using
> vb.net. I cant
> > > > > figure out how to declare the variables.
> > > > >
> > > > > I have tried declaring all the types I know of ie short, integer,
> single,
> > > > > tried strings etc.
> > > > >
> > > > > In vb.net I use:
> > > > >
> > > > >             Dim thisdata as short
> > > > >             Dim thatdata as ?????
> > > > >             Dim someother as integer
> > > > >
> > > > >             FileOpen(1, FileName$, OpenMode.Binary, OpenAccess.Read)
> > > > >
> > > > >             FileGet(1, thisdata )
> > > > >             FileGet(1, thatdata )
> > > > >             FileGet(1, someother )
> > > > >
> > > > > The data is good until thatdata, then everything is junk.
> > > > >
> > > > > What would the old vb5 code have written in this case? Must have
> choosen
> > > > > some format? How can I read it now in vb.net?  I realize the variant
> was
> > > > > dropped/changed in .net? But I still need to read the old files.
> > > > >
> > > > > BTW, this is a simplified version of the actual code/file structure
> where I
> > > > > have the problem. I have not tried the above code and not sure it
> will
> > > > > duplicate the problem exactly.
> > > > >
> > > > > It is very important to be able to read these old data files.
> > > > >
> > > > > Thanks in advance,
> > > > >
> > > > > Tom
> > > >
> > > >
> >
> >
>
>
>
>
Author
8 Oct 2006 3:33 PM
Michael D. Ober
Tracks,

Something that might help is to put the following statements at the top of
the code file:

Option Explicit On      ' Require variable declaration
Option Strict On         ' Enforce Type Safety

With these two statements, the VB 2005 compiler will refuse to compile
ambiguous code such as

dim a
dim b
dim c

c = a + b

You'll get an error on the addition that you will need to resolve before you
can compile.

Mike.


Show quoteHide quote
"Tracks" <Tra***@discussions.microsoft.com> wrote in message
news:BDD279B1-C03C-4F3A-88F9-346D620E2662@microsoft.com...
> Michael,
>
> I dont think so. But there are many data files to read that could have
> anything in them.
>
> See my other earlier post from today for an example you can duplicate.
>
>
>
>
>
>
> "Michael D. Ober" wrote:
>
> > You don't by any chance have 1 and 2 as consecutive characters in your
> > source data file.  If so, the operation 1 + 2 is ambiguous since the
> > characters are read from the file as strings and adding two strings can
be
> > done via string concatination.  In VB 6 and earlier, 1 + 2 would
normally
> > return 3, but it could, on occassion, return 12.  In VB 2005, the
reverse is
> > true.
> >
> > Mike Ober.
> >
> > >
> > > Tracks wrote:
> > > > Thanks, I see. But, I tried it previously declaring as object as you
> > suggest,
> > > > and I still dont read the value correctly in .net. I know the real
> > thatdata
> > > > value is 12. But I read 3. etc. And all values following are a
jumble.
> > > >
> > > > I or it dont seem to know what length variable to read, or what kind
of
> > > > object to be. I need to know what vb5 would have written, what kind
of
> > object
> > > > was the variant in vb5?? then I can tell .net what to read?
> > > >
> > > >
> > > >
> > > > "rowe_newsgroups" wrote:
> > > >
> > > > > >             Dim thatdata as ?????
> > > > >
> > > > > Dim thatdata as Object
> > > > >
> > > > > In .NET everything is an object, so you could say that "Object" is
now
> > > > > the hold-all type. And if you were wondering, you no longer need
to
> > use
> > > > > the Set keyword when working with objects. You should then be able
to
> > > > > use DirectCast() to attempt to convert "thatdata" to whatever type
you
> > > > > need.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Seth Rowe
> > > > >
> > > > > Tracks wrote:
> > > > > > I have old legacy code from vb5 where data was written to a file
> > with a
> > > > > > variant declaration  (this was actually a coding error?)...
> > > > > >
> > > > > > in vb5 the code was:
> > > > > >
> > > > > >             Dim thisdata as integer
> > > > > >             Dim thatdata
> > > > > >             Dim someother as integer
> > > > > >
> > > > > >             thatdata = ubound( Array1 )
> > > > > >
> > > > > >             Put 1, , thisdata
> > > > > >             Put 1, , thatdata
> > > > > >             Put 1, , someother
> > > > > >
> > > > > > So "thatdata" was variant by default, then given an integer by
> > ubound?
> > > > > >
> > > > > > Now I need to read the old files created from this code using
> > vb.net. I cant
> > > > > > figure out how to declare the variables.
> > > > > >
> > > > > > I have tried declaring all the types I know of ie short,
integer,
> > single,
> > > > > > tried strings etc.
> > > > > >
> > > > > > In vb.net I use:
> > > > > >
> > > > > >             Dim thisdata as short
> > > > > >             Dim thatdata as ?????
> > > > > >             Dim someother as integer
> > > > > >
> > > > > >             FileOpen(1, FileName$, OpenMode.Binary,
OpenAccess.Read)
> > > > > >
> > > > > >             FileGet(1, thisdata )
> > > > > >             FileGet(1, thatdata )
> > > > > >             FileGet(1, someother )
> > > > > >
> > > > > > The data is good until thatdata, then everything is junk.
> > > > > >
> > > > > > What would the old vb5 code have written in this case? Must have
> > choosen
> > > > > > some format? How can I read it now in vb.net?  I realize the
variant
> > was
> > > > > > dropped/changed in .net? But I still need to read the old files.
> > > > > >
> > > > > > BTW, this is a simplified version of the actual code/file
structure
> > where I
> > > > > > have the problem. I have not tried the above code and not sure
it
> > will
> > > > > > duplicate the problem exactly.
> > > > > >
> > > > > > It is very important to be able to read these old data files.
> > > > > >
> > > > > > Thanks in advance,
> > > > > >
> > > > > > Tom
> > > > >
> > > > >
> > >
> > >
> >
> >
> >
> >
>
Author
8 Oct 2006 2:30 PM
Tracks
Thanks for looking. Ok, I made an example. I am using VB6 as I dont have VB5
installed but I am duplicating the problem with this simple code:

***********
The VB6 code (make a form with two buttons and you can read and write the
file):


Dim variable1 As Integer
Dim variable2 As Integer
Dim variable3
Dim variable4 As Integer

Private Sub Form_Load()

    Dim anarray(9) As String

    variable1 = 1
    variable2 = 2
    variable3 = UBound(anarray)
    variable4 = 4


End Sub

Private Sub WriteCommand1_Click()

            Open "c:\tomtemp\test1.dat" For Binary Lock Read Write As 1

            Put 1, , variable1
            Put 1, , variable2
            Put 1, , variable3
            Put 1, , variable4

    Close

End Sub

Private Sub ReadCommand2_Click()

            Open "c:\tomtemp\test1.dat" For Binary Lock Read Write As 1

            Get 1, , variable1
            Get 1, , variable2
            Get 1, , variable3
            Get 1, , variable4

    Close

End Sub




********************
the vb.net code:


    Dim variable1 As Short
    Dim variable2 As Short
    Dim variable3
    Dim variable4 As Short

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load


        FileOpen(1, "c:\tomtemp\test1.dat", OpenMode.Binary, OpenAccess.Read)

        FileGet(1, variable1)
        FileGet(1, variable2)
        FileGet(1, variable3)
        FileGet(1, variable4)



        FileClose(1)


    End Sub


***************************


Put whatever after the variable3 delare and watch the value of variable 3
(or error), which should be "9". I give the variable3 a value using ubound
since that is what happens in the original, not sure if it matters. It should
make variable3 an integer? But .....as you can see... waaaa?

Thanks again,

Tom