Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Currency Data Type in VB.Net ?

206 views
Skip to first unread message

Mike Higham

unread,
Jan 11, 2003, 2:16:59 PM1/11/03
to
Hi,

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


Dave

unread,
Jan 12, 2003, 8:36:50 PM1/12/03
to
Two things to try:

First:

YourVariable = CDec(Your Input)

If that doesn't work, try setting:

Option Strict Off

Mike Higham

unread,
Jan 13, 2003, 8:12:03 PM1/13/03
to

Thanks Dave, but I don't see how this helps...

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...

Alick [MSFT]

unread,
Jan 13, 2003, 11:43:15 PM1/13/03
to
Since Visual Basic .NET does not support the Visual Basic 6.0 Currency data
type, use the Decimal data type instead for this functionality. If
possible, how about make some modification on the source file before
upgrading to VB.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

Mike Higham

unread,
Jan 14, 2003, 6:46:08 AM1/14/03
to
Thanks Alick,
Unfortunatly, neither of these links have anything useful re upgrading the
Currency data type.

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...

_AnonCoward

unread,
Jan 14, 2003, 11:46:53 AM1/14/03
to
This is a quick note off the top of my head here during a break, so plz
over look any obvious idiocy on my part, but as I recall in vb6 you
cannot declare variables as decimal directly. Instead you declare them
as variants then convert them using the CDec() function. I don't know if
that is relevant, but what the heck.


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

: > | > >
: > | >
: > |
: > |
: > |
: >
:
:


Stephen Weatherford [MSFT]

unread,
Jan 17, 2003, 6:23:35 PM1/17/03
to
As has been noted by others, Currency does not exist in VB.NET. The upgrade
wizard converts the code to use Decimal instead. VB .NET correctly reads in
a Currency value and turns it into a Decimal value when you use a variable
outside of a structure, e.g.:

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...

sldr...@gmail.com

unread,
Jan 29, 2014, 3:38:28 PM1/29/14
to
Hey Mike, I have the exact same issue, were you able to resolve it, if so would you mind sharing the method used?
0 new messages