pl.help me out on this :
i need to calculate balance amount....however...i am not able to calculate it.
C i have coursefees

then when i click on installment 1 and enter the amount my balance amount textbox should reflect
the coursefees- installment1 total

similarly when i click on installment 2 and enter the amount my balance amt textbox should reflect
the coursefees-inst1-inst2 value

similarly when i click on intallment 3 and enter the amount my balance amt textbox should reflect
the coursefees -inst1-inst2-inst3

however i am getting error as cannot convert string "" to double...! i tired a lot but i am not
getting over this error ! Pl help me out soon !

waiting for quick response!

2) can ne one tell me how to validate email id text box....
eg..if @ sign is missing it should prompt(Invalid email id!)

cya
Rohan

Recommended Answers

All 5 Replies

it would be better if you post your code
any way , I think you didn't convert from string to double before calculating,
you wrote like this

Balance.Text = coursefees - installment1.Text

it may work but if user did not enter value and leave the textbox empty then you will have cannot convert string "" to double error
to solve it

Balance.Text = coursefees - CDbl(installment1.Text)

I hope this will help you

The problem you are having concerning "cannot convert string "" to double" is that you have an empty textbox. You need to add code so that if a textbox is blank, then the program does not try to perform a calculation on it. Better yet, add some validation to make sure the text is a number.

For item number two, use the instr() command to see if the "@" character is in the e-mail address. i.e.

If InStr(emailID,"@") > 0 then
emailIDOkay = TRUE
else
emailIDOkay = False
End If

timothybard is right, just Cdbl won't solve it :)

Here's a link to test for a valid email address with regular expression:
http://www.vbforums.com/showthread.php?t=407441
and you should also check:
http://www.regular-expressions.info/email.html
and you'll notice that there's not any bullet-proof method to test email address validity.

Manal answered your first question, but here's a slightly improved version:

If String.IsNullOrEmpty(installment1.Text) Then
  ' Empty value
  Balance.Text = ""
Else
  Try
     Balance.Text = (coursefees - CDbl(installment1.Text)).ToString
  Catch ex As Exception
    ' installment1.Text was not a numerical value
    Balance.Text = ""
  End Try
End If

Oh thanks a lot for your favourable responses !!! I will surely try ur codes....Thanks a lot once again....!

cya
Rohan

Here's a link to test for a valid email address with regular expression:
http://www.vbforums.com/showthread.php?t=407441
and you should also check:
http://www.regular-expressions.info/email.html
and you'll notice that there's not any bullet-proof method to test email address validity.

Manal answered your first question, but here's a slightly improved version:

If String.IsNullOrEmpty(installment1.Text) Then
  ' Empty value
  Balance.Text = ""
Else
  Try
     Balance.Text = (coursefees - CDbl(installment1.Text)).ToString
  Catch ex As Exception
    ' installment1.Text was not a numerical value
    Balance.Text = ""
  End Try
End If
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.