Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Saturday, July 23, 2011

VB-57 : Calculations using Grid control

Using the Grid control write a program that displays sum,difference,product and quotient of numbers (ranging from 1 to 10) in the respective cells upon selection of particular operation.
(Note : Place 4 command buttons for operations choice & a grid control)


Click  Simple Programs(3) to get an idea about Calculation.


Refer The four calculations  & .Simple Calculator also


(A)Program Design : 


(B) Property(Controls Used) :
  • 2 Labels with Captions Number1 & Number2
  • 2 TextBoxes (Name Text1 with index 0&1 :- So that, the name of the 2 TextBoxes will be Text1(0) & Text1(1)
  • Select Project-->Components-->Microsoft Fles Grid Control 6.0 to add a Grid (Name-Grid1,Fixed Row-1,Fixed Column-0,Rows-5,Columns-2)
  • 4 Command Buttons with Name Command1  with index 0,1,2 & 3 (So that Name will be Command1(0),Command1(1),Command1(2) and Command1(3) and Captions as Sum,Quotient,Product and Difference 

(C) Attaching Code to the Object :



Private Sub Command1_Click(Index As Integer)
Dim ans As Single
Select Case Index
Case 0
ans = Val(Text1(0).Text) + Val(Text1(1).Text)
Case 1
ans = Val(Text1(0).Text) / Val(Text1(1).Text)
Case 2
ans = Val(Text1(0).Text) * Val(Text1(1).Text)
Case 3
ans = Val(Text1(0).Text) - Val(Text1(1).Text)
End Select
Grid1.Col = 1
Grid1.Row = Index + 1
Grid1.Text = ans
End Sub
Private Sub Form_Load()
Grid1.Row = 0
Grid1.Col = 0
Grid1.Text = "Operation"
Grid1.Col = 1
Grid1.Text = "Result"
Grid1.Row = 1
Grid1.Col = 0
Grid1.Text = "Sum"
Grid1.Row = 2
Grid1.Text = "Quotient"
Grid1.Row = 3
Grid1.Text = "Product"
Grid1.Row = 4
Grid1.Text = "Difference"
End Sub
Private Sub Text1_Change(Index As Integer)
Dim n As Single
n = Val(Text1(Index).Text)
If n < 0 And n > 10 Then
MsgBox "Number should between 1 to 10 only"
Text1(Index).SetFocus
End If
End Sub



(D) Output :


Give Numbers as 8 & 2 , then click the 4 command buttons in order to display the result inside the Grid.

Refer this Video Tutorial
====================================================================
=========================================================

No comments: