0% found this document useful (0 votes)
19 views7 pages

Visual Basic .NET Code Examples

Binary trees

Uploaded by

inchristjoe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Visual Basic .NET Code Examples

Binary trees

Uploaded by

inchristjoe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VISUAL BASIC.

NET CODES
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Dim num1, num2, sum AsInteger
num1 = InputBox("Enter first number")
num2 = InputBox("Entr second number")
sum = num1 + num2
[Link] = sum
EndSub

PrivateSub Button2_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] = Val([Link]) + Val([Link])
EndSub

PrivateSub Button3_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Dim num1, num2, total AsInteger
num1 = [Link]
num2 = [Link]
total = Val(num1) + Val(num2)
[Link] = total

EndSub
EndClass

________________________________________________________________
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Dim num1 AsInteger, num2 AsInteger, num3 AsInteger
num1 = [Link]
num2 = [Link]
num3 = num1 + num2
[Link] = num3
[Link] = num3

EndSub
____________________________________________________________________

PrivateSub Form1_Load(ByVal sender As [Link], ByVal e As


[Link]) [Link]
[Link] = [Link]
EndSub

1 lovemoremanyeruke@[Link] 0777634287/0712389336
PrivateSub Button2_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim x AsInteger, p AsInteger
For x = 0 To 100
p = x Mod 2
If p = 1 Then
[Link](x)
Else

EndIf
Next
EndSub
EndClass
____________________________________________________________________

ModuleModule1

Sub Main()
Dim num1, num2, total As Integer
[Link]("Enter first number")
num1 = [Link]()
[Link]("Enter second number")
num2 = [Link]()
total = num1 + num2
[Link]("Total is " & total)
[Link]()
EndSub

EndModule

____________________________________________________________________

