473,386 Members | 1,821 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.

data converstion from long to int

wb
Newbie at .net having trouble with data conversion.

I am using the random constructor and trying to pass in seed value of time
as instructed by help.

rvalue = new random(int)

dim x as long
dim z as integer
x = datetime.now.tick

z = int(x)

when the coversion takes place an exception error is thrown. maybe it isn't
possible to convert a long to an int. But that is what the constructor
takes and the help says that time is a good value to pass in.

suggestions?

WB
Dec 4 '05 #1
4 1696
WB

Where did you get this code?

dim x as long
dim z as integer
x = datetime.now.tick

z = int(x)

It should be in VB.Net
\\\
Dim x As Long = Now.Ticks
Dim z As Integer = CInt(x)
///
I hope this helps,

Cor
Dec 4 '05 #2
"wb" <none> schrieb:
dim x as long
dim z as integer
x = datetime.now.tick

z = int(x)

when the coversion takes place an exception error is thrown. maybe it
isn't possible to convert a long to an int. But that is what the
constructor takes and the help says that time is a good value to pass in.


'Int' will return a floating point number. It's typically get used to
remove the fractional part of a number. You may want to use 'CInt' instead
which will perform a type conversion. Note that this conversion will fail
if 'Ticks'' value cannot be represented in an 'Integer'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 4 '05 #3
wb
I have tried all possible combinations of data conversion; all with the same
outcome. The exception gets thrown when the Random constructor takes a seed
parameter such as Cint(Now.Tick). As you state "...the conversion will fail
if "Ticks" value cannot be represented in an Integer" how am I supposed to
pass in the value? The MSDN documentation on Random() uses the code I am
trying to replicate.

WB

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ez****************@TK2MSFTNGP10.phx.gbl...
"wb" <none> schrieb:
dim x as long
dim z as integer
x = datetime.now.tick

z = int(x)

when the coversion takes place an exception error is thrown. maybe it
isn't possible to convert a long to an int. But that is what the
constructor takes and the help says that time is a good value to pass in.


'Int' will return a floating point number. It's typically get used to
remove the fractional part of a number. You may want to use 'CInt'
instead which will perform a type conversion. Note that this conversion
will fail if 'Ticks'' value cannot be represented in an 'Integer'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 5 '05 #4

wb wrote:
I have tried all possible combinations of data conversion; all with the same
outcome. The exception gets thrown when the Random constructor takes a seed
parameter such as Cint(Now.Tick). As you state "...the conversion will fail
if "Ticks" value cannot be represented in an Integer" how am I supposed to
pass in the value? The MSDN documentation on Random() uses the code I am
trying to replicate.


Maybe you'd want to "mask" just the least-significant 32 bits (that is,
the bits that change more often) from the value returned by Now.Ticks
before performing the conversion:

Dim Seed As Integer = CInt(Now.Ticks And &HFFFFFFFF)

HTH.

Regards,

Branco.

Dec 5 '05 #5

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

Similar topics

8
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i...
1
by: J. Campbell | last post by:
I have a feeling that I'm doing things all ass-backwards (again ;-), and would like some advice. What I want to do is: put some data to memory and then access that memory space as an array of...
1
by: Shahzad | last post by:
Dear Respected Gurus/Sirs, I would like to share your ideas and get reviews will be highly appreciated in anticipation Question No.1 I had developed a seprate audit/security database that...
2
by: Rookie | last post by:
Hi, I had a question on DllImport. On importing a function from a VC++ dll using DllImport (to a C# program), the function argument data types and the return types may be of a type that is not...
5
by: Mike | last post by:
Hi, I'm new to vb.net and would be grateful if anyone could offer some advice on the best way to approach this problem: I wish to dynamically capture pricing information e.g. 10 stock prices...
13
by: Susan Beebe | last post by:
I have downloaded the code described in Microsoft article Q154078. I am trying to send raw ZPL (zebra barcode printer) code from Microsoft access. It works just fine if I hard code the actual...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
6
by: Protoman | last post by:
Can you have a function pointer as a data member? Like: template <class T> class Integrate { public: Integrate(long double& (T* f)(T& x)):fn(f){} long double& operator()(T& lowLimit, T&...
3
by: =?Utf-8?B?Q2Fpcm4=?= | last post by:
I have some XML data which I wish to relate to existing classes, but data does not map exactly so serialsation will not work, the other consideration is that some of the XML data will need...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.