0% found this document useful (0 votes)
7 views5 pages

Visual Basic Programming Examples

Uploaded by

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

Visual Basic Programming Examples

Uploaded by

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

Module Module1

Sub Main(args As String())


[Link]("Ahsan")
[Link]()

End Sub

End Module

-----------------------------------------------------------------------------------
---------------------------------------------------------

Sir Practice
Module Module1

Sub Main()
'DECLARATION
Dim ITEMCODE As Integer
Dim ITEMNAME As String
Dim PRICE As Double
Dim SOLD As Boolean

'ASSIGNMENT
ITEMCODE = 3248
ITEMNAME = "TAPAL CHAI"
PRICE = 800
SOLD = True

'PRODUCING OUTPUT
[Link]("ITEMNAME CODE " & ITEMCODE)
[Link]("ITEMNAME NAME " & ITEMNAME)
[Link]("PRICE " & PRICE)
[Link]("SOLD " & SOLD)
[Link]()
End Sub

End Module
-----------------------------------------------------------------------------------
-------------------------------------------------------------

MY PRACTICE
Module Module1

Sub Main()
'DECLARATION
Dim ITEMCODE As Integer
Dim ITEMNAME As String
Dim PRICE As Double
Dim AGE As Integer

'ASSIGNMENT
ITEMCODE = 1020
ITEMNAME = "Parrot"
PRICE = 25000
AGE = 16

'PRODUCING OUTPUT
[Link]("ITEMNAME CODE " & ITEMCODE)
[Link]("ITEMNAME NAME " & ITEMNAME)
[Link]("PRICE " & PRICE)
[Link]("AGE " & AGE)
[Link]()
End Sub

End Module
-----------------------------------------------------------------------------------
---------------------------------------------------------------

SIR PRACTICE
Module Module1

Sub Main()
'IDE-INTEGRATED DEVELOPMENT ENVIRONMENT
Dim NAME, ADDRESS As String
Dim AGE As Integer
Dim DOA As Date
Dim STUDYING As Boolean
[Link]("ENTER NAME:- ")
NAME = [Link]()
[Link]("ENTER ADDRESS:- ")
ADDRESS = [Link]()
[Link]("ENTER AGE:- ")
AGE = [Link]()
[Link]("ENTER DATE OF ADMISSION:- ")
DOA = [Link]()
[Link]("ENTER ARE YOU STUDYING?:- ")
STUDYING = [Link]()
[Link]("-----------------------------------------")
[Link]("NAME:- " & NAME)
[Link]("ADDRESS:- " & ADDRESS)
[Link]("AGE:- " & AGE)
[Link]("DATE OF ADMISSION:- " & DOA)
[Link]("ARE YOU STUDYING?:- " & STUDYING)
[Link]("------------------------------------------")
[Link]()
End Sub
End Module
-----------------------------------------------------------------------------------
-----------------------------------------------------------------

MY PRACTICE
Module Module1

Sub Main()
'IDE-INTEGRATED DEVELOPMENT ENVIRONMENT
Dim NAME, ADDRESS As String
Dim AGE As Integer
Dim DOA As Date
Dim STUDYING As Boolean
[Link]("ENTER NAME:- ")
NAME = [Link]()
[Link]("ENTER ADDRESS:- ")
ADDRESS = [Link]()
[Link]("ENTER AGE:- ")
AGE = [Link]()
[Link]("ENTER DATE OF ADMISSION:- ")
DOA = [Link]()
[Link]("ENTER ARE YOU STUDYING?:- ")
STUDYING = [Link]()
[Link]("-----------------------------------------")
[Link]("NAME:- " & NAME)
[Link]("ADDRESS:- " & ADDRESS)
[Link]("AGE:- " & AGE)
[Link]("DATE OF ADMISSION:- " & DOA)
[Link]("ARE YOU STUDYING?:- " & STUDYING)
[Link]("------------------------------------------")
[Link]("ENTER NAME:- ")
NAME = [Link]()
[Link]("ENTER ADDRESS:- ")
ADDRESS = [Link]()
[Link]("ENTER AGE:- ")
AGE = [Link]()
[Link]("ENTER DATE OF ADMISSION:- ")
DOA = [Link]()
[Link]("ENTER ARE YOU STUDYING?:- ")
STUDYING = [Link]()
[Link]("-----------------------------------------")
[Link]("NAME:- " & NAME)
[Link]("ADDRESS:- " & ADDRESS)
[Link]("AGE:- " & AGE)
[Link]("DATE OF ADMISSION:- " & DOA)
[Link]("ARE YOU STUDYING?:- " & STUDYING)
[Link]("-----------------------------------------")
[Link]()
End Sub
End Module

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
18 October 2024
Sir Practice

