Beruflich Dokumente
Kultur Dokumente
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
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()
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
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
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
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
a = Console.ReadLine() Dim d As New Class2 d.area(a) d.accept() Console.ReadLine() End Sub End Module
11)
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()
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)
Public Class Form1 Public a, b As String Private Sub Form1_Load() Handles MyBase.Load a = "hello" b = "welcome" MsgBox(a) MsgBox(b)
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
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
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)
Module dysplay1 Public Sub display(ByVal s) r = Len(s) While r <> 0 Console.Write("" & s(r - 1)) r -= 1 End While Console.ReadLine()
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
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