🖥️Chapter 5: Programming in Visual Studio
Class 8 CBSE Computer | By Pratap Sanjay Sir

📌 1. Creating a Simple Visual Basic Program
- Open Visual Studio 2017.
- Go to File → New → Project.
- Select Windows Forms App (.NET Framework).
- Give your project a name and click OK.
- Drag and drop controls like Label, TextBox, and Button from the Toolbox.
- Double-click the Button to write the code in its click event.
Example:
Private Sub btnClickMe_Click(sender As Object, e As EventArgs) Handles btnClickMe.Click
MessageBox.Show("Hello, Welcome to VB!")
End Sub
📌 2. Basic Elements of a Visual Basic Program
- Namespace: Container for classes.
- Class: Defines the structure of the program.
- Method: Performs specific tasks (like Button click).
- Controls: UI elements like Label, Button, TextBox.
- Variables: Store and manage data during execution.
🔹 Declaring and Initializing Variables
Dim name As String = "Sanjay"
Dim age As Integer = 14
🔹 Data Types
- Integer: Whole numbers (e.g., 10)
- Double: Decimal values (e.g., 10.5)
- String: Text (e.g., "Hello")
- Boolean: True or False
🔹 Operators
- Arithmetic: +, -, *, /, Mod
- Relational: =, <>, >, <, >=, <=
- Logical: And, Or, Not
- String Concatenation:
&
(used to join text)
Dim message As String = "Hello " & name
📌 3. Control Statements in Visual Basic
🔹 If...Then Statement
If age >= 18 Then
MessageBox.Show("You are eligible to vote")
End If
🔹 If...Then...Else Statement
If marks >= 33 Then
MessageBox.Show("Pass")
Else
MessageBox.Show("Fail")
End If
🔹 Nested If...Then...Else Statement
If marks >= 75 Then
MessageBox.Show("Distinction")
ElseIf marks >= 60 Then
MessageBox.Show("First Division")
ElseIf marks >= 33 Then
MessageBox.Show("Pass")
Else
MessageBox.Show("Fail")
End If
🔹 Select Case Statement
Select Case grade
Case "A"
MessageBox.Show("Excellent")
Case "B"
MessageBox.Show("Good")
Case Else
MessageBox.Show("Try Harder")
End Select
📌 4. Looping Statements
🔹 For...Next Loop
For i = 1 To 5
MessageBox.Show("Number: " & i)
Next
🔹 While...End While Loop
Dim i As Integer = 1
While i <= 5
MessageBox.Show("Count: " & i)
i += 1
End While
🔹 Do...Loop While
Dim i As Integer = 1
Do
MessageBox.Show("Running: " & i)
i += 1
Loop While i <= 5
📌 5. Some Additional Controls
- CheckBox: Select multiple options
- RadioButton: Select one option from many
- ComboBox: Dropdown list
- ListBox: List with multiple selectable items
- Timer: Executes code at set intervals
🔹 CheckBox Example
If chkMath.Checked = True Then
MessageBox.Show("Math is selected")
End If
🔹 RadioButton Example
If rbtnMale.Checked = True Then
MessageBox.Show("Gender: Male")
End If
Chapter 5: Programming in Visual Studio Que. & Ans.
Click here to access all Questions & Answers
Visit Now ⤴
No comments:
Post a Comment