2. Write a VB program to create magical square (3*3). Enter numbers in between 1 to 9 in the square such that addition of each row and each column should be 15.


Private Sub Command1_Click()
Label1.Caption = CInt(Text1.Text) + CInt(Text2.Text) + CInt(Text3.Text)
Label2.Caption = CInt(Text4.Text) + CInt(Text5.Text) + CInt(Text6.Text)
Label3.Caption = CInt(Text7.Text) + CInt(Text8.Text) + CInt(Text9.Text)
Label4.Caption = CInt(Text1.Text) + CInt(Text4.Text) + CInt(Text7.Text)
Label5.Caption = CInt(Text2.Text) + CInt(Text5.Text) + CInt(Text8.Text)
Label6.Caption = CInt(Text3.Text) + CInt(Text6.Text) + CInt(Text9.Text)

If (Label1.Caption = 15 And Label2.Caption = 15 And Label3.Caption = 15 And Label4.Caption = 15 And Label5.Caption = 15 And Label6.Caption = 15) Then

MsgBox ” all waya well”, vbOKCancel
Else
MsgBox ” all NOT waya well”, vbOKCancel
End If
End Sub

Private Sub Command2_Click()
Text1.Text = ” ”
Text2.Text = ” ”
Text3.Text = ” ”
Text4.Text = ” ”
Text5.Text = ” ”
Text6.Text = ” ”
Text7.Text = ” ”
Text8.Text = ” ”
Text9.Text = ” ”
Text1.Text = ” ”
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s