-
I am new to VB and am trying to make a very simple program for school. I need some very basic things. I have a form with 3 text boxes, a command button, and a label. Text1, Text2, Text3, Label1, Command1.
1. int4 = (int1, int2, int3) / 100
I have started with:
Dim....
for each as an integer. I then <i>thought</i> I could type:
int1 = text1.text
I was wrong. Invalid outside procedure. What would I type there? Thanks.
-
Are you sure the character's in the TextBox's are numbers when you assigned them to int1?
-
It's as soon as I hit the play button to test the script it gives me the error.
-
Well if your wanting label1 to be equal to the equation when you click the button try this:
Code:
Private Sub Command1_Click()
Label1.Caption = (CInt(Text1.Text) + CInt(Text2.Text) + CInt(Text3.Text)) / 100
End Sub
If not, give some more information so I can help you better.
-
That is exactly it, thanks
-
Your welcome. If you need anything else, just let me know.
-
Invalid outside procedure occurs when you have snippets of code outside your procedures. Also Cint will round towards nearest whole and .5 up. Using INT will allow you to round down, in other words, remove the decimal parts
-
'or'
Label1.Caption = (Val(Text1) + Val(Text2) + Val(Text3)) / 100