Module Module1

Sub Main()
Dim Number As Integer
[Link]("Enter any number:- ")
Number = [Link]()
If Number = 0 Then End

If Number < 0 Then [Link]("It's a negative number")

If Number > 0 Then [Link]("It's a positive number")

[Link]()
End Sub
End Module

-----------------------------------------------------------------------------------
---------------------------------------------------------------------------
Module Module1

Sub Main()
Dim Number As Integer
[Link]("Enter any number:- ")
Number = [Link]()
If Number < 0 Then
[Link]("You entered a negative number")
[Link]("Negative numbers are not accepted")
[Link]("Run your program again to enter new number")
End If
[Link]()
End Sub
End Module
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------
Module Module1

Sub Main()
Dim Number As Integer
[Link]("Enter any number:- ")
Number = [Link]()
If Number < 0 Then
[Link]("You entered a negative number")
Else
[Link]("You entered either a zero/positive number")
End If
[Link]()
End Sub
End Module
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------
Module Module1
Sub Main()
Dim Grade As Char
[Link]("Enter Grade ")
Grade = UCase([Link]())
If Grade = "U" Then
[Link]("Oops! you got a U")
ElseIf Grade = "E" Then
[Link]("Better luck next time! You got an E")
ElseIf Grade = "D" Then
[Link]("Good Attempt! You got a D")
ElseIf Grade = "C" Then
[Link]("Keep working! You got a C")
ElseIf Grade = "B" Then
[Link]("Well Done! You got a B")
ElseIf Grade = "A" Then
[Link]("Excellent! You got an A")
Else
[Link]("INVALID GRADE")
End If
[Link]()
End Sub
End Module
-----------------------------------------------------------------------------------
------------------------------------------------------------------------------
Module Module1
Sub Main()
Dim Amount, Tax As Integer
[Link]("Enter Bill Amount:- ")
Amount = [Link]()
'Tax %5 if exceeds to 5000
'Tax %10 if exceeds to 10000
If Amount >= 5000 Then
Tax = Amount * 5 / 100
End If

If Amount >= 10000 Then


Tax = Amount * 10 / 100
End If

Amount = Amount + Tax


[Link]("Amount including sales tax " & Amount)
[Link]()
End Sub
End Module
-----------------------------------------------------------------------------------
-------------------------
25 - October - 2024
Case Statement Sir
-----------------------------------------------------------------------------------
-------------------------
Module Module1
Sub Main()
Dim monthno As Integer
Dim monthname As String
[Link]("ENTER MONTH NUMBER ")
monthno = [Link]()
Select Case monthno
Case 1
monthname = "January"
Case 2
monthname = "February"
Case 3
monthname = "March"
Case 4
monthname = "April"
Case 5
monthname = "May"
Case 6
monthname = "June"
Case 7
monthname = "July"
Case 8
monthname = "August"
Case 9
monthname = "September"
Case 10
monthname = "October"
Case 11
monthname = "November"
Case 12
monthname = "December"
Case Else
monthname = "Invalid Month Number Entered"
End Select
[Link](monthname)
[Link]()
End Sub
End Module

Common questions

Powered by AI

