Makindo Medical Notes"One small step for man, one large step for Makindo" |
|
---|---|
Download all this content in the Apps now Android App and Apple iPhone/Pad App | |
MEDICAL DISCLAIMER: The contents are under continuing development and improvements and despite all efforts may contain errors of omission or fact. This is not to be used for the assessment, diagnosis, or management of patients. It should not be regarded as medical advice by healthcare workers or laypeople. It is for educational purposes only. Please adhere to your local protocols. Use the BNF for drug information. If you are unwell please seek urgent healthcare advice. If you do not accept this then please do not use the website. Makindo Ltd. |
Visual Basic (VB) is an event-driven programming language developed by Microsoft. It is designed to be easy to learn and use, providing a graphical user interface (GUI) to modify code by dragging and dropping objects and defining their behavior and appearance. VB is commonly used for developing Windows applications and automating tasks in Microsoft Office.
' This is a single-line comment
' This is a ' multi-line comment ' in Visual Basic
Dim age As Integer Dim height As Double Dim name As String Dim isActive As Boolean
If age > 18 Then Console.WriteLine("Adult") Else Console.WriteLine("Minor") End If
For i As Integer = 1 To 5 Console.WriteLine(i) Next Dim j As Integer = 1 While j <= 5 Console.WriteLine(j) j += 1 End While Dim k As Integer = 1 Do While k <= 5 Console.WriteLine(k) k += 1 Loop
Function Add(a As Integer, b As Integer) As Integer Return a + b End Function Sub Main() Dim sum As Integer = Add(5, 3) Console.WriteLine("Sum: " & sum) End Sub
Sub Greet(name As String) Console.WriteLine("Hello, " & name & "!") End Sub Sub Main() Greet("Alice") End Sub
Try Dim result As Integer = 10 / 0 Catch ex As DivideByZeroException Console.WriteLine("Cannot divide by zero!") End Try
Class Dog Public Name As String Public Age As Integer Public Sub New(name As String, age As Integer) Me.Name = name Me.Age = age End Sub Public Sub Bark() Console.WriteLine(Name & " says woof!") End Sub End Class Sub Main() Dim myDog As New Dog("Buddy", 3) myDog.Bark() End Sub
Class Animal Public Name As String Public Sub Speak() Console.WriteLine("Animal speaks") End Sub End Class Class Dog Inherits Animal Public Sub Speak() Console.WriteLine(Name & " says woof!") End Sub End Class Sub Main() Dim myDog As New Dog() myDog.Name = "Buddy" myDog.Speak() End Sub
Class Animal Public Overridable Sub Speak() Console.WriteLine("Animal speaks") End Sub End Class Class Dog Inherits Animal Public Overrides Sub Speak() Console.WriteLine("Dog barks") End Sub End Class Class Cat Inherits Animal Public Overrides Sub Speak() Console.WriteLine("Cat meows") End Sub End Class Sub Main() Dim myDog As Animal = New Dog() Dim myCat As Animal = New Cat() myDog.Speak() ' Output: Dog barks myCat.Speak() ' Output: Cat meows End Sub
' This code is auto-generated when you design a form using the Visual Studio GUI designer Public Class MainForm Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click MessageBox.Show("Button clicked!") End Sub End Class
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click MessageBox.Show("Button clicked!") End Sub
Imports System.Data.SqlClient Sub Main() Dim connectionString As String = "Data Source=(local);Initial Catalog=MyDatabase;Integrated Security=True" Dim query As String = "SELECT * FROM MyTable" Using connection As New SqlConnection(connectionString) connection.Open() Dim command As New SqlCommand(query, connection) Dim reader As SqlDataReader = command.ExecuteReader() While reader.Read() Console.WriteLine(reader("ColumnName").ToString()) End While End Using End Sub
Visual Basic is a versatile and user-friendly programming language ideal for developing Windows applications and automating tasks. It supports procedural, object-oriented, and event-driven programming. Key features include easy GUI development, robust data access, and comprehensive error handling. Understanding its syntax, control structures, object-oriented principles, and data access techniques is essential for effective Visual Basic programming.
4/4 Important computer algorithms in Visual Basic and Python ChatGPT html Copy code
Sub BubbleSort(arr() As Integer) Dim n As Integer = arr.Length Dim temp As Integer For i As Integer = 0 To n - 2 For j As Integer = 0 To n - 2 - i If arr(j) > arr(j + 1) Then temp = arr(j) arr(j) = arr(j + 1) arr(j + 1) = temp End If Next Next End Sub
def bubble_sort(arr): n = len(arr) for i in range(n - 1): for j in range(n - 1 - i): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] arr = [5, 3, 8, 4, 2] bubble_sort(arr) print(arr)
Sub QuickSort(arr() As Integer, low As Integer, high As Integer) If low < high Then Dim pi As Integer = Partition(arr, low, high) QuickSort(arr, low, pi - 1) QuickSort(arr, pi + 1, high) End If End Sub Function Partition(arr() As Integer, low As Integer, high As Integer) As Integer Dim pivot As Integer = arr(high) Dim i As Integer = low - 1 For j As Integer = low To high - 1 If arr(j) < pivot Then i += 1 Dim temp As Integer = arr(i) arr(i) = arr(j) arr(j) = temp End If Next arr(high) = arr(i + 1) arr(i + 1) = pivot Return i + 1 End Function
def quick_sort(arr, low, high): if low < high: pi = partition(arr, low, high) quick_sort(arr, low, pi - 1) quick_sort(arr, pi + 1, high) def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] < pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 arr = [5, 3, 8, 4, 2] quick_sort(arr, 0, len(arr) - 1) print(arr)
Function LinearSearch(arr() As Integer, x As Integer) As Integer For i As Integer = 0 To arr.Length - 1 If arr(i) = x Then Return i End If Next Return -1 End Function
def linear_search(arr, x): for i in range(len(arr)): if arr[i] == x: return i return -1 arr = [5, 3, 8, 4, 2] print(linear_search(arr, 4))
Function BinarySearch(arr() As Integer, x As Integer) As Integer Dim low As Integer = 0 Dim high As Integer = arr.Length - 1 While low <= high Dim mid As Integer = (low + high) \ 2 If arr(mid) = x Then Return mid ElseIf arr(mid) < x Then low = mid + 1 Else high = mid - 1 End If End While Return -1 End Function
def binary_search(arr, x): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == x: return mid elif arr[mid] < x: low = mid + 1 else: high = mid - 1 return -1 arr = [2, 3, 4, 5, 8] print(binary_search(arr, 4))
Sub DFS(graph As Dictionary(Of Integer, List(Of Integer)), v As Integer, visited As HashSet(Of Integer)) visited.Add(v) Console.WriteLine(v) For Each neighbor As Integer In graph(v) If Not visited.Contains(neighbor) Then DFS(graph, neighbor, visited) End If Next End Sub
def dfs(graph, v, visited): visited.add(v) print(v) for neighbor in graph[v]: if neighbor not in visited: dfs(graph, neighbor, visited) graph = { 0: [1, 2], 1: [0, 3, 4], 2: [0], 3: [1], 4: [1] } visited = set() dfs(graph, 0, visited)
Sub BFS(graph As Dictionary(Of Integer, List(Of Integer)), start As Integer) Dim visited As New HashSet(Of Integer) Dim queue As New Queue(Of Integer) visited.Add(start) queue.Enqueue(start) While queue.Count > 0 Dim v As Integer = queue.Dequeue() Console.WriteLine(v) For Each neighbor As Integer In graph(v) If Not visited.Contains(neighbor) Then visited.Add(neighbor) queue.Enqueue(neighbor) End If Next End While End Sub
from collections import deque def bfs(graph, start): visited = set() queue = deque([start]) visited.add(start) while queue: v = queue.popleft() print(v) for neighbor in graph[v]: if neighbor not in visited: visited.add(neighbor) queue.append(neighbor) graph = { 0: [1, 2], 1: [0, 3, 4], 2: [0], 3: [1], 4: [1] } bfs(graph, 0)
Function Fibonacci(n As Integer) As Integer Dim memo(n) As Integer memo(0) = 0 memo(1) = 1 For i As Integer = 2 To n memo(i) = memo(i - 1) + memo(i - 2) Next Return memo(n) End Function
def fibonacci(n): memo = [0] * (n + 1) memo[1] = 1 for i in range(2, n + 1): memo[i] = memo[i - 1] + memo[i - 2] return memo[n] print(fibonacci(10))
Function LCS(X As String, Y As String) As Integer Dim m As Integer = X.Length Dim n As Integer = Y.Length Dim L(m + 1, n + 1) As Integer For i As Integer = 0 To m For j As Integer = 0 To n If i = 0 Or j = 0 Then L(i, j) = 0 ElseIf X(i - 1) = Y(j - 1) Then L(i, j) = L(i - 1, j - 1) + 1 Else L(i, j) = Math.Max(L(i - 1, j), L(i, j - 1)) End If Next Next Return L(m, n) End Function
def lcs(X, Y): m = len(X) n = len(Y) L = [[0] * (n + 1) for i in range(m + 1)] for i in range(m + 1): for j in range(n + 1): if i == 0 or j == 0: L[i][j] = 0 elif X[i - 1] == Y[j - 1]: L[i][j] = L[i - 1][j - 1] + 1 else: L[i][j] = max(L[i - 1][j], L[i][j - 1]) return L[m][n] print(lcs("AGGTAB", "GXTXAYB"))
Understanding and implementing common algorithms in Visual Basic and Python is crucial for developing efficient and effective software solutions. This includes sorting algorithms like Bubble Sort and Quick Sort, search algorithms like Linear Search and Binary Search, graph algorithms like DFS and BFS, and dynamic programming solutions like the Fibonacci sequence and Longest Common Subsequence. Mastery of these algorithms enhances problem-solving skills and coding proficiency in both languages.