|
-
Nov 4th, 2000, 01:42 PM
#1
Thread Starter
Junior Member
I am new to VB and am trying to build a simple loop to add numbers from two text boxes and display the result in a label. For instance, if the user inputs 1 and 5 into two text boxes and then clicks on the sum command button, the code will add 1+2+3+4+5 and display the result in the result label. Can anyone help me with the code?
-
Nov 4th, 2000, 01:49 PM
#2
Member
Is this what your after?
text3 = ""
dim search as integer
for search = val(text1) to val(text2)
text3 = val(text3) + search
next search
-
Nov 4th, 2000, 08:46 PM
#3
Frenzied Member
Almost!!! replace the + with a &, because it are integers it'll add the previous value to the new one.
Code:
text3 = ""
dim search as integer
for search = val(text1) to val(text2)
text3 = val(text3) & search
next search
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 4th, 2000, 09:00 PM
#4
Member
I guess its a matter of interpetation. Mine will produce 15 in text3 while Jop's will produce 12345 in text 3
-
Nov 6th, 2000, 07:29 AM
#5
Difference:
+ = Add strings/get an answer
& = Add to string(s)
(Not just strings...integers/etc. as well)
-
Nov 6th, 2000, 04:56 PM
#6
Addicted Member
A better and more pro answer would have been:
'+' Sum up the two numbers whereas
'&' concatenates them together.
If your a biginner I suggest getting the following book it's very good recomended by my programming teacher.
Tite: Visual Basic 6 How to Program
Author: Deitel & Deitel & Nieto (A father & son book)
It will teach from beginer to intermediate/advance sort of level (covers graphics, database, internet, multimedia as well + more
Also it lists good programming practice, bad programming practice, comon mistakes etc
Top book!!!
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
|