Sie sind auf Seite 1von 22

1)

How to write Perfect number program code in vb.net using for loop and next

Dim sum As Integer = 0 Dim i As Integer For i = 1 To Convert.ToInt16(TextBox1.Text) - 1 If (Convert.ToInt16(TextBox1.Text) Mod i = 0) Then sum += i End If Next If sum = Convert.ToInt16(TextBox1.Text) Then MsgBox("It is perfect no") Else MsgBox("It is no perfect no") End If

2) Login form validation in vb.net using username and password field


Onbutton_click() { If (UsernameTextBox.Text = "" And PasswordTextBox.Text = "") Then MsgBox("Enter username & password") Else If (UsernameTextBox.Text = "") Then MsgBox("Enter username") Else If (PasswordTextBox.Text = "") Then MsgBox("Enter password") Else If (UsernameTextBox.Text = "scott" And PasswordTextBox.Text = "tiger") Then ProgressBar1.Visible = True ProgressBar1.Value = 0 Dim i As Integer = 100000 While (i >= ProgressBar1.Value) ProgressBar1.Value = ProgressBar1.Value + 10 End While Form1.Show() Me.Hide() Else MsgBox("Enter correct username & password") End If }

3) checkbox.checked | listbox.item | radiobutton.cheked in vb.net


How to write vb.net code to check checkbox and select listItem item and add them.
Private Sub Buttonon_Click() Handles Button1.Click listboxvalue.Items.Add("First Name=" + TextBoxvalue1.Text + " Last Name=" + TextBoxvalue2.Text + " Address=" + TextBoxvalue3.Text + " City=" + ComboBox1.Text + "\nSex=") If (radiobuttonvalue.Checked = True) Then listboxvalue.Items.Add("Male") Else listboxvalue.Items.Add("Female") End If listboxvalue.Items.Add(" Age=" + NumericUpDown1.Value.ToString() + " Hobbies are=") If (chkvalue1.Checked = True) Then listboxvalue.Items.Add(" Cricket") End If If (chkvalue2.Checked = True) Then listboxvalue.Items.Add(" Football") End If If (chkvalue3.Checked = True) Then listboxvalue.Items.Add(" Tennis") End If If (chkvalue4.Checked = True) Then listboxvalue.Items.Add(" BasketBall") End If End Sub

4) Console.Write-line | vb.net | draw table | For loop


Console.Write-line | vb.net | draw table using code Module Module1 Dim i, j, n As Integer Sub Main() Console.WriteLine("How many line do u want:") n = Console.ReadLine() For i = 1 To n For j = 1 To n Console.Write(j) Next n=n-1 Console.WriteLine() Next Console.ReadLine() End Sub End Module

5) How to use Console.WriteLine | Console.ReadLine() in vb.net

vb.net module | Console.WriteLine | Console.ReadLine() Module Module1 Dim s As String Sub Main() s = greet() Console.WriteLine(s) Console.ReadLine() End Sub End Module use of Console.WriteLine() and Console.ReadLine()

6) How to implements Radio Button in vb with forecolor


Radio Button code in vb with Forecolor. Radio Button Checked Property.

Public Class Form1 Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged If RadioButton1.Checked Then RadioButton1.ForeColor = Color.Red Else RadioButton1.ForeColor = Color.Blue End If End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged If RadioButton2.Checked Then RadioButton2.ForeColor = Color.DeepPink Else RadioButton2.ForeColor = Color.Blue End If End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged If RadioButton3.Checked Then RadioButton3.ForeColor = Color.Black

Else RadioButton3.ForeColor = Color.Blue End If End Sub End Class

7) How to use For loop in vb.net


Example of For loop in Vb.Net Module Module1 Dim n, a, b, c, i As Integer Sub Main() Console.WriteLine("Enter the number") n = Console.ReadLine() a=0 b=1 For i = 0 To n c=a+b Console.WriteLine(c) a=b b=c Next Console.ReadLine() End Sub End Module

