If-Else, also known as If-Then-Else statements are used for basic conditional logic.
Syntax:
If condition Then
statements
ElseIf condition2 Then
More Statements
Else
else statements
End If
Just like if statement, it is always followed by “End If” to show that the if-else block is over.
Example:
Dim n As Integer = 5
If n Mod 2 = 0 Then
Console.WriteLine("Even")
Else
Console.WriteLine("Odd")
End If
The timer control is a looping control used to repeat any task in a given time interval. It is an important control used in Client-side and Server-side programming, also in Windows Services. It is used to execute an application after a specific amount of time. Once the timer is enabled, it generates a tick event handler to perform any defined task in its time interval property. [1]
The Windows Forms TrackBar control (also sometimes called a “slider” control) is used for navigating through a large amount of information or for visually adjusting a numeric setting.
ADO.NET(Active Data Objects .NET) is the database access framework used to connect to data sources like MS SQL Server, Microsoft Access, Oracle SQL, MySQL/MariaDB, SQLite, direct XML, etc
ADO.NET has many features like:
In Visual Basic, loop statements are used to run code repeatedly while the condition is maintained.
There are 4 types of Loops:
While condition
statements
End While
While index <= 10
Console.WriteLine(index.ToString)
index += 1
End While
Do { While | Until } condition
statements
Loop
Do While index <= 10
Console.WriteLine(index.ToString)
index += 1
Loop
For counter = start To End
statements
Next
For index As Integer = 1 To 5
Console.WriteLine(index.ToString)
Next
For Each element In group
statements
Next
Dim arr() As Integer = {1, 2, 3, 4, 5}
For Each item As Integer In arr
Console.WriteLine(item)
Next
| ADO | ADO.NET | |—| — | | It is based on COM (Component Object Modelling). | It is a CLR (Common Language Runtime) based library. | | It works only when data store is connected. | It does not needs active connection to access data from data store. | | It has feature of locking. | It does not have feature of locking. | It access and store data from data source by recordset object. | It access and store data from data source by dataset object. | | XML integration is not feasible in ADO. | XML integration is feasible in ADO.NET. | | In ADO, data is stored in binary form. | While in this, data is stored in XML. | | It allow us to create client side cursors only. | It give us the choice of using weather client side and server side cursors. | | It requires SQL JOINs and UNIONs to combine data from multiple tables in a single result table. | It uses DataRelational objects, for combining data from multiple tables without requiring JOINs and UNIONs. | | It supports sequential access of rows in a RecordSet. | It allows completely non-sequential data access in DataSet through collection based hierarchy. |
ComboBox control - is used to display more than one item in a drop-down list. It is a combination of Listbox and Textbox in which the user can input only one item. Furthermore, it also allows a user to select an item from a drop-down list. [1]
Imports System.Windows.Forms
Public Class Form1
Private Sub Form1(sender As Object, e As EventArgs) Handles Me.Load
Fruit.Items.Add("Banana")
Fruit.Items.Add("Cherry")
Fruit.Items.Add("Orange")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Textbox1.Text = Fruit.Text
End Sub
End Class
PictureBox control - is used to display the images on Windows Form. The PictureBox control has an image property that allows the user to set the image at runtime or design time. [1]
Public Class Picturebx
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Dim Str As String = "C:\Users\AMIT YADAV\Desktop\"
PictureBox1.Image = Image.FromFile("C:\Users\AMIT YADAV\Desktop\jtp2.png")
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Height = 250
PictureBox1.Width = 400
Label1.Visible = False
End Sub
Private Sub Picturebx_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "javaTpoint.com" 'Set the title name for the form
Button1.Text = "Show"
Label1.Text = "Click to display the image"
Label1.ForeColor = ForeColor.Green
End Sub
End Class
DataReader
is a forward-only, read-only cursor used to retrieve a stream of data from a database.
Key Features:
DataReader
can only traverse the data in a forward direction. Once you read a row, you cannot go back.DataReader
. It is strictly for reading data.DataReader
requires an open connection to the database while reading data. This means that the connection must remain open for the duration of the read operation.DataAdapter
serves as a bridge between a DataSet and a data source.
DataReader
.DataAdapter
allows you to work with data in a disconnected manner.DataAdapter
can fill multiple tables in a DataSet and can also manage relationships between those tables.DataAdapter
works with DataSet, allowing you to store data in memory and manipulate it without needing to constantly connect to the database.Description: A TextBox
control allows users to input and edit text. It is commonly used for forms where user input is required.
Properties:
TextBox
. This is the most commonly used property.True
, allows the TextBox
to accept multiple lines of text. This is useful for comments or descriptions.True
, the user cannot change the text in the TextBox
, making it useful for displaying information that should not be edited.Practical Use: A TextBox
is often used in forms for input fields like name, email, or password. For example, in a login form, you would typically have two TextBox
controls for the username and password.
Description: A ComboBox
combines a drop-down list with an editable text box, allowing users to either select an item from a list or enter a custom value.
Properties:
ComboBox
. You can add or remove items dynamically at runtime.ComboBox
behaves. Options include DropDown
, DropDownList
, and Simple
. DropDownList
prevents users from entering custom values.ComboBox
to suggest items as the user types, enhancing user experience.Practical Use: A ComboBox
is often used for selecting options from a predefined list, such as selecting a country from a list of countries in a registration form. It can also allow users to input custom values if needed.
Description: A ListBox
displays a list of items from which the user can select one or more items. It is useful for presenting a collection of options.
Properties:
ComboBox
, this property holds the collection of items in the ListBox
.ListBox
. Options include One
(single selection), MultiSimple
, and MultiExtended
(multiple selections).True
, enables a horizontal scrollbar if the items exceed the width of the ListBox
.Practical Use: A ListBox
is often used to display options for selection, such as a list of available products in an e-commerce application. Users can select multiple items (e.g., multiple products) to add to their cart.
Description: A PictureBox
control is used to display images in a Windows Forms application. It can show bitmaps, icons, or other types of images.
Properties:
PictureBox
. You can load images from files, resources, or streams.PictureBox
. Options include Normal
, StretchImage
, AutoSize
, and CenterImage
. This allows you to control how the image fits within the control.PictureBox
, which can be useful if the image does not fill the entire control.PictureBox
, which can be set to None
, FixedSingle
, or Fixed3D
.Practical Use: A PictureBox
is commonly used in applications that require image display, such as a photo viewer or an application that showcases product images. For instance, in a gallery application, each PictureBox
can display a different image, allowing users to browse through a collection.
| Parameters | Sub Procedures | Functions | |————|—————-|———–| | 1 | A subprocedure is not associated with an event. | A function is also not associated with an event. | | 2 | A subprocedure is called whenever it is required to perform certain tasks. It returns control to the calling code after performing a task. | A function is called whenever a value is required to be returned to the calling code after performing a task. | | 3 | A subprocedure does not return a value to the calling code. | Functions return a value to the calling code. | | 4 | A subprocedure cannot be used with an expression. | Functions are used in an expression. | | 5 | A subprocedure helps to make the code readable, and easy to modify and debug. | In functions, it is not easy to modify and debug the code. | | 6 | A subprocedure is a generalized type of function. | A function is a specific type of procedure. | | 7 | A subprocedure is declared with the keyword Sub. | A function is declared with the keyword Function. |
[1]
Class Program
Sub Main()
DisplayMessage()
End Sub
Sub DisplayMessage()
Console.WriteLine("Hello, this is a subroutine!")
End Sub
End Class
Class Program
Sub Main()
Dim result As Integer
result = AddNumbers(5, 10)
Console.WriteLine("The sum is: " & result)
Console.ReadLine()
End Sub
Function AddNumbers(a As Integer, b As Integer) As Integer
Return a + b
End Function
End Class
ADO.NET has two main components that are used for accessing and manipulating data are the .NET Framework data provider and the DataSet. [1]
Docking and undocking in Visual Studio for Windows Forms refers to the ability to arrange controls within a form. Docking allows a control to attach itself to one of the edges of its parent container, automatically resizing to fill the available space. This is useful for creating layouts that adapt to different form sizes and orientations. Undocking, on the other hand, allows a control to be separated from its parent container, enabling it to float freely or be moved to another location, such as a different monitor. [1]
Progress Bar - It represents a Windows progress bar control. It is used to provide visual feedback to your users about the status of some task. It shows a bar that fills in from left to right as the operation progresses. Similar to what we all seen when downloading or sharing any content.
Taskbar - TODO
To create a Visual Basic application project. The project type comes with all the template files that you need.
Public Class Form1
Private Sub Button1(sender As Object, e As EventArgs) Handles Button1.Click
label1.Text = "Hello World!"
End Sub
End Class
Conditional Statements are already answered in Q1.
Class Genshin
' Declaration of variable str
Dim str As String = "Impact"
Sub Main()
' if str equal to "Impact", below Statement will be executed.
If str = "Impact" Then
Console.WriteLine("Get Help!")
End If
Console.WritLine("press any key to TOUCH GRASS?")
Console.ReadKey()
End Sub
End Class
Class Pablo
Sub Main()
' 'vbCrLf' is used to jump in the next line just like \n in C.
Console.Write(" The number starts from 1 to 10 " & vbCrLf)
For i As Integer = 1 To 10 Step 1
' if the condition is true, the following statement will be executed
Console.WriteLine(" Number is {0} ", i)
' after completion of each iteration, next will update the variable counter
Next
Console.WriteLine(" Press any key to BE FREEEE!")
Console.ReadKey()
End Sub
End Class
An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords: try, catch, finally, and throw.
Syntax:
try {
// statements causing exception
} catch( ExceptionName e1 ) {
// error handling code
} catch( ExceptionName e2 ) {
// error handling code
} finally {
// statements to be executed
}