## sk8rock_15

how do i add the numbers in label1 and label2 and i want it to appear at label3?

## abelingaw 69

Use textbox control for input purpose, not label.

Have a command button control on your form first and put this code on it.

``````Private Sub Command1_Click()

Sum = Val(Text1.Text) + Val(Text2.Text)

Label3.Caption = Sum

End Sub``````

Cheers!!

## sk8rock_15

No, i will not input the two number..

the two labels are linked at a picture box. If the picture1 was clicked, the label1 appears number 1 same as the picture2 and label2.

## sk8rock_15

Yes, it's my first time to post here.

Did i violate a rule?

## AndreRet 362

Only with the title. The title needs to have a description of your error, say "Add numbers in labels". Being new, no harm no foul.:)

As far as your question goes, what bexactly do you need if you are not going to get the sum of both. If you click on pic1, label 1 shows 1, why then add the 1 to label 3 as well?

@Abe, your code will not work. You need to declare the sum first -

``````Private Sub Command1_Click()
Dim Sum As Integer

Sum = Val(Text1.Text) + Val(Text2.Text)

Label3.Caption = Sum

End Sub``````

## sk8rock_15

because I'm creating a game. A logic game.

The picture1 is one of the choices in the first question and it is the correct answer. So if the player clicked it, i will give him 1 point which i want to be placed at the label1. Actually my problem is solved i will just do it like this:

Line 4.

Sum = Val(Label1.Caption) + Val(Label2.Caption)

Am I right?

## abelingaw 69

@Sir Andre

@Abe, your code will not work. You need to declare the sum first -

It still works without declaring sir ;)

@sk8rock_15
Have a look at this, I included the code for the Picture controls.

``````Private Sub Command1_Click()

Sum = Val(Label1.Caption) + Val(Label2.Caption)
Label3.Caption = Str(Sum)

End Sub

Private Sub Picture1_Click()
Label1.Caption = "1"
End Sub

Private Sub Picture2_Click()
Label2.Caption = "1"
End Sub``````

## sk8rock_15

Don't quarrel guys.

Anyways, thanks for both of you.

Cheers!!

## sk8rock_15

Yeah, I already know the code on Picture boxes. Why str? AndreRet declare the SUM as Integer while you are declaring it as String.

What is the correct one?

## abelingaw 69

It still works either way.

``Str(Sum)``

You don't need to declare Sum and Str as string but it will still work

I really don't know why.

## sk8rock_15

why you declare the SUM as string?

AndreRet declare it as Integer. What is the correct one?

## abelingaw 69

Just like i said, both of them will work..

## AndreRet 362

No it will not. If the OP starts with more advanced coding, he is going to fall into a pitfall, bugging his application. If we do give advice, we give the correct advice.:)

It still works without declaring sir

It will because "Sum" is a function within vb6. What if the OP uses it as a string, as you suggested? This means that if a user adds MyPic12345 it will be declared, as where an integer will throw an error, only wanting numbers, 12345. This is the correct way to make your application bug free.;)

``Option Explicit``