8) Factorial Number in Vb.Net | Using For Next loop


Find out Factorial number of given number Module Module1 Dim a, i As Integer Dim fact As Integer Sub Main() Console.WriteLine("enter the number") a = Console.ReadLine() fact = 1 i=1 For i = 1 To a fact = fact * i Next i Console.WriteLine("factorial is" & fact) Console.ReadLine() End Sub End Module

9) Interface in vb.net | imath


How to implements Interface in Vb.Net

Public Interface imath Function add(ByVal a As Integer, ByVal b As Integer) As Integer Function subst(ByVal a As Integer, ByVal b As Integer) As Integer End Interface Public Class math Implements imath Public Function add(ByVal a As Integer, ByVal b As Integer) As Integer Implements imath.add Return a + b End Function Public Function subst(ByVal a As Integer, ByVal b As Integer) As Integer Implements imath.subst Return a - b End Function End Class save page as math.vb

code for interface

Module Module1 Sub Main() Dim s As New math Dim d, w As Integer ''Dim obj As New math Console.WriteLine("enter the value of d & w") d = Console.ReadLine() w = Console.ReadLine() 'Console.WriteLine(obj.add(a, b))

'Console.WriteLine(obj.subst(a, b)) 'Console.ReadLine() Console.WriteLine(s.add(d, w)) Console.WriteLine(s.subst(d, w)) Console.ReadLine() End Sub End Module Save as Module1.vb

10) Inheritance in Vb.Net | How to use New Keyword


How to write Inheritance Program in Vb.Net using New Keyword. Develop Logic by writing Code.
Public Class Class1 Public a, p As Double Public Sub area(ByVal ra As Integer) a = 3.14 * ra * ra p = 2 * 3.14 * ra End Sub End Class

Public Class Class2 Inherits Class1 Dim w As New Class1 Dim r As Double Public Sub accept() 'Console.WriteLine("enter the radius") 'r = Console.ReadLine 'w.area(r) Console.WriteLine("area=" & a) Console.WriteLine("perimeter=" & p) End Sub End Class

Module Module1 Sub Main() Dim a As Integer Console.WriteLine("enter the redius")

a = Console.ReadLine() Dim d As New Class2 d.area(a) d.accept() Console.ReadLine() End Sub End Module

11)

Addition Of Two numbers in Vb.net

Module Module1 Dim a, b, c As Integer Sub Main() Console.WriteLine("Enter the number") a = Console.ReadLine() Console.WriteLine("Enter the second value") b = Console.ReadLine() c=a+b Console.WriteLine("sum is" & c) Console.ReadLine()

End Sub End Module

12) Sum of 1..10 Number in Vb.Net Using For Loop

Module Module1 Dim n, i, sum As Integer Sub Main() sum = 0 Console.WriteLine("Enter the number") n = Console.ReadLine() For i = 1 To 10 sum = sum + n Console.WriteLine(sum) Next i Console.ReadLine() End Sub End Module

13)

How to use MsgBox in Vb.Net

Public Class Form1 Public a, b As String Private Sub Form1_Load() Handles MyBase.Load a = "hello" b = "welcome" MsgBox(a) MsgBox(b)

End Sub End Class

14) Vb.Net Code With Window Application using Case

Module Module2 Function greet() Console.WriteLine("Pritam") End Function End Module Second Program

Module Module1 Sub main() Dim n As Integer Console.WriteLine("find element") Console.WriteLine("enter value ") n = Console.ReadLine() Console.WriteLine(" " & find(n)) Console.ReadLine() End Sub Function find(ByVal b) As String Select Case (b) Case 0 To 20 Dim arr() As String = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"} Return arr(b - 1) Case Else Console.WriteLine("wrong entry") End Select End Function End Module

15) Console Application in Vb.Net using If and then

