Visual Basic 6.0 Making a PIGGY BANK

Visual Basic 6.0 Making a PIGGY BANK

Hello everyone today we will create a Piggy Bank in Visual Basic 6.0.
A very simple program, Things we will need in our form are 3 TextBoxs, 5 Labels, 3 Command Buttons and nothing else. 

So, let`s do this.

We have created 3 text boxes for taking input from the user into a variable we will declare it later inside the code and we have created 3 command button one is Exit this will close the program,
then we have a clear button, as the name describe it will clear the text boxes for new values if the user wants to add and lastly we have a calculate button that will add all the value containing inside the text box which the user has given.

Let`s jump to the code part

for exit button the is very simple 

Private Sub Command3_Click()
End Sub 

Now lets code for clear button

Private Sub Command2_Click()
TextOne.Text = ""
TextTwo.Text = ""
TextFive.Text = ""
resultLabel.Caption = ""
End Sub 

as we want our label where we are displaying our result. we want it to get clear before we add another entry so we did clear the resultLable too. 

now let`s code the calculate button

Private Sub Command1_Click()

Dim a, b, c, d As Integer
a = Val(TextOne.Text)
b = Val(TextTwo.Text)
c = Val(TextFive.Text)
d = 1 * a + 2 * b + 5 * c
resultLabel.Caption = d

End Sub


1.Dim is used to declare a variable we declared a, b,c,d as an integer variable. Integer is a datatype

2.The writing End inside a code window will result in ending the program to be care full.

3. Val function is always used to convert a String to Numeric form When we enter a value in the text box at the run time the inputted text will be of a string DataType to use that data for calculation we have to convert it into numeric form. Ther is another function called CInt( ) function this will also do the same mentioned above.

To learn more about Datatypes go to>>>>> VB DataTypes 
wait for the ad for 5 sec and then skip the add and enjoy.

And again thanks for reading. have any doubt ask in the comment I will be happy to help.😄😄


Post a Comment