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

A section for those creating 3rd party tools and add ons. Lots of techincal code creation type questions would go here.

Moderator: David Winter

Post Reply
User avatar
Brodie
Posts: 145
Joined: Thu May 05, 2005 10:33 pm

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

Post 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.

WYBaugh
Posts: 158
Joined: Mon Jul 05, 2004 7:50 pm

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

Post 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
User avatar
Brodie
Posts: 145
Joined: Thu May 05, 2005 10:33 pm

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

Post 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
QBPR
Posts: 22
Joined: Wed Feb 08, 2006 5:44 pm

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

Post by QBPR »

I'm always amazed at any language that lets you implicitly convert datatypes on the fly without throwing a compile error. Ick.
NCrawler
Posts: 26
Joined: Tue Jun 03, 2003 9:19 pm
Location: Sherwood, AR

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

Post 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
WYBaugh
Posts: 158
Joined: Mon Jul 05, 2004 7:50 pm

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

Post by WYBaugh »

Hey NCRawler,

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

Bill
Post Reply

Return to “3rd Party Developers Area”