0% found this document useful (0 votes)
1 views

VBNET Console HelpCodes

Binary trees

Uploaded by

inchristjoe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

VBNET Console HelpCodes

Binary trees

Uploaded by

inchristjoe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

VISUAL BASIC.

NET CODES
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim num1, num2, sum AsInteger
num1 = InputBox("Enter first number")
num2 = InputBox("Entr second number")
sum = num1 + num2
Label1.Text = sum
EndSub

PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
EndSub

PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Dim num1, num2, total AsInteger
num1 = Me.TextBox4.Text
num2 = Me.TextBox5.Text
total = Val(num1) + Val(num2)
Me.TextBox6.Text = total

EndSub
EndClass

________________________________________________________________
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim num1 AsInteger, num2 AsInteger, num3 AsInteger
num1 = TextBox1.Text
num2 = TextBox2.Text
num3 = num1 + num2
TextBox3.Text = num3
Label1.Text = num3

EndSub
____________________________________________________________________

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) HandlesMyBase.Load
Me.BackColor = Color.Aquamarine
EndSub

1 [email protected] 0777634287/0712389336
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim x AsInteger, p AsInteger
For x = 0 To 100
p = x Mod 2
If p = 1 Then
ListBox1.Items.Add(x)
Else

EndIf
Next
EndSub
EndClass
____________________________________________________________________

ModuleModule1

Sub Main()
Dim num1, num2, total As Integer
Console.WriteLine("Enter first number")
num1 = Console.ReadLine()
Console.WriteLine("Enter second number")
num2 = Console.ReadLine()
total = num1 + num2
Console.WriteLine("Total is " & total)
Console.ReadKey()
EndSub

EndModule

____________________________________________________________________

PublicClassForm1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
Dim a, b, c AsInteger, x, y AsDouble
a = InputBox("Enter the value for variable a")
b = InputBox("Enter the value for variable b")
c = InputBox("Enter the value for variable c")
If (b ^ 2 - 4 * a * c) > 0 Then
x = (-b + Math.Sqrt(b ^ 2 - 4 * a * c)) / 2 * a
y = (-b - Math.Sqrt(b ^ 2 - 4 * a * c)) / 2 * a
ListBox1.Items.Add("The first root for the equation is
"& y)
ListBox1.Items.Add("The second root for the equation is
"& x)

ElseIf (b ^ 2 - 4 * a * c) = 0 Then
x = (-b) / 2 * a

2 [email protected] 0777634287/0712389336
ListBox1.Items.Add("The only root for the equation is "&
x)
Else
MsgBox("The has no real roots")
EndIf

EndSub
EndClass
________________________________________________________________
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim names AsString
Dim count AsInteger
Dim names1 AsString
names1 = ""
names = InputBox("Enter a string")
For count = Len(names) To 1 Step -1
names1 = names1 + Mid(names, count, 1)
Next count
If names = names1 Then
ListBox1.Items.Add("The word "& names &" is a
palindrome")
MsgBox("The word "& (names) &" is a palindrome")
Else
ListBox1.Items.Add("The word "& names &" is not a
palindrome")
MsgBox("The word "& (names) &" is not a palindrome")
EndIf
EndSub
____________________________________________________________________
__________________________
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim x, y AsInteger
For x = 620 To 500 Step -1
y = x Mod 2
If y = 1 Then
ListBox1.Items.Add(x)
Else
ListBox2.Items.Add(x)
EndIf
Next
EndSub
EndClass

________________________________________________________________
ModuleModule1
Function Add(ByVal a, ByVal b) AsInteger
3 [email protected] 0777634287/0712389336
Add = a + b
EndFunction
Sub Main()
Dim fn, sn, answer AsInteger
Console.WriteLine("Enter first number")
fn = Console.ReadLine()
Console.WriteLine("Enter first number")
sn = Console.ReadLine()
answer = Add(fn, sn)
Console.WriteLine("The sum is "& answer)
Console.ReadKey()
EndSub

EndModule
________________________________________________________________
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim x, mark AsInteger
For x = 1 To 2
mark = InputBox("Enter a mark")
If mark < 0 Or mark > 100 Then
MsgBox("Enter a mark from 0 to 100 only")
Else
SelectCase mark
CaseIs>= 70 ', Is <= 100
'MsgBox("Grade A")
ListBox1.Items.Add("The grade of the mark "&
mark &" is A")
Case 65 To 69
'MsgBox("Grade B")
ListBox1.Items.Add("The grade of the mark "&
mark &" is B")
Case 55 To 64
'MsgBox("Grade C")
ListBox1.Items.Add("The grade of the mark "&
mark &" is C")
Case 50 To 54
'MsgBox("Grade D")
ListBox1.Items.Add("The grade of the mark "&
mark &" is D")
Case 40 To 49
'MsgBox("Grade E")
ListBox1.Items.Add("The grade of the mark "&
mark &" is E")
Case 35 To 39
'MsgBox("Grade O")
ListBox1.Items.Add("The grade of the mark "&
mark &" is O")

4 [email protected] 0777634287/0712389336
Case Else
'MsgBox("Grade F")
ListBox1.Items.Add("The grade of the mark "&
mark &" is F")
EndSelect
EndIf

Next

If mark < 0 Or mark > 100 Then x = -1


EndSub
____________________________________________________________________
__________________
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim x, mark AsInteger
x = 0
DoWhile x < 2
mark = InputBox("Enter a mark")
If mark > 0 And mark <= 100 Then
SelectCase mark
CaseIs>= 70 ', Is <= 100
'MsgBox("Grade A")
ListBox1.Items.Add("The grade of the mark "&
mark &" is A")
Case 65 To 69
'MsgBox("Grade B")
ListBox1.Items.Add("The grade of the mark "&
mark &" is B")
Case 55 To 64
'MsgBox("Grade C")
ListBox1.Items.Add("The grade of the mark "&
mark &" is C")
Case 50 To 54
'MsgBox("Grade D")
ListBox1.Items.Add("The grade of the mark "&
mark &" is D")
Case 40 To 49
'MsgBox("Grade E")
ListBox1.Items.Add("The grade of the mark "&
mark &" is E")
Case 35 To 39
'MsgBox("Grade O")
ListBox1.Items.Add("The grade of the mark "&
mark &" is O")
Case Else
'MsgBox("Grade F")
ListBox1.Items.Add("The grade of the mark "&
mark &" is F")
EndSelect

5 [email protected] 0777634287/0712389336
EndIf
x += 1
Loop
EndSub
__
____________________________________________________________________
__________________
PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim x, mark AsInteger
x = 0
Do
mark = InputBox("Enter a mark")
If mark > 0 And mark <= 100 Then
SelectCase mark
CaseIs>= 70 ', Is <= 100
'MsgBox("Grade A")
ListBox1.Items.Add("The grade of the mark "&
mark &" is A")
Case 65 To 69
'MsgBox("Grade B")
ListBox1.Items.Add("The grade of the mark "&
mark &" is B")
Case 55 To 64
'MsgBox("Grade C")
ListBox1.Items.Add("The grade of the mark "&
mark &" is C")
Case 50 To 54
'MsgBox("Grade D")
ListBox1.Items.Add("The grade of the mark "&
mark &" is D")
Case 40 To 49
'MsgBox("Grade E")
ListBox1.Items.Add("The grade of the mark "&
mark &" is E")
Case 35 To 39
'MsgBox("Grade O")
ListBox1.Items.Add("The grade of the mark "&
mark &" is O")
Case Else
'MsgBox("Grade F")
ListBox1.Items.Add("The grade of the mark "&
mark &" is F")
EndSelect
EndIf
x += 1
LoopUntil x = 2
EndSub

6 [email protected] 0777634287/0712389336
____________________________________________________________________
__________________
PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim names(4) AsString
Dim x, y AsInteger, temp AsString
x = 0
DoWhile x < 5
names(x) = InputBox("Enter a name")
ListBox1.Items.Add(names(x))
x += 1
Loop
For x = 0 To 4
For y = 0 To 3
If names(y) > names(y + 1) Then
temp = names(y)
names(y) = names(y + 1)
names(y + 1) = temp
EndIf
Next
Next
x = 0
ListBox2.Items.Clear()
ListBox1.Items.Clear()
Do
ListBox2.Items.Add(names(x))
ListBox1.Items.Add(names(x))

x = x + 1
LoopUntil x = 5
EndSub

____________________________________________________________________
__________________
PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Dim names(4) AsString
Dim x AsInteger
x = 0
ListBox2.Items.Clear()
DoWhile x < 5
names(x) = InputBox("Enter a name")
ListBox2.Sorted = True
x += 1
Loop
EndSub
EndClass

7 [email protected] 0777634287/0712389336

You might also like