Saturday, February 23, 2019

Vb.net lab cycle


1.Write a Vb.net program to find factorial of a given number

  
Module Factorial
    Sub main()
        Dim n, i, f As Integer
        Console.Write("Enter a Number: ")
        n = CInt(Console.ReadLine())
        f = 1
        For i = 1 To n
                f = f * i
        Next
            Console.WriteLine("Factorial of " + n.ToString() + " is " + f.ToString())
      
     End Sub
     End Module


2.Check whether the given number is Armstrong Number or not



Module ArmstrongNumber

    Sub Main()
        Dim n, r, sum, m As Integer
        Console.Write("Enter a number= ")
        n = CInt(Console.ReadLine())
        sum = 0
        m = n
        While n <> 0
            r = n Mod 10
            sum =sum +  Math.Pow(r, 3)
            n = n \ 10

        End While
        If sum = m Then
            Console.WriteLine(t.ToString + " is a Armstrong Number")
        Else
            Console.WriteLine(t.ToString + " is NOT an Armstrong Number")
        End If
       
    End Sub

End Module

3.Calculate Sum of the digits of a given number


Module sumofdigits

    Sub Main()
        Dim n, sum, r As Integer
        Console.Write("Enter a Number: ")
        n = CInt(Console.ReadLine())
        sum = 0
        While n <> 0
            r = n Mod 10
            sum = sum + r
            n = n \ 10
        End While
        Console.WriteLine("Sum of Digits=" + sum.ToString())
        Console.ReadLine()
    End Sub

End Module



4.Check whether the number is a Perfect Number or not



Module PerfectNum

    Sub Main()
        Dim n, p, r, sum As Integer
        Console.Write("Enter a number: ")
        n = CInt(Console.ReadLine())
        p = 1
        sum = 0
        While p <= n \ 2
            r = n Mod p
            If r = 0 Then
                sum = num + p
            End If
            p = p + 1
        End While
        If sum = n Then
            Console.WriteLine(n.ToString + " is a Perfect Number")
        Else
            Console.WriteLine(n.ToString + " is NOT a Perfect Number")
        End If     
    End Sub
End Module
 
 

5.Fibonacci Sequence

 
 
Module Fibonacci
 
    Sub Main()
        Dim n, f1, f2, f3 As Integer
        Console.Write("Enter Your Term:")
        n = CInt(Console.ReadLine())
        f1 = 0
        f2 = 1
        f3 = 0
        While n <> 0
            Console.Write(f3 & " ")
            f1 = f2
            f2 = f3
            f3 = f1 + f2
            n = n - 1
        End While
        
    End Sub
 
End Module

     6. Write a program in VB.Net to perform String Operations.

   
Module Module1

Sub Main()

        Dim  s1 As String = "welcome to vb.net"

        Dim s2  As String = "programming"

        Dim s3  As String

        s3 = s1 & s2


        Console.WriteLine("after cancat" & s3)

        s3 = LCase(s1)

        Console.WriteLine("LowerCase:" & s3)

        s3 = s1.ToUpper()

        Console.WriteLine("uppercase " & s3)

        s3 = s1.Substring(0, 7)

        Console.WriteLine("sub string" & s3)

        s3 = s1.Replace("vb.net", "java")

        Console.WriteLine("after replace" & s3)

        s3 = s1.Remove(0, 11)

        Console.WriteLine("after removing" & s3)

        Console.WriteLine("length of str1 string" & s1.Length())

        Console.WriteLine("length of str2 string" & s2.Length())

        Console.ReadLine()

   End Sub

End Module

                             7. Exception Handling 

Module Module1
 Sub Main()
 Dim a, b, c As Integer
 Console.WriteLine("enter two number")
 Try
 a = CInt(Console.ReadLine())
 b = CInt(Console.ReadLine())
 c = a / b
 Console.WriteLine("quotient " & c)
                    
 Catch e As OverflowException
 Console.WriteLine("cannot divide by zero")
         Finally
Console.WriteLine("this is always excuted")

End Try

End Sub


End Module

            WINDOWS APPLICATION

8.Zoom In/Zoom Out


Image-   localsource>import
Sizemode>striceimage
Button1-text>zoom in
Button2-text>zomm out


 Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgsHandles Button1.Click
       PictureBox1.Width = PictureBox1.Width + 20
       PictureBox1.Height = PictureBox1.Height + 20

End Sub

