|
-
Mar 31st, 2006, 01:25 AM
#1
Thread Starter
New Member
CDbl? What is it?
Hi, I'm trying to create an inputbox for uiJob1TextBox, uiJob2TextBox, and uiJob3TextBox. This way the user will be asked to enter a number for each textbox. Now I have my code:
VB Code:
Const RaisePercentage As String = "Raise Percentage: "
Dim job1HP As Double, job2HP As Double, job3HP As Double
Dim job1NewHP As Double, job2NewHP As Double, job3NewHP As Double
Dim raisePercent As Double
Try
job1HP = CDbl(uiJob1TextBox.Text)
job2HP = CDbl(uiJob2TextBox.Text)
job3HP = CDbl(uiJob3TextBox.Text)
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical)
uiJob1TextBox.Focus()
Exit Sub
End Try
Do
Try
raisePercent = CDbl(InputBox("Please enter the raise percentage.", "Raise Percentage")) / 100
Exit Do
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical)
End Try
I'm trying to understand what CDbl is? Because I'm thinking if i use the 'Try' statement and make job1HP equal to something else that contains in (uiJob1Textbox)
That then I can create a raisePercent= "blah" code which will allow me to enter a InputBox for the three textboxes. Anyone have any suggestions or what
CDbl means and if I can use a different expression so this way I can have expression A equal uiJobTextbox, expression B equal textbox2, and expression C equal textbox3.
Thanks!
-
Mar 31st, 2006, 01:33 AM
#2
Re: CDbl? What is it?
CDbl() = Convert.ToDouble()
In this case it's ok as your variables are declared as Double
-
Mar 31st, 2006, 01:36 AM
#3
Thread Starter
New Member
Re: CDbl? What is it?
Oh Ok, So any idea how I Could create an inputbox message allowing the user to enter data into each of the three textboxes separately?
-
Mar 31st, 2006, 01:43 AM
#4
Thread Starter
New Member
Re: CDbl? What is it?
I think I'm close, I'm trying to enter
VB Code:
Try
job1HP = CDbl(uiJob1TextBox.Text)
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical)
uiJob1TextBox.Focus()
Exit Sub
End Try
Do
Try
raisePercent = CDbl(InputBox("Please enter the raise percentage for Job 1.", "Raise Percentage")) / 100
Exit Do
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical)
End Try
As separate "Try-Catch" statements. Will this work? It looks like it could.
-
Mar 31st, 2006, 02:01 AM
#5
Re: CDbl? What is it?
You shouldn't be using CDbl like that. It is bad practice to just force a conversion and then clean up the mess if it fails. You should only use CDbl if you know for a fact that the value is, or can be converted to, a Double. You should be using Double.TryParse as it does not throw an exception if the converson fails, e.g.
VB Code:
Dim myDouble As Double
If Double.TryParse(myString, Globalization.NumberStyles.Float, Nothing, myDouble) Then
'The conversion was successful and the value was stored in myDouble.
Else
'The conversiuon failed.
End If
If you're using 2005 (which you haven't specified, please use the radio buttons provided when starting threads in future) you can omit the second and third parameters.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|