473,566 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 1705
WB

Where did you get this code?

dim x as long
dim z as integer
x = datetime.now.ti ck

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

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******** ********@TK2MSF TNGP10.phx.gbl. ..
"wb" <none> schrieb:
dim x as long
dim z as integer
x = datetime.now.ti ck

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
3789
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 got to write them in a bmp file (in which RGB values are limited to 8 bits per channel). so i need to have them scaled down. first of all i find...
1
2058
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 data-types of my choosing (eg an array of char, short, or int). The application has to do with generating checksum-type values for files or strings,...
1
3735
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 stored userID,Password,Username to track who has logon/logout, and what actions had performed(add, edit, delete, update etc). now the question who to...
2
5779
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 supported by C#. In this case if I am not mistaken the system performs default marshalling - matching the data types to its most similar equivalent...
5
1221
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 and use this data to generate a number of graphs over time (in real time) of each share price. This means for each share I need to store a price...
13
21640
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 data in the string being sent to the printer. However, if I prompt the user for data or if I insert data from a particular record/field in a form...
5
3393
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 text field. I want to know which Data type I need to use so that it doesnt waste memory. thanks in advance, rAinDeEr
6
2288
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& upLimit) const; private: long double& (T* fn)(T& x);
3
1648
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 transposing during the convertion. My considerations are to either use :- 1.) XSLT initially carry out the converstion so converting some of the data (...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.