Dim n(10), i, a As Integer Console.WriteLine("enter the values") For i = 0 To 9 n(i) = Console.ReadLine() Next Console.WriteLine("enter the value which you want find in array") a = Console.ReadLine() For i = 0 To 9 If (n(i) = a) Then Console.WriteLine("no is found") Stop Console.ReadLine() Else Console.WriteLine("no is not found") Console.ReadLine() Stop End If

16) How to use Mode in Vb.Net | Mode examples

Module Module1 Dim n, i, sum, m As Integer Sub Main() Console.WriteLine("Enter the number") n = Console.ReadLine() m=n For i = 1 To n - 1 If (n Mod i = 0) Then sum = sum + i End If Next i If (sum = m) Then Console.WriteLine("It is perfect number") Else Console.WriteLine("Not perfect number") End If Console.ReadLine()

17)

How to use Reverse the number in vb.net

Module dysplay1 Public Sub display(ByVal s) r = Len(s) While r <> 0 Console.Write("" & s(r - 1)) r -= 1 End While Console.ReadLine()

18) Me.Close | Len | Mid | Timer1.Interval function in vb.net ..

count length of the string .Using timer control. Public Class Form1 Dim str, a As String Dim j, k, l As Integer Private Sub ExitToolStripMenuItem_Click(ByVal....) Handles ExitToolStripMenuItem.Click Me.Close() End Sub Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load str = " dev raj" l = Len(str) + 1 j=0 k=1 Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal....) Handles Timer1.Tick

'j = j + 1 a = Mid(str, l, 1) Label1.Text = a + Label1.Text l=l-1 If l <= 0 Then Label1.Text = str l = Len(str) + 1 Timer1.Interval = 1000 Label1.Text = "" Timer1.Enabled = True End If 'If j >= Len(str) + 1 Then ' 'a = "" ' j=0 ' Timer1.Interval = 1000 ' Label1.Text = "" ' Timer1.Enabled = True 'End If End Sub End Class

19) How to bind data to Datagrid or Gridview in vb.net using DataBind()


Private Sub Page_Load(....) Handles MyBase.Load 'Put user code to initialize the page here Dim con As New SqlClient.SqlConnection("Data Source=SERVER;Initial Catalog=ERP;Integrated Security=True") Dim com As New SqlClient.SqlCommand Dim ds As New DataSet

Dim da As New SqlDataAdapter da = New SqlDataAdapter("select scode,fname,prod1,prod2,prod3,prod4 from Supplier_Master", con) da.Fill(ds, "Stock") dgsupp.DataSource = ds.Tables("Stock") dgsupp.DataBind() End Sub

20) How to write logic between Start and end namespace in vb.net
Namespace ERP 'start of namespace Partial Class managerhomepage Inherits System.Web.UI.Page Private Sub Page_Init(ByVal...) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'If Convert.ToString(Session("ut")) = "" Then ' Server.Transfer("ErpError.aspx") 'End If End Sub End Class End Namespace 'end of namespace

1. LOGIN FORM
Public Class form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If (UsernameTextBox.Text = "" And PasswordTextBox.Text = "") Then MsgBox("Enter username & password") ElseIf (UsernameTextBox.Text = "") Then MsgBox("Enter username") ElseIf (PasswordTextBox.Text = "") Then MsgBox("Enter password") ElseIf (UsernameTextBox.Text = "abhi" And PasswordTextBox.Text = "1234") Then Me.Hide() Form2.Show() Else MsgBox("Enter correct username & password") End If End Sub

End Class

Private Sub txtgood_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtclick.Click If txtclick.Checked = True Then txtclick.Text = "Good" txtlow.Visible = False txtmedium.Visible = False End If txtemphseno.Focus() End Sub Private Sub txtmedium_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtmedium.Click If txtmedium.Checked = True Then txtmedium.Text = "Medium" txtlow.Visible = False txtclick.Visible = False End If txtemphseno.Focus() End Sub Private Sub txtlow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtlow.Click If txtlow.Checked = True Then txtlow.Text = "Low" txtclick.Visible = False txtmedium.Visible = False End If txtemphseno.Focus() End Sub

Das könnte Ihnen auch gefallen