Programs
Programs
on moving scroll bar background color of text box must be changed. CODE: Public Class Form1 Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll TextBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value) End Sub Private Sub HScrollBar2_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar2.Scroll TextBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value) End Sub Private Sub HScrollBar3_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar3.Scroll TextBox1.BackColor = Color.FromArgb(HScrollBar1.Value, HScrollBar2.Value, HScrollBar3.Value) End Sub End Class
Q 2. Design a GUI application which copies contents if one text file into another after checking whether the file exists or not
code
Public Class Form2 Dim SourcePath As String = "I:\mehul\mehul.txt" Dim SaveDirectory As String = "I:\mehul\backup\" Dim Filename As String = System.IO.Path.GetFileName(SourcePath) Dim SavePath As String = System.IO.Path.Combine(SaveDirectory, Filename) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If System.IO.File.Exists(SavePath) Then MessageBox.Show("file exists") Else MessageBox.Show("the file doesn't exist Coping file") My.Computer.FileSystem.CopyFile(SourcePath, SavePath) End If End Sub
End Class
Q.3 Input an array of 10 elements. Store even and odd no. in different arrays and display contents of all the arrays. CODE:
Public Class Form3 Dim a(9) As Integer Dim sum As Integer = 0 Dim j As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click a(j) = TextBox1.Text ListBox1.Items.Add(a(j)) If a(j) Mod 2 = 0 Then ListBox2.Items.Add(a(j)) Else ListBox3.Items.Add(a(j)) End If sum = sum + a(j) j=j+1 If j = 10 Then Button1.Visible = False End If End Sub End Class
Q. 1 Write a console application that show the Demo of method overriding Output:
Code:
Module Module1 Class over Public Overridable Function add(ByVal x As Integer, ByVal y As Integer) Console.WriteLine("Function Inside Base Class") Return (x + y) End Function End Class Class derover Inherits over Public Overrides Function add(ByVal x As Integer, ByVal y As Integer) Console.WriteLine(MyBase.add(120, 100)) Console.WriteLine("Function Inside Derive Class") Return (x + y) End Function End Class Sub Main() Dim obj As New derover Console.WriteLine(obj.add(10, 100)) Console.ReadLine() End Sub End Module
Code:
Module Module1 Public Class mul Public a, b As Integer Public c, d As Double Public Function mul(ByVal a As Integer) As Integer Return a End Function Public Function mul(ByVal a As Integer, ByVal b As Integer) As Integer Return a * b End Function Public Function mul(ByVal d As Double, ByVal c As Double) Return d * c End Function End Class Sub Main() Dim res As New mul System.Console.WriteLine("Overload values of class Mul is::") System.Console.WriteLine(res.mul(10)) System.Console.WriteLine(res.mul(20, 10)) System.Console.WriteLine(res.mul(12.12, 13.32)) Console.ReadLine() End Sub End Module
Q.3 Design a window form that accept a number from user in textbox and check whether it is a palindrome or not Design:
Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n, r, sum, t As Integer Console.Write("Enter a Number:") n = CInt(Console.ReadLine()) sum = 0 t=n While n <> 0 r = n Mod 10 sum = sum * 10 + r n = n \ 10 End While If sum = t Then MessageBox.Show(t.ToString() + " is a Palindrome Number") Else MessageBox.Show(t.ToString() + " is not Palindrome Number") End If End Sub Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Dim KeyAscii As Short = Asc(e.KeyChar) If Not (KeyAscii >= System.Windows.Forms.Keys.D0 And KeyAscii <= System.Windows.Forms.Keys.D9) Then KeyAscii = 0 TextBox1.Focus() End If If KeyAscii = 0 Then e.Handled = True End If If TextBox1.Text.IndexOf(".") > 0 Then e.Handled = True End If If TextBox1.Text.IndexOf(".") Then If TextBox1.SelectionStart > TextBox1.Text.IndexOf(".") Then If TextBox1.Text.Length - TextBox1.Text.IndexOf(".") = 3 Then e.Handled = True End If End If End If End Sub
End Class
Save table:
Design:
Add Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New SqlConnection("Data Source=AKHILESH-PC\SQLEXPRESS;Initial Catalog=azad;Integrated Security=True") con.Open() Dim cmd As New SqlCommand() cmd.CommandText = ("insert into student_detail values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')") cmd.ExecuteNonQuery() con.Close() MessageBox.Show("Record Added Successfully") End Sub
Save Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New SqlConnection("Data Source=AKHILESH-PC\SQLEXPRESS;Initial Catalog=azad;Integrated Security=True") con.Open() Dim cmd As New SqlCommand() cmd.CommandText = ("insert into student_detail values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')")
Update Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New SqlConnection("Data Source=MASYS7;Initial Catalog=azad;Integrated Security=True") con.Open() Dim cmd As New SqlCommand() cmd.CommandText = ("update student_detail set student_name=+TextBox2.text+ where rollno='" + TextBox1.Text + "'") cmd.ExecuteNonQuery() con.Close() MessageBox.Show("Record Update Successfully") End Sub
Exit Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Close() End Sub
Q.5 count the words , letters and vowels from the string input in textbox
Public Class Form6 Dim str As String Dim i, l, words As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click str = TextBox1.Text str = LTrim(str) str = RTrim(str) l = str.Length i = 0 words = 0 While (i < l) If str(i) = " " Then words = words + 1 i = i + 1 While str(i) = " " i = i + 1 End While
Else i = i + 1 End If End While words = words + 1 Label1.Text = "No. of words = " & words
Dim str1, s, c As String Dim ll As Integer str1 = TextBox1.Text ll = Len(str1) c = 0 Dim intloopIndex As Integer For intloopIndex = 1 To ll s = Mid(str1, intloopIndex, 1) If (s = "A" Or s = "a" Or s = "E" Or s = "e" Or s = "I" Or s = "i" Or s = "O" Or s = "o" Or s = "U" Or s = "u") Then c = c + 1 End If Next Label2.Text = "No of Vowels: " & c.ToString str1 = str1.Replace(" ", "") Label3.Text = "No of characters: " & str1.Length End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class