Functions in Qbasic

 In this chapter we learn about following:

  • Function and its types
  • Types of library function
  • The use of library function in Qbasic

Function is a set of codes which helps to perform a task quickly and easily and returns somethings. Function manipulates data passes to it and returns either a string a numeric value. Once a function is written and debugged it can be reused. Function as a unique name which is known as calling function.

Qbasic supports two types of function. They are discussed below:
  1. User define function
  2. Library (build in ) function
User define function is define by user in real time to perform specific task. The function has to be created before it is used in the program. The programmer define this type of function if Qbasic does not provide library function using FUNCTION ..... END FUNCTION statement. nuna(),sum(), pro(),eo$(), count() etc are example of user define function that can be defined only in real time to solve the specific problems.


library (Build in) function
The library function are used in Qbasic to make programming more coinvent to the programmer associated with mathematical application. These function are ready-made formulas that help us to do calculation more easily and quickly. Library function accepts data and returns a value. Qbasic has many library function which are prepared by the QBasic developer.  library function are also called build in function. There are two types of library function used in Qbasic. They are:
  • String function
  • Mathematical function 
A string library function always gives a string value where as a numeric library function processes a numeric value.

String function
string function are used to manipulate string. A string can be defined as a set of alphanumeric characters.

some of the string manipulating function used in Qbasic are described below:

LEFT$()
left$ takes 2 arguments or parameter. Left is string function that returns specific number of character from the left side of supplied string and returns the value.

syntax:
left$(string expression, length)

example
cls
a$="computer"
print left$(a$,4)
end

comp



right$()
right$ function takes 2 argument. the right$ is a sting library or in build function that returns specific number of characters from the right side of supplied string and returns the value.

syntax:
right$(string expressing, length)

eg

cls
a$="computer"
print right$(a$,5)
end

outputer
puter

MID$()
the mid$ is a string function that returns specified number of character from the specified location of string. unlike left$ and right$ function it takes 3 arguments or parameter.
syntax:
mid$(string, starting position, length)

eg
CLS
a$ = "aakansha"
PRINT MID$("aakansha", 3, 3)
END


len( )
it is a mathematical function.Is has 1 argument which is string. It give number of letter of the provided string.
syntax:
len(string)
eg
 
UCASE$( )
it is string function as it give output string.  it changes into capital letters

 
LCASE$( )
it is string function as it give output string. it changes into small letters

 
ACS( ) 
it is number function as it give output number
ASCII(American standard Code for Information Interchange) .
A=65,B=66,C=67........Z=90
a=97,b=98...........z=122
 
chr$()
 
it is string function as it give output string. it gives corresponding  string of given
ASCII value.


str$( )
5 "5"
6 "6"
 
it converts number into string

val()
it converts string into number.
 


Comments