PublicClassForm1
PrivateSub Button1_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link]()
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 + [Link](b ^ 2 - 4 * a * c)) / 2 * a
y = (-b - [Link](b ^ 2 - 4 * a * c)) / 2 * a
[Link]("The first root for the equation is
"& y)
[Link]("The second root for the equation is
"& x)

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

2 lovemoremanyeruke@[Link] 0777634287/0712389336
[Link]("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 [Link], ByVal e As


[Link]) Handles [Link]
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
[Link]("The word "& names &" is a
palindrome")
MsgBox("The word "& (names) &" is a palindrome")
Else
[Link]("The word "& names &" is not a
palindrome")
MsgBox("The word "& (names) &" is not a palindrome")
EndIf
EndSub
____________________________________________________________________
__________________________
PrivateSub Button2_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim x, y AsInteger
For x = 620 To 500 Step -1
y = x Mod 2
If y = 1 Then
[Link](x)
Else
[Link](x)
EndIf
Next
EndSub
EndClass

________________________________________________________________
ModuleModule1
Function Add(ByVal a, ByVal b) AsInteger
3 lovemoremanyeruke@[Link] 0777634287/0712389336
Add = a + b
EndFunction
Sub Main()
Dim fn, sn, answer AsInteger
[Link]("Enter first number")
fn = [Link]()
[Link]("Enter first number")
sn = [Link]()
answer = Add(fn, sn)
[Link]("The sum is "& answer)
[Link]()
EndSub

EndModule
________________________________________________________________
PublicClassForm1

PrivateSub Button1_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
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")
[Link]("The grade of the mark "&
mark &" is A")
Case 65 To 69
'MsgBox("Grade B")
[Link]("The grade of the mark "&
mark &" is B")
Case 55 To 64
'MsgBox("Grade C")
[Link]("The grade of the mark "&
mark &" is C")
Case 50 To 54
'MsgBox("Grade D")
[Link]("The grade of the mark "&
mark &" is D")
Case 40 To 49
'MsgBox("Grade E")
[Link]("The grade of the mark "&
mark &" is E")
Case 35 To 39
'MsgBox("Grade O")
[Link]("The grade of the mark "&
mark &" is O")

4 lovemoremanyeruke@[Link] 0777634287/0712389336
Case Else
'MsgBox("Grade F")
[Link]("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 [Link], ByVal e As
[Link]) Handles [Link]
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")
[Link]("The grade of the mark "&
mark &" is A")
Case 65 To 69
'MsgBox("Grade B")
[Link]("The grade of the mark "&
mark &" is B")
Case 55 To 64
'MsgBox("Grade C")
[Link]("The grade of the mark "&
mark &" is C")
Case 50 To 54
'MsgBox("Grade D")
[Link]("The grade of the mark "&
mark &" is D")
Case 40 To 49
'MsgBox("Grade E")
[Link]("The grade of the mark "&
mark &" is E")
Case 35 To 39
'MsgBox("Grade O")
[Link]("The grade of the mark "&
mark &" is O")
Case Else
'MsgBox("Grade F")
[Link]("The grade of the mark "&
mark &" is F")
EndSelect

5 lovemoremanyeruke@[Link] 0777634287/0712389336
EndIf
x += 1
Loop
EndSub
__
____________________________________________________________________
__________________
PrivateSub Button3_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
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")
[Link]("The grade of the mark "&
mark &" is A")
Case 65 To 69
'MsgBox("Grade B")
[Link]("The grade of the mark "&
mark &" is B")
Case 55 To 64
'MsgBox("Grade C")
[Link]("The grade of the mark "&
mark &" is C")
Case 50 To 54
'MsgBox("Grade D")
[Link]("The grade of the mark "&
mark &" is D")
Case 40 To 49
'MsgBox("Grade E")
[Link]("The grade of the mark "&
mark &" is E")
Case 35 To 39
'MsgBox("Grade O")
[Link]("The grade of the mark "&
mark &" is O")
Case Else
'MsgBox("Grade F")
[Link]("The grade of the mark "&
mark &" is F")
EndSelect
EndIf
x += 1
LoopUntil x = 2
EndSub

6 lovemoremanyeruke@[Link] 0777634287/0712389336
____________________________________________________________________
__________________
PrivateSub Button4_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim names(4) AsString
Dim x, y AsInteger, temp AsString
x = 0
DoWhile x < 5
names(x) = InputBox("Enter a name")
[Link](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
[Link]()
[Link]()
Do
[Link](names(x))
[Link](names(x))

x = x + 1
LoopUntil x = 5
EndSub

____________________________________________________________________
__________________
PrivateSub Button5_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim names(4) AsString
Dim x AsInteger
x = 0
[Link]()
DoWhile x < 5
names(x) = InputBox("Enter a name")
[Link] = True
x += 1
Loop
EndSub
EndClass

7 lovemoremanyeruke@[Link] 0777634287/0712389336

Common questions

Powered by AI

The grading system uses a Select Case statement to evaluate the entered mark. It assigns grades based on specific ranges: A for 70 and above, B for 65-69, C for 55-64, D for 50-54, E for 40-49, O for 35-39, and F for marks below 35. Messages corresponding to the grade are displayed, and the grade is added to a list .

The code displays results using various UI elements such as labels, text boxes, and message boxes. For example, results of arithmetic operations are shown in text boxes or labels, palindrome verification uses list boxes and message boxes, while calculated grades are added to list boxes. This provides immediate feedback and interactivity within the application .

Real-time input validation prompts users for a mark only within the valid range (0 to 100). It uses conditional checks to ensure the inputs fall within this range, displaying error messages for invalid inputs and requesting re-entry. This enhances the accuracy and quality of user data acquisition .

The program calculates the result of addition by asking the user to input two integers via the console, reads them with ReadLine, computes their sum using a predefined Function Add, and prints the result using WriteLine. The code demonstrates interactive user input and output in a console application .

The code uses a simple bubble sort algorithm to arrange names. It compares adjacent names and swaps them if they are in the wrong order. This process repeats from the first to the fourth element in two nested loops. After sorting, the names are added to two list boxes, presenting the sorted order .

Names are input through InputBox within a Do-While loop that continues until five names are entered. Once collected, the program sorts the names using a bubble sort and displays them in multiple list boxes, effectively handling continuous input and presenting the processed data in ordered form .

The code uses a loop to reverse the input string one character at a time. It compares the original string with the reversed version. If they are the same, it determines the word is a palindrome and displays a message box and adds it to a list, indicating it is a palindrome. If not, it indicates the word is not a palindrome in similar fashion .

Integer addition is performed by prompting the user to input numbers through input boxes. The input values are read as strings, converted to integers, and then summed using the '+' operator. The result is then displayed on the interface either through a label or a text box .

The code iteratively checks each number within a specified range using a For loop and the modulus operator. If the number mod 2 results in 1, the number is odd and added to ListBox1. Otherwise, it is added to ListBox2 as an even number. This logic efficiently separates odd and even numbers .

The code computes quadratic roots using the quadratic formula. It first checks the discriminant (b^2 - 4ac). If positive, it calculates two roots via the quadratic formula, displaying them if they exist. If zero, it calculates and displays one root. If negative, it informs there are no real roots .

You might also like