Assignment 3:: Problem 1: Design A Form With A Horizontal Scroll Bar, A Vertical Scroll Bar
Assignment 3:: Problem 1: Design A Form With A Horizontal Scroll Bar, A Vertical Scroll Bar
Problem 1: Design a form with a horizontal scroll bar, a vertical scroll bar and a shape object. Change both of the scroll bar vales from minimum to maximum and vice versa. The width and height of the shape object will be changed accordingly.
Public Class Form1 Private Sub HScrlBar_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrlBar.Scroll LabelW.Text = 100 + HScrlBar.Value Obj.Location = New Point(425 - HScrlBar.Value / 2, Obj.Location.Y) Obj.Width = 100 + HScrlBar.Value End Sub Private Sub VScrlBar_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrlBar.Scroll LabelH.Text = 100 + VScrlBar.Value Obj.Location = New Point(Obj.Location.X, 265 - VScrlBar.Value / 2) Obj.Height = 100 + VScrlBar.Value End Sub End Class
Output:
Problem 2: Write a VB program to convert the case of a selected text given in a textbox.
Public Class Form1 Private Sub Button_UCase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_UCase.Click TextOut.Text = UCase$(TextIn.SelectedText) End Sub Private Sub Button_LCase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_LCase.Click TextOut.Text = LCase$(TextIn.SelectedText) End Sub End Class
Output:
Problem 3: Design a VB application that takes a string from the user and irrespective of leading and trailing white spaces tests whether it is a palindrome or not.
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim flag As Integer, temp1, temp2 As String If TextBox1.Text = "" Then flag = 0 MsgBox("Error : Required field is empty") Else flag = 1 End If If flag = 1 Then If CheckBox1.Checked = False Then temp1 = TextBox1.Text temp2 = StrReverse(temp1) Else temp1 = Trim(TextBox1.Text) temp2 = StrReverse(temp1) End If If temp1 = temp2 Then Output.ForeColor = Color.Green Output.Text = "Input string is Palindrome." Else Output.ForeColor = Color.Red Output.Text = "Input string is NOT Palindrome." End If Output.Visible = True End If End Sub End Class
Output:
Problem 4: Design a VB application that demonstrate the difference between call by value and call by reference mechanisms.
Public Class Form1 Private Sub Swap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Swap.Click Dim A, B As Integer If Not IsNumeric(InA.Text) Or Not IsNumeric(InB.Text) Then MsgBox("Only numeric values are allowed") Else A = Val(InA.Text) B = Val(InB.Text) If RadioByVal.Checked = False And RadioByRef.Checked = False Then MsgBox("Select a mechanism") Else If RadioByVal.Checked = True Then SwapByValue(A, B) OutStatement.Text = "Numbers A and B are swapped through Call by Value mechanism" Else SwapByReference(A, B) OutStatement.Text = "Numbers A and B are swapped through Call by Reference mechanism" End If OutStatement.Visible = True OutA.Text = A OutB.Text = B End If End If End Sub Function SwapByValue(ByVal A As Integer, ByVal B As Integer) Dim Temp Temp = A A=B B = Temp End Function Function SwapByReference(ByRef A As Integer, ByRef B As Integer) Dim Temp Temp = A A=B B = Temp End Function End Class
Output: