Can't divide a type UInt64

K

Kevin

Dim X as int32
Dim Y as int64

X = Y / 1024

gives me the error:
"Operator is not valid for type 'UInt64' and type 'Integer'."

I'm new to VB.NET and this is one of the reasons why I've resisted so
long. I've tried Dimming X as Int64 and integer. What do I have to
do to divide this stinkin' number?
 
C

Chris, Master of All Things Insignificant

Well your error message and your code don't match up. I think you ment to
type
Dim X as int32
Dim Y as UInt64

You need to convert these to Int64 types. Why are you using the UInt64?
I've never used them myself so I don't know why you would need to use them.
This code should work though.

Dim X as Double
Dim Y as UInt64
'Set Y to something here
X = Convert.ToDouble(Y)/1024

hope it helps
Chris
 
H

Herfried K. Wagner [MVP]

Kevin said:
Dim X as int32
Dim Y as int64

X = Y / 1024

gives me the error:
"Operator is not valid for type 'UInt64' and type 'Integer'."

I assume you are using 'UInt64' instead of 'Int64'. VB 2002/2003 do not
support unsigned datatypes out of the box, and unsigned datatypes are not
CLS-compliant (in VB 2005 unsigned types will be supported). If possible,
use unsigned datatypes.
 
K

Kevin

I'm actually using WMI to get computer information on the workstations
on our network.

Win32_PhysicalMemory returns the "Capacity" property that is in UInt64
form. I'm trying to divide to convert it to MB.
 
H

Herfried K. Wagner [MVP]

Kevin said:
I'm actually using WMI to get computer information on the workstations
on our network.

Win32_PhysicalMemory returns the "Capacity" property that is in UInt64
form. I'm trying to divide to convert it to MB.

This cannot be done using VB.NET. You may either want to do that in C# or
use p/invoke to format the number of bytes to a human-readable string, if
you want to display it to the user:

C# code:

\\\
ulong Bytes = ...;
long Megabytes = (long)(i / 1024);
///

Formatting a number of bytes to a string with unit
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=formatbytes&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top