PrivateSub Button2_Click(sender AsObject, e AsEventArgsHandles Button2.Click
        PictureBox1.Width = PictureBox1.Width - 20
        PictureBox1.Height = PictureBox1.Height - 20
End Sub
End Class

                            9.Quiz


Properties
Groupbox1 >text>what is remove text function
Radiobutton1 >text>string.remove
Radiobutton2 >text>string.insert
Radiobutton3 >text>string.substring

Groupbox2 >text>what is replace function?
Radiobutton4 >text>strcomp
Radiobutton5 >text>string.copy
Radiobutton6>text>string.replace

Groupbox3 > text >what is search string function?
Radiobutton7>text>Lcase
Radiobutton8>text >string.indexof
Radiobutton9 >text> both

Button1>Text > submit

Program

Public Class Form1
Private c AsInteger
PrivateSub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
            c = c + 1
Else
MsgBox("wrong answer")
End If
If RadioButton6.Checked Then
            c = c + 1
Else
MsgBox("wrong answer")
End If
If RadioButton8.Checked Then
            c = c + 1
Else
MsgBox("wrong answer")
End If
MsgBox("your score is"& c)
End Sub
End Class

10.Text Formatting Using Checkbox
Properties
Button1>text >fill
Button2> text >get select the items

 Public Class Form1

PrivateSub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For As Integer = 1 To 10
CheckedListBox1.Items.Add("item:"&i, True)

Next
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim str As String = ""
For Each x As String In CheckedListBox1.CheckedItems
str = str& x &","
Next
MsgBox("the channel items are:"&str)
End Sub
End Class


11.Free Hand Drawing


Public Class Form1
Privatepx, py As Integer
Private drag As Boolean

Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
        Drag = True
px = e.X
py = e.Y

End Sub

Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If Drag Then
Dim g As Graphics = Me.CreateGraphics()
g.DrawLine(Pens.Blue, px, py, e.X, e.Y)
px = e.X
py = e.Y
End If
End Sub

PrivateSub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
        Drag = False
End Sub
End Class

12.Convert Text into Bold, Italic and underline using check box

 
  
public class Form1
Private Sub Checkbox1_Checkedchanged( Byval sender As System.Object,
Byval e As System.EventArgs) Handles Checkbox1.CheckedChanged
Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style
Xor FontStyle.Bold)
End Sub 
Private Sub Checkbox2_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox2.CheckedChanged
 Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style Xor FontStyle.Italic)
End Sub 
Private Sub Checkbox3_Checkedchanged( Byval sender As System.Object, Byval e As System.EventArgs) Handles Checkbox3.CheckedChanged
 Textbox1.Font = New Font(TextBox1.Font, Textbox1.Font.Style Xor FontStyle.Underline)
End Sub
End Class
 

13.Calculator 

Properties
Button1> text > 0      Button7> text > 6
Button2> text > 1      Button8> text > 7
Button3> text > 2       Button9> text > 8
Button4> text > 3       Button10> text > 9
Button5> text > 4        Button11> text > +
Button6> text > 5        Button12> text > -
Button13> text > *    Button15> text > .
Button14> text > /     Button16> text > mod
Button17> text > =    Button18> text > c
Program
Public Class Form1
Private pre, cur As Double
Private opcode As String
PrivateSub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For As Integer = 3 To 7
Dim c As Control = Me.Controls(i)
AddHandler c.Click, AddressOf Op
Next
For As Integer = 8 To 18
Dim c AsControl = Me.Controls(i)
AddHandler c.Click, AddressOf numbers


Next
End Sub
Private Sub numbers(ByVal s As Object, e As EventArgs)
Dim b As Button = s
        TextBox1.Text = TextBox1.Text &b.Text

End Sub
Private Sub op(ByVal s As Object, e As EventArgs)
Dim b As Button = s
opcode = b.Text
pre = CDbl(TextBox1.Text)
        TextBox1.Text = ""

End Sub

Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
Dim res AsDouble
cur = CDbl(TextBox1.Text)
Select Case opcode
Case "+"
res = pre + cur
Case "-"
res = pre - cur
Case "*"
res = pre * cur
Case "/"
res = pre / cur
Case "mod"
res = pre Mod cur
End Select
        TextBox1.Text = res
End Sub

Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
pre = 0
cur = 0
        opcode = ""
        TextBox1.Text = ""

End Sub
End Class

14.WordProcesor


Properties
Menusprit
File >open,new,save,exit
Edit >copy,cut,paste,undo,redo
Format >color,font,bullet
Richtextbox
Dialogbox
Colordialogbox,fontdilogbox,savedialogbox,opendialogbox

Program:
Public Class Form1

Private Sub NewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewToolStripMenuItem.Click
RichTextBox1.Clear()
End Sub

Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
If openfiledialog1.showdialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.LoadFile(OpenFileDialog1.FileName)
End If
End Sub

Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
If SaveFileDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
RichTextBox1.SaveFile(SaveFileDialog1.FileName)
End If
End Sub

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub

Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CopyToolStripMenuItem.Click
RichTextBox1.Copy()
End Sub

Private SubCutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CutToolStripMenuItem.Click
RichTextBox1.Cut()
EndSub

Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PasteToolStripMenuItem.Click
RichTextBox1.Paste()
End Sub

Private SubUndoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UndoToolStripMenuItem.Click
RichTextBox1.Undo()
End Sub

Private Sub RedoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RedoToolStripMenuItem.Click
RichTextBox1.Redo()
End Sub

Private Sub ColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ColorToolStripMenuItem.Click
If ColorDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
            RichTextBox1.SelectionColor = ColorDialog1.Color
End If
End Sub

Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog <>Windows.Forms.DialogResult.Cancel Then
            RichTextBox1.SelectionFont = FontDialog1.Font
End If

End Sub

Private Sub BulletToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BulletToolStripMenuItem.Click
        RichTextBox1.SelectionBullet = True

End Sub
End Class

15.CreatingDialague Boxes

            
Form1

Textbox
Buttton1
Text > enter text
Form2
Label>enter text hole
Textbox
Button1>ok
Dialogresult>ok
Button2>cancel
Dialogresult>cancel

Public Class Form1

Private f As New Form3()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If f.ShowDialog = DialogResult.OK Then

             TextBox1.Text = f.TextBox1.Text

Else

MsgBox("cancel was clicked")
 End If 

End Sub

End Class

Public Class Form2 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Me.Close()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class

 

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. sir there is a mistake in 4th(Perfect number) program....11th line it is //sum= sum + P
    //you written as sum= num + p......

    ReplyDelete
  3. It's because i see the screen rather than the keyboard when I am typing

    ReplyDelete
  4. Sir i am yogaraj..what are the
    Last 3 programs

    ReplyDelete