Page 1 of 1

Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Sat Feb 11, 2006 12:23 am
by Brodie
Today, 08:11 PM #1
Montrèal


Posts per day: 0.30 Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

--------------------------------------------------------------------------------

Private Sub Command1_Click()
Dim a, b, c As Double
a = Text6.Text
b = Text10.Text

c = a + b
Text6.Text = c
End Sub

I know I am doing something wrong but for the life of me I can`t remember.This is a very simple application its to add the new Points for to the old points for in the database.Heres the problem the points for is at 22 .I want to add 5 more points which = 27.The problem is it gives me 225 it just adds the 25 to the end of the statement.
I know as soon as someone tells me the right way it will probably click but till then I am stopped.


RE: Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Sat Feb 11, 2006 1:15 am
by WYBaugh
Hey Broday,

You need to convert the two text fields to doubles. Try:

Dim a, b, c As Double

a = Val(Text1.Text)
b = Val(Text2.Text)
c = a + b

Text3.Text = Str(c)

Bill

RE: Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Sat Feb 11, 2006 2:19 am
by Brodie
Dim a, b, c As Double

a = Val(Text1.Text)
b = Val(Text2.Text)
c = a + b

Text3.Text = Str(c)

Thanks Bill

RE: Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Wed Feb 15, 2006 3:54 pm
by QBPR
I'm always amazed at any language that lets you implicitly convert datatypes on the fly without throwing a compile error. Ick.

RE: Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Wed Mar 08, 2006 2:41 pm
by NCrawler
WBaugh has a good solution, but one thing I would like to point out is that you need to implicitly declare your variables. Your statement: Dim a, b, c as Double is actually dimensioning a and b as variants and c as a double, change your statement thus:

Dim a As Double, b As Double, c As Double


Jon

RE: Need VB6 Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted: Sat Mar 11, 2006 3:03 am
by WYBaugh
Hey NCRawler,

Thank you for the clarification. I'm a C/C# developer so my VB is fairly rusty.

Bill