Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Wednesday, March 22, 2023

QBASIC Sub Procedure: An Overview of the Basics


QBASIC Sub Procedure: An Overview of the Basics


QBASIC Sub Procedure


Introduction:


If you are a beginner in programming, you might have come across QBASIC, a high-level programming language developed by Microsoft for DOS operating systems. QBASIC is an easy-to-learn language that is used to write simple and basic programs. In this article, we will explore QBASIC sub procedures, which are an essential part of this programming language.

What is a QBASIC Sub Procedure?


In QBASIC, a sub procedure is a section of code that performs a specific task. It is a collection of statements that perform a particular action or set of actions. Sub procedures are used to break down a program into smaller and more manageable parts. This helps in writing efficient and maintainable code.

Types of QBASIC Sub Procedures


There are two types of sub procedures in QBASIC:

Sub Procedures with Parameters


A sub procedure with parameters takes input values when it is called. These input values are passed to the sub procedure as parameters. The sub procedure performs the required operations on the parameters and returns a value, which can be used by the calling program.

Sub Procedures without Parameters


A sub procedure without parameters does not take any input values. It performs a specific task and returns a value, which can be used by the calling program.

How to Create a QBASIC Sub Procedure?


Creating a sub procedure in QBASIC is easy. Here are the steps to follow:

Step 1: Declare the Sub Procedure

To declare a sub procedure in QBASIC, use the SUB keyword, followed by the name of the sub procedure, and any parameters that it takes. 

For example:

mySubProcedure (param1, param2)


Step 2: Write the Code

After declaring the sub procedure, write the code that performs the required task. For example:

PRINT param1 + param2

Step 3: End the Sub Procedure

To end the sub procedure, use the END SUB keyword. 
For example:

END SUB

Calling a QBASIC Sub Procedure


Once you have created a sub procedure in QBASIC, you can call it from another part of your program. To call a sub procedure, use its name, followed by any parameters that it requires. 

For example:

mySubProcedure 10, 20



Benefits of Using QBASIC Sub Procedures

  • Using sub procedures in QBASIC offers several benefits:
  • Sub procedures make your code more organized and easier to understand.
  • They allow you to reuse code, which saves time and effort.
  • Sub procedures make it easier to debug your code since you can test each sub procedure independently.

Example 1: 
Input any two numbers and display the sum using calling with parameters.

QBASIC Sub Procedure

QBASIC Sub Procedure



Example 2: Input any two numbers and display the sum using without calling the parameter.




Conclusion

QBASIC sub procedures are a powerful tool that can help you write efficient and maintainable code. They allow you to break down your program into smaller and more manageable parts, making it easier to write and debug your code. If you are just starting with QBASIC, mastering sub procedures is an excellent first step.


You may also Read:
QBASIC program to display only vowel letters from input string


FAQs


1) What is QBASIC?

Ans: QBASIC is a high-level programming language developed by Microsoft for DOS operating systems.

2) What are sub procedures in QBASIC?

Ans: Sub procedures in QBASIC are a collection of statements that perform a specific task. They are used to break down a program into smaller and more manageable parts.

3) How do you create a QBASIC sub procedure?

Ans: To create a QBASIC sub procedure, use the SUB keyword, followed by the name of the sub procedure, and any parameters that it takes. Write the code that performs the required task, and then end the sub procedure using the END SUB keyword.

4) What are the benefits of using QBASIC sub procedures?

Ans: Using QBASIC sub procedures makes your code more organized and easier to understand

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages