VBNET Console HelpCodes
VBNET Console HelpCodes
NET CODES
PublicClassForm1
EndSub
EndClass
________________________________________________________________
PublicClassForm1
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
________________________________________________________________
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
4 [email protected] 0777634287/0712389336
Case Else
'MsgBox("Grade F")
ListBox1.Items.Add("The grade of the mark "&
mark &" is F")
EndSelect
EndIf
Next
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