424,972 Members | 901 Online
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

 P: 34 hi all.. how to add numbers i.e 2+2 = 4 , what i get is 2+2= 22... how to code it? :D Sep 20 '07 #1
8 Replies

 P: 95 hi all.. how to add numbers i.e 2+2 = 4 , what i get is 2+2= 22... how to code it? :D do you know what variables are? Sep 20 '07 #2

 Expert 100+ P: 1,295 hi all.. how to add numbers i.e 2+2 = 4 , what i get is 2+2= 22... how to code it? :D if you are working with strings, that's what will happen, if you are working with numeric values, vb will add them: dim a as string dim b as string dim c as string a = "2" b = "2" c= a + b 'c will be 22 if you define them as integer, long, single, doble, etc, the result will be 4 Sep 20 '07 #3

 Expert 5K+ P: 8,434 If you want to get technical, the "+" operator does not add strings, it concatenates them. (After all, what would you expect to happen if you said to print "SMITH" + "JONES" ?) Sep 21 '07 #4

 100+ P: 274 you can add string by using val() function as given below. Its true that + is used to concatenate strings, however you can use this for both purposes. Dim a As String Dim b As String Dim c As String a = "2" b = "3" c = Val(a) + Val(b) Text1.Text = c take care farhana Sep 21 '07 #5

 P: 50 Actually adding a number's in visual basic is a little bit confusing but if you'll know get the logic its easy to add them. Expand|Select|Wrap|Line Numbers Dim sum as double   sum =  Val(txtnum1.text) + Val(txtnum2.text)     The Val will convert the text holding by txtnum1 and txtnum2 to a numeric value. Sep 21 '07 #6

 P: 34 Thanks all .. tried and understood the concept.. but it just wont work.. dunno why....thanks farhana .. that works.. Sep 24 '07 #7

 Expert 5K+ P: 8,434 Thanks all .. tried and understood the concept.. but it just wont work.. dunno why....thanks farhana .. that works.. Just show us your code. No matter how experienced the developer, it usually turns out to be a case of "how could I miss that!". Whoops! Hang on... I'm confused, is the problem resolved or not? Sep 24 '07 #8

 P: 34 Yeap.. problem solved.. muchas gracias..:D Sep 24 '07 #9