View Full Version : VB6 text boxes
Here is the other problem that I had (the first was with printing a form, on a previous thread).
I have several text boxes. I want to put the sum of the contents (numerical) into another textbox.
I can't figure out how to add the contents of textboxes. I have tried many different arangements, different variables... I can multiply the contents but can't add them.
My question is "How do I add the contents of textboxes? (they are on the same form)
neveryona
08-05-2002, 02:06 AM
Private Sub cmdAdd_Click()
Dim int1 As Integer, int2 As Integer, int3 As Integer
int1 = Text1
int2 = Text2
int3 = int1 + int2
Text3 = int3
End Sub
neveryona
08-05-2002, 02:14 AM
Oh, and one other thing, if you are using larger number you can declare them as long as well, or if they are decimal numbers declare them as singles...good luck!:)
Neveryona - Just before I had read your post, I was experimenting with an idea that I had:
Private Sub Command1_Click()
Dim Jim As Integer
Dim Bob As Integer
Dim Tom As Integer
Text2 = Jim
Text3 = Bob
Tom = Jim + Bob
Text4 = Tom
End Sub
Why wouldn't that work? It looks very similar to the code that you posted?
Neveryona - I just tried your code and can't get it to work. I am suspicious of a problem with my instalation of VB6.
neveryona
08-05-2002, 07:21 PM
Did you debug as you go along so that you can see where it is messing up. Also, I was having problems with my vb installation as well. I ended up downloading a service pack for it, that worked very well. You might want to try that. Cna't remember the name of it, but go to their website and you will find it.
This in strange. I just tried it again and it worked fine.
I think that it may be a good idea to get that service pack. I wasn't aaware that VB even had service packs. Is it just at the M$ website?
neveryona
08-06-2002, 12:12 AM
Hi Jes,
http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/dnldoverview.asp
This is the place...
Neveryona,...what is your first name?
Your code works perfectly and I haven't downloaded the service pack yet. What makes the difference? Why didn't my code work but yours did? It was essentially the same, except for the varriables?
Private Sub Command1_Click()
Dim Jim As Integer
Dim Bob As Integer
Dim Tom As Integer
Text2 = Jim
Text3 = Bob
Tom = Jim + Bob
Text4 = Tom
End Sub
I have text 2, 3 and 4 and command1 on my form.
neveryona
08-07-2002, 08:24 PM
Private Sub Command1_Click()
Dim Jim As Integer
Dim Bob As Integer
Dim Tom As Integer
Jim = Text2
Bob = Text3
Tom = Jim + Bob
Text4 = Tom
End Sub
You just had the first two text boxes on the wrong side. The value is placed on the right and goes into object on the left. :D
Ok. That makes sense.
I have:
Private Sub Command1_Click()
Dim one As Currency, Two As Currency, Three As Currency
one = Text1
Two = Text2
Three = one + Two
Text3 = Three
End Sub
My form has Text1,2 and 3 (in Properties the data feild is ###.## for all of them and the data format is currency for all three of them but I put 2.111 in text1 and 3.222 in text2, push the command button to execute the above code and text3 displays 5.333 in it.
How can you get a textbox to display a number as currncy (or a number with 2 decimal places)?
neveryona
08-08-2002, 12:19 PM
one = Text1
Two = Text2
Three = one + Two
text3 = format(Three, "currency")
End Sub
GIve this a try....
And if that doesn't work, change your variables to singles, as then use the format...hope it works...:)
That worked great. Thanks.
neveryona
08-08-2002, 05:45 PM
Glad to help!:cool:
What would you do if you wanted to print a form on a paper that has a letterhead? (so it has to be about 2 inches from the top)
I have done some reading about this and I think that the using the printer object is the only way. Is there another way?
vBulletin v3.6.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.