in vb anything is treated as string so by default "+" concates two strings. if the operands on both sides are numeric then its ok but if the data is of any other type then it just concates them so to use it as an "addition" operator then you must use the val() function. also the "&" operator is used for concatenation only. example.
suppose we have three textboxes named as TxtFirst TxtSecond TxtThird and a command button. now on click event of command button code as
txtThird.Text = TxtFirst.Text + TxtSecond.Text
this will concated the string in first and second text boxes and shows in third textbox but if you code as txtThird.Text = val(TxtFirst.Text) + val(TxtSecond.Text) then you will get the addition result in ThirdTextbox.
in vb anything is treated as string so by default "+" concates two strings. if the operands on both sides are numeric then its ok but if the data is of any other type then it just concates them so to use it as an "addition" operator then you must use the val() function.
ReplyDeletealso the "&" operator is used for concatenation only.
example.
suppose we have three textboxes named as
TxtFirst TxtSecond TxtThird and a command button.
now on click event of command button code as
txtThird.Text = TxtFirst.Text + TxtSecond.Text
this will concated the string in first and second text boxes and shows in third textbox but if you code as
txtThird.Text = val(TxtFirst.Text) + val(TxtSecond.Text)
then you will get the addition result in ThirdTextbox.