Wednesday, 12 March 2014

What is Enumerated Data, User Defined Types, Expression, Operators and Comments?

Enumerated Data, User Defined Types, Expression, Operators and Comments.




Enumerated Data:


Enumerated Data is user define data, which is declared with word Enum, syntax for enumerated data is.

                                            Enum UserTypeName
                                                        Value 1
                                                        Value 2
                                                       ------------
                                                        Value n
                                            End Enum

The Value 1, Value 2, - , - , Value n are also called named constant. Each value of enumerated type data has a numbers are assigning to value implicitly or explicitly. This is shown in the following example.




Example:


             Start Visual Basic with a new Standard EXE project. Place two CommandButton Controls on a Form and write the following code in Click event of each CommandButton control and General Section of Form.


In General Section
     Enum listofitem1
               Item1                ‘ implicitly assign 1
               Item2                ‘ implicitly assign 2
               Item3                ‘ implicitly assign 3
        End Enum
Enum listofitem2
          Item11 = 30                ‘ Explicitly assign 30
          Item21                        ‘ implicitly assign 31
          Item23 = 12               ‘ Explicitly assign 12
End Enum


Private Sub Command1_Click ()
     Dim item As Integer
     Item = 2
     Select Case item
         Case 1, 2, 3
               Print, “Item from listitem1”
         Case 4, 5, 6
               Print, “item not from listitem1”
     End Select
End Sub


Private Sub Command2_Click ()
     Dim item As Integer
     Item = 31
     Select Case item
         Case 12, 30, 31
               Print, “Item from listitem2”
         Case 48, 49
               Print, “item not from listitem2”
     End Select
End Sub

Press F5 to run this project and press each CommandButton to check its output.

User Defines Types:


User's Defined data type is one which can be created by using type statement by a user. Syntax of Type statement is
  
                    [Private | Public] Type TypeName
                                 Variable are declared
                    End Type

When type statement is used in General Section of the Form then word Private  is used. Similarly Public word is used when type statement is used in a module section of the visual Basic. User defined data type is just like use of structures in C languages.

Example:


          Start Visual Basic with new Standard EXE Project. Place a CommandButton control on the Form and write following coding in the click event of the CommandButton and in General Section.

Private Type Student
   Rano As Integer
   Name As String
End Sub


Private Sub Command1_Click ()
     Dim x As Integer
     x. Rno  = 10
     x. Name = “ M Shahid “
     Print “ Rno =   “; x. Rno ‘And Name =    “; x. Name
  End Sub

Press F5 to run this project and press each CommandButton to check its output.

Expression:


An expression is the combination of operands ( variables/constants) and operators, which provides a result (+, _, >, 3, 5, 6 and etc). e.g.
  • 5 + 3 - 3
  • x > y and x > z

Operators:


Operators is a symbol or set of two symbols that performs an action between the nearest Operands in Visual Basic commonly following operators are used.
  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators

    1. Arithmetic Operators:

                          Arithmetic operators are used for calculation purposes. The list arithmetic operators and their description is shown in the following table.


Operator Symbol
Purpose/Description
Example
+
Addition
3 + 4 = 7
-
Subtraction
5 – 4 = 1
*
Multiplication
23 * 4 = 72
/
Division (Real)
2 / 3 = 1.666666666667
\
Division (Integer)
5 / 3 = 1
Mod
Remainder
5 Mod 3 = 2


    2. Relational Operators:


Relational Operators are used to form simple condition between different operands. The list of Relational operators and its description is shown in following table.


Operator Symbol
Purpose/Description
Example
>
Greater than
5 > 3
<
Less than
-5 < 90
>=
Greater than or Equal
X >= 5
<=
Less than or Equal
X <= y
=
Equal
w = s
<>
Not Equal
67 <> x


    3. Logical Operators:


Logical Operators are used to form a compound condition. Logical Operators are.
  • And     ' The expression with And operator returns True value if both conditions on both sides of               And operator are True otherwise returns False.
  • Or       ' The expression with or operator returns False value if both condition of Or operator are                 False otherwise return True value.
  • Not     '  Used for negation purpose.

Comments ( or Remarks ):


Comments or remarks are those lines of the code of an application, which are not interpreted by the interpreter or compiler (i.e Ignored by interpreter/ compiler ). In Visual Basic a line of code can be a comment or remark if ( ' ) apostrophe symbol or the reserved word Rem is placed at the start, in the middle, or at any other place of the line. The portion after this ( ' ) symbol and word Rem shall not be executed by the interpreter or compiler e.g.

                        ' Line for Comment Or
                        Rem Line for comment

Both statements have same function.


Me : If you need more help, want to ask feel free to use below comment box. It will be my pleasure to help you. THANKS for reading.



0 comments:

 
Search Engine Submission - AddMe url submit Casino us org Seo Packages http://blogsiteslist.com