I need to read sime Random Access files created by VB6
Some of these records include Currency data fields.
There is no Currency type in VB.net, onlt Decimal.
When I try to GET a VS6 record in VB.net that contains Currency data, I get
an error to the effect that the Scale factor for the Decimal type is
invalid.
Is there any way to get a currency type in VB .net?
Or, do I have to write VB6 programs to extract all the data I have into some
intermediate file (say .CSV) then write a VB.net program to re-create all
the files?
I can see the sense in MS designing .Net from the ground-up, and largely
ignoring compatibility, but I don't see why it would cause any issues to
support the odd legacy data type??
Mike
First:
YourVariable = CDec(Your Input)
If that doesn't work, try setting:
Option Strict Off
In VB6, I created some ramdom access files e.g. (Simplified and
hypothetical)
-----------------------------------------
Type AcBalance
strAcNo As String * 6
curBalance As Currency
End Type
Sub Main
Dim recAc as AcBalance
Open "MYDATA.DAT" for Random Access As #1 Len=Len(recAc)
strAcNo = "123456"
curBalance = 1234.56
PUT #1, 123456, recAc
Close #1
End Sub
-----------------------------------------------------------
So in the file "MYDATA,DAT, I have a record consisting of six characters,
followed by an 8 byte integer value, (which VB6 calls currency, and
implicitly treats as scaled by 1000)
Now, when I want to read the same file in VB .NET, I have to define a
structure for the record. Then string is no problem, but how do I define the
currency field?
VB6 "currency" is an 8 byte floating value (implicitly multiplied by 1000 to
give an ineger) VB .NET seems to have no equivalent?
The nearest I can see is the Decimal type, but IIRC that's a 10 byte field.
That would make a nonsense of my recordsize, not to mention the value of the
field...
That said, although a daft way around the problem, - thinking as I type -
perhaps I could code currency fields as Int64 variables, at least they'd be
the same size (8 bytes) .... At least then I'd only need to worry about
explicitly handling the scaling factor.(Asuming there's no issues with
Big/Little Endian)
I'll have to give it a try, but as I said before, it seems damn daft of MS
to make it difficult (maybe impossinble) to properly read a data file
created by other programming languages.
Mike
"Dave" <nl...@nospam.cox.net> wrote in message
news:3e2217bf...@news.east.cox.net...
"Things to Consider Before Upgrading"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconthingstoconsiderbeforemigrating.asp
Language Recommendations for Upgrading
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconlanguagerecommendations.asp
Sincerely,
Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Mike Higham" <michael.higham@_SPAMBLOCK_.virgin.net>
| References: <#u7xAdcuCHA.1960@TK2MSFTNGP11>
<3e2217bf...@news.east.cox.net>
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb.upgrade
Even if I want to write a one-off program to convert all my data files, how?
In VB6 I can see no way that I can write a record to file that contains
Decimal fields - VB6 does NOT have a Decimal type AFAIK.
I seems to me that the only way round this is to write VB6 programs to
unload all my data files into, perhaps text files, then write VB.Net
programs to re-load the data, that's just pain daft.
This also means I have to upgrade an entire suite of programs at once, VB6
and VS.Net have no sensible common data type for money amounts. So, there is
no way VB6 and VS.Net programs can share any data.
Surely this is a serious design failure in .Net.
That said, I've just done a quick test using the Int64 type to map to my
Currency types. At least the record length is correct now. Not so sure about
the actual data - at a glance some looks Ok, just 1000 times the expected
currency value - some looks strange, with large negative values - further
investigation required.
Mike
"Alick [MSFT]" <al...@online.microsoft.com> wrote in message
news:U$Lyqd4uCHA.1872@cpmsftngxa06...
Also, bear in mind that VB.net does not support unsigned integers. Could
that be causing some of your values to appear as negative values? If so,
would C# better server your needs here?
Ralf Thompson at carolina dot rr dot com
"Mike Higham" <michael.higham@_SPAMBLOCK_.virgin.net> wrote in message
news:#Vd8AK8uCHA.616@TK2MSFTNGP11...
: Thanks Alick,
: > vbconthingstoconsiderbeforemigrating.asp
: >
: > Language Recommendations for Upgrading
: >
:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/h
tml/
: > vbconlanguagerecommendations.asp
: > | > >
: > | >
: > |
: > |
: > |
: >
:
:
Dim c As Decimal
FileGet(1, c)
However, it appears to have problems when reading in a Currency value that
is part of a structure. I have noted this problem and we will investigate
whether this can be fixed for a future version of VB.
In the meantime, here are two possibilities for you:
1) read in the currency values separately (instead of reading it in as part
of a structure), or
2) read in the currency value as an Int64 value, and then use
Decimal.FromOACurrency() to convert from the Int64 value to the proper
Decimal value. Note that the same problem occurs for writing out the
currency in a structure as well, so if you need to keep your output file
compatible, then you need to use Decimal.ToOACurrency() to get a Int64
value and write that out instead of the decimal value to keep it compatible
with VB6 apps.
Stephen Weatherford, Microsoft
VB Team
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mike Higham" <michael.higham@_SPAMBLOCK_.virgin.net> wrote in message
news:urW4Fr2uCHA.2280@TK2MSFTNGP11...