On this
article I will discuss some codes that might help you on creating some projects
in VB6
The
following will be discussed on this article
1.
Declaration of Variables
2.
Conditional Statements(if then else, Select
Case)
3.
Loopings ( For Next)
I-
Declaration of Varibles
In declaring a variable the
keyword Dim ,and public this are the
keyword which is commonly used.
the Dim is a declaration of
variable wherein the variable is accessible only on the module/form that you
created for example if you have a form1 and a declare a variable named gamers
then the variable gamers would be accessible only on Form1 if you have 2 forms
then the second form would not have the ability to access this variable.
Public - the public keyword indicates that you want to
declare this function a such way that all of the forms and modules that you
have can access this variable meaning there is no limit on accessing this
variable
After deciding on what would be
the use of the variable(Dim or Public)
you need now to consider what would be the name of the variable the name
of the variable it can be anything but it must be related on the use of the
variable.
The last thing to consider is the
type of the variable there are different type of variables you may use integer,
string , double etc.
Example:
Dim name as string
Public
name as string
(Public
can be access by: if it is inside a form
you need to put the name of the form then period and the name of the variable
e.g Form1.name, But if you will use a module no need to put the name of the module)
II - Conditional
Statements
II.a - if
condtion
The
if condition have the following keyword:
If
condition then
Code
to execute
End
if
This
type of condition is you just want to check one condition if it goes false then
there is nothing to do Example:
If a =1 then
Msgbox
“one”
End
if
Another
example is with the else keyword
If
condition then
Code
to execute
Else
Code
to execute
End
if
This is more flexible than the
first condition, this one can be used for error handling for example if a
person is expected to input a number and the user would input a wrong input the
else statement would be executed
Example:
If
a = 1 then
Msgbox
“one”
Else
Msgbox
“its not number one”
End
if
Note
that you can put a multiple if inside a if it is what we call nested if and
make sure that the count of of your if is equal to the closing of the if the
“END IF”
Another
conditional statement is the select Case if you will create a codition that you
know already on what is the input you can use select case.
Example:
Select
Cases status
Case "single"
Msgbox
"Single"
Case "married"
Msgbox
"married"
Case "widow"
Msgbox
"widow"
Case Else
Msgbox "There is no such status like that"
End Select
III - Looping
1.
For condition Next
The for next loop has it’s the
following component the condition would be the reference on how long this loop
or codes should be executed, for example if you want to have code that will print or show a number from 1 to 10 then you will need to use a looping
statement example:
Dim
start as integer
For
start = 1 to 10
Msgbox
start
Next
Meaning
thiscode prints the value of start the value of start will change when you
execute this loop from 1 to 10.
Walang komento:
Mag-post ng isang Komento