What Is CDbl Doing

Apr 16, 2010

I had until recently been under the impression that the CDbl(x) operation in VB.NET was essentially a cast (i.e., the VB equivalent of (double)x in C#); but a recent discovery has revealed that this is not the case.[code]d will be set to the value -12345.12345! Now, don't get me wrong, this is kind of convenient in my particular scenario; but I have to admit I'm confused as to why this works. In particular, I'm confused because:[code]How is CDbl so clever?

View 3 Replies


ADVERTISEMENT

When To Use CDbl And CStr Functions Using VB

Jan 26, 2012

I'm learning to use this program and I'm a few weeks into learning it and I'm understanding most of it fine, but I just cannot get a grasp on when to use CDbl, CInt, CStr etc. functions. Here's an example of a few lines of code I can't get a grasp of:

If IsNumeric(txtFirst.Text) And IsNumeric(txtSecond.Text) Then
txtSum.Text = CStr(CDbl(txtFirst.Text) + CDbl(txtSecond.Text))

This program is supposed to take 2 numbers that are inputted by the user and add them together. simple. I was playing around with it, and I took out the CDbl and CStr functions, and the 2 numbers that were supposed to be added together were only added side by side (ex. If I input 2 and 15 as my numbers it would spit out 215).

So I'm curious when to use these functions.

My first nagging question is, how come on the second line, it says CStr(CDbl(? Why would I need to convert to double, THEN to string? which is my understanding, unless I am reading this wrong.

Another question I have is, if I declare var1 as Dim var1 as Double I constantly see the next line as var1 = CDbl(txtbox.text) and so on. I don't understand why we need to convert to Double here, since when I declared the variable as a double, it should already be in a double form already, shouldn't it?

View 2 Replies

VS 2005 Select All Fields And Cdbl For One?

Nov 28, 2009

I am using the following code to get all my database fields, I would like to convert one of the fields to Cdbl, not sure how to do that

Dim comm As New OleDb.OleDbCommand("Select * From " & Me.OpenFileDialog1.SafeFileName & " Where Status <> 'S'", con)

I know how to individually do it field by field but i dont want to have to write a select for each field if that makes sense?

Dim comm2 As New OleDbCommand("Select Cdbl([Selling Price]) as SoldPrice, Status From " & Me.OpenFileDialog1.SafeFileName & " Where Status = 'S'", con)

So something that pulls ALL fields and converts one

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved