Hello everyone!

I'm writing my third program and it's running and the math formula's are working great, however, I just had a few questions.

I'm trying to use hours = CDbl(txtHours.Text) but when I start the program I get a conversion from string "" to type 'Double" is not valid...but I declared hours As a Double not a string. The program still runs and works fine, but just with that beginning error box.

Also, I have three radio buttons that represent 3 internet packages. After the user enters how many hours they have used the internet for the month, they click on a radio button and it calculates how much they owe. However, I'm finding that the first radio button representing the first package in the group is always selected at the start of the program so it displays the total right off the bat forcing the user to enter the number of hours and then click on another package just to click back to the first package that was already selected at the beginning of the program. I tried adding

rdoPackageA.Checked = False


to the beginning of the program but the radio button was still selected. I then moved them to the constructor and it didn't have any effect, the first radio button was still pre-selected.

When I added this statement and two others to clear the other radio buttons to my clear button, it works fine and clears the previous selection from the radio buttons so the user can enter a new hour figure and click on which package he wants.

Any help would be appreciated....thanks!

BTW, I'm using VB9 if that helps. :)

I get a conversion from string "" to type 'Double"

How can you convert this " " to double ?? you should before conversion check if the textbox contains non-text value.

to the beginning of the program but the radio button was still selected. I then moved them to the constructor and it didn't have any effect, the first radio button was still pre-selected.

From RadioButton control properties, change Checked property to False.

Hi there,

I've checked in the properties for all of the radio buttons and checked is already set to false.

Also, I made sure in the hours text box properties that nothing is already entered into text before the program runs, it's completely blank.

Yes my friend if it's blank so we can't convert blank value to double!!
If the textbox value is blank don't perform CDbl(string)!!
I've dropped a lot of radio buttons and run. The form drawn and no radio button being selected.

Ok thanks for the help.

:)

I ended up using TryParse to both store and validate hours.

'store data in variable amd validate it
If Double.TryParse(txtHours.Text, hours) Then
txtError.Text = "Success!"
Else
txtError.Text = "Error value must be numeric."

End If

Even though it's solved, another solution to this would have been to set the value of the textbox to 0 by default (such as in form load)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.