Thursday, December 15, 2011

Button Play

1.A program that will initially display two buttons, the first is enabled and the other is disabled. The behavior will be, once you click the Enabled button, it will be disabled, while the other button (which is disabled) will be enabled.



2. CODE:


Public Class frmButtonPlay

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

btn1.Enabled = False
btn2.Enabled = True
End Sub


Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

btn2.Enabled = False
btn1.Enabled = True
End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backtoindex.Click

Me.Close()
End Sub

Private Sub frm2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

btn1.Enabled = True
btn2.Enabled = False
End Sub

End Class

3. Save & Run...

Got Focus

1. A program that will illustrate the GotFocus event with four text box and a label. As you move the focus from one text box to another, the label will tell you which of them has the focus.



2. The CODE:


Public Class frm3

Private Sub GotFocus_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub MultipleEvents(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter

ShowInfo.Text = "Text " & Microsoft.VisualBasic.Right(ActiveControl.Name, 1) & " is in Focus"
End Sub

Private Sub Label1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Leave
End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

Me.Close()
End Sub

End Class

3. Save & Run your program.

Visible Enabled

1. Make an interface like this ti notice the trick.



2. The code..

Public Class frm2

Private Sub VisibleEnabled_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

TextBox.Visible = False
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

TextBox.Visible = True
TextBox.Text = "I am here."
TextBox.Enabled = True
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click

TextBox.Visible = True
TextBox.Text = "I am enabled."
TextBox.Enabled = True
End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click

TextBox.Enabled = False
TextBox.Text = "I am disabled."
End Sub

Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox.TextChanged
End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backtoindex.Click

Me.Close()
End Sub

End Class

3. Save & Run the program.

Mouse Locator

1. A program showing the location of the pointer (x and y) in the title bar. Form name is "frm1".





2. Enter the CODE:


Public Class frm1

Private Sub MouseLocator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub MouseLocator_Mousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

Me.Text = "Your location in X is " & e.X & " and Y is " & e.Y

End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backtoindex.Click

Me.Close()

End Sub
End Class

3. Save and Run your program.

Grade Generator

1. Construct the user interface as follows:



2. Code:


Public Class frmGradeGenerator

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim FinalGrade As Single

FinalGrade = Val(txtPrelimGrade.Text) * 0.3 + Val(txtMidtermGrade.Text) * 0.3 + Val(txtFinalsGrade.Text) * 0.4

txtFinalGrade.Text = FinalGrade

Select Case FinalGrade

Case 98 To 100
txtEquivalentGrade.Text = "1.0"
txtRemarks.Text = "Excellent"

Case 95 To 97
txtEquivalentGrade.Text = "1.25"
txtRemarks.Text = "Outstanding"

Case 92 To 94
txtEquivalentGrade.Text = "1.5"
txtRemarks.Text = "Very Good Work"

Case 89 To 91
txtEquivalentGrade.Text = "1.75"
txtRemarks.Text = "Very Satisfactory work"

Case 86 To 88
txtEquivalentGrade.Text = "2.0"
txtRemarks.Text = "Quite Good Work"

Case 83 To 85
txtEquivalentGrade.Text = "2.25"
txtRemarks.Text = "Good Work"

Case 80 To 82
txtEquivalentGrade.Text = "2.5"
txtRemarks.Text = "Satisfactory Work"

Case 77 To 79
txtEquivalentGrade.Text = "2.75"
txtRemarks.Text = "Moderately Satisfactory Work"

Case 75 To 76
txtEquivalentGrade.Text = "3.0"
txtRemarks.Text = "Passing"

Case Is < 75
txtEquivalentGrade.Text = "5.0"
txtRemarks.Text = "Failure"

Case Else
MsgBox("You Enter an Invalid Grade", MsgBoxStyle.Exclamation, "Warning")

End Select
End Sub

End Class

3. Save and Run the program.

Case Conversion

1. Construct the user interface:



2. Enter the code as follows:


Public Class frmCaseConversion

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

txtLcase.Text = Microsoft.VisualBasic.LCase(txtInput.Text)
txtUcase.Text = Microsoft.VisualBasic.UCase(txtInput.Text)
txtPcase.Text = Microsoft.VisualBasic.StrConv(txtInput.Text, VbStrConv.ProperCase)
End Sub

End Class

3. Save and Run..

Palindrome Test

1. Design the following:



2. Enter the code as follows:


Public Class frmPalindromeTest

Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click

Dim Result As String

txtReverse.Text = Microsoft.VisualBasic.StrReverse(txtInput.Text)

Result = Microsoft.VisualBasic.StrComp(txtInput.Text, txtReverse.Text)

If Result = 0 Then

lblResult.Text = "The string is a Palindrome"

Else
lblResult.Text = "The string is not a Palindrome"

End If
End Sub

End Class

3. Save and Run the program.