The number-checking programs differ primarily in their conditional statement execution. The first one checks if a number is zero, negative, or positive by using separate conditional paths for each type of number . It identifies a positive number if the number is greater than zero, leaving conditions disentangled in separate blocks. Meanwhile, the other variations focus on catching negative numbers specifically and prompting the user to re-run the program for such inputs, whereas non-negative numbers result in a simple, collective message . This distinction illustrates different approaches to error handling and user prompts.

User interaction during data input is implemented through repetitive prompts and user feedback loops. The programming modules utilize the Console.ReadLine() function to capture user inputs and subsequently process these for varied data types such as strings, integers, and booleans . For instance, a prompt requests user entry which is then stored in a corresponding variable; later, the entered information is displayed back for confirmation, ensuring the user is aware of the input capture and processing flow . The processes show a standard input-output interaction cycle in console applications.

The tax calculation logic presented is somewhat reflective of real-world scenarios where tax rates scale with certain thresholds. However, the logic mimics a stepped approach that applies a single rate at each threshold rather than incrementally adding tax percentage across additional brackets, which can be a caveat if real-world considerations include progressive tax models. This model prioritizes simplicity and minimal calculations at the risk of mimicking less dynamic, tiered taxation systems where rate jumps are fixed, less frequently adjusted to transactional specifics .

The logic in the sales tax calculation program possesses limitations due to the sequential if statement configuration without using else-if chaining, leading to potential overwriting of tax calculations without explicit blocking. If an amount qualifies for a higher tax bracket, only that computation is retained. This logic design does not inherently detect or prevent recalculations, risking inefficiencies or oversight in billing scenarios with interconnected conditions . Further, it does not account for compounded tax scenarios where multiple calculations might coexist contextually.

Output formatting in the provided programs for displaying item details and user information is achieved through string concatenation and systematic output structure. Concatenation leverages the '&' operator to append variable values to descriptive string literals. For displaying item details like ITEMCODE, ITEMNAME, and PRICE, the outputs configure each component in a specified order, maintaining a consistent and clear representation . User information displays further break segments with separators surrounding the outputs, establishing clear sections that highlight entered and derived data distinctly, enhancing readability and validating programmatic display functions.

Interactive features in processing and displaying user personal information include sequential prompting and immediate responsiveness through the Console.ReadLine() function. Users input data such as NAME, ADDRESS, AGE iteratively, allowing the program to store these values in pre-defined variables, confirmed back through console output . This feedback loop ensures prompt interaction by echoing entered data and using clear section delineations, reinforcing accuracy in user-data handling, maintaining transparency in what information the program retains and displays, central to interactive console applications.

The Select Case statement is employed to streamline month recognition based on user input. By matching the integer input (month number) against predefined cases, each associated with a specific month name, the program simplifies multiple conditional checks into one coherent block. The use of 'Case' clauses allows the program to cycle through potential matches efficiently before assigning 'monthname' a value corresponding to the matched entry. An additional 'Case Else' provides handling for invalid input, reinforcing the robustness of input validation within the logic .

The grade input handling program utilizes a series of else-if statements to check for specific valid grades. It evaluates the entered character and provides a personalized message for each recognized grade from U to A. If the entered grade does not match any predefined options, the program outputs 'INVALID GRADE' , effectively managing unexpected or incorrect user input by alerting users to input inaccuracies and maintaining program robustness.

The sales tax is calculated based on thresholds: if the bill amount is 5000 or greater, a 5% tax is applied, and if it reaches 10000 or higher, a 10% tax is levied . The code uses sequential if statements to determine which percentage to apply, effectively using only the highest applicable rate, as the higher condition overwrites the previous computation. This illustrates a non-cumulative tax structure as higher amounts overwrite the lower tier's tax calculation.

Variable declaration and initialization are foundational to the program's operation, defining the types of data each variable can hold and assigning initial values where necessary. In each module example, variables such as ITEMCODE, ITEMNAME, PRICE, and SOLD are declared with specific types indicating integer, string, double, and boolean formats respectively . These declarations precede input or computation processes, ensuring that the program assigns memory and allocates suitable space for values. Initial values are explicitly set in sequences once the program logic demands their availability or output utility.

You might also like