473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Read legacy vb5 files with variant declare in vb.net

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
Oct 6 '06 #1
7 2107
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
Oct 6 '06 #2
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

Oct 7 '06 #3
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:
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
Oct 8 '06 #4
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
>
>



Oct 8 '06 #5
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

Oct 8 '06 #6
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

Oct 8 '06 #7
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.
"Tracks" <Tr****@discussions.microsoft.comwrote in message
news:BD**********************************@microsof t.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
>
>
>
>



Oct 8 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lloyd | last post by:
I'm currently creating the next version of our company's education product, and it seems that we still need to support legacy hardware & software (Win 95/Pentium-1, MacOS 8). To that end, we've been...
12
by: deko | last post by:
Is there a quick and dirty way to delete all files in a given directory? perhaps something like this: Set objFile = CreateObject("Scripting.FileSystemObject") objFile.DeleteFile "all files in...
16
by: ben beroukhim | last post by:
I have huge number of legacy code which use standard files functions. I would like to pass a memory pointer rather than a FILE pointer. I am trying to use FILEs in the code to refer to memory...
3
by: Dave Coate | last post by:
Hello again, I am going to re-post a question. I got some excellent suggestions from Rob and Mattias on this but their ideas did not solve the problem. Here is the original post: ...
0
by: Mark Raishbrook | last post by:
I'm writing an app that controls a Bluefish444 video capture card. One of the members of its COM interface is GetAnalogCardProperty(ByVal propType As Integer, ByRef propValue As Object). That...
6
by: sghi | last post by:
Hi All, I'm new to this group and quite new to access/vba. So, shortly after beginning to write a simple application for my wife, I came across a blocking problem: I need to intercept the sql...
2
by: Heike | last post by:
Hello everybody, I have a Problem with C Sharp. I have to use external functions in DLLs. This Functions are written in Visual C++ 6 like this: int (__stdcall *GetGlobalValue) (VARIANT Appl,...
1
NeoPa
by: NeoPa | last post by:
This can be built on, but I've not needed to so far. This is used in my database(s) and stored as modOS. Option Compare Database Option Explicit Public Const conHKCR = &H80000000 Public...
1
by: smugcool | last post by:
hi, i am creating a form with a text field and two command buttons in vb 6.0 I want when somebody will click on command1 button a path will be shown in the text field. And for second command...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.