SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


                                               CHAPTER 8
                                                ARRAYS

Control Arrays

A control array is a group of controls that share the same name and type.
They also share the same event procedures.
Common uses for control arrays include menu controls and option button groupings.

Why Use Control Arrays?

Adding controls with control arrays uses fewer resources than simply adding multiple controls of the
same type to a form at design time. Control arrays are also useful if you want several controls to
share code. For example, if three option buttons are created as a control array, the same code is
executed regardless of which button was clicked.

Example:

  Steps for creating Control Array of Option Button:
       1. Place an option button control on the form.
       2. Copy and paste the same option button control, a message box is displayed which ask
           for creating control array of option button.
       3. Click YES.




        Private Sub optColor_Click(Index As Integer)
                  If Index = 0 Then
                     txtMessage.ForeColor = vbRed
                  ElseIf Index = 1 Then
                     txtMessage.ForeColor = vbGreen
                  ElseIf Index = 2 Then
                     txtMessage.ForeColor = vbBlue
                  End If
        End Sub


Select Case
Visual Basic provides the Select Case structure as an alternative to If...Then...Else for selectively
executing one block of statements from among multiple blocks of statements.

A Select Case statement provides capability similar to the If...Then...Else statement, but it makes
code more readable when there are several choices.

                                                                                                        1
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


A Select Case structure works with a single test expression that is evaluated once, at the top of the
structure.
 Visual Basic then compares the result of this expression with the values for each Case in the
structure.
If there is a match, it executes the block of statements associated with that Case:

                 Select Case testexpression
                     [Case expressionlist1
                         [statementblock-1]]
                     [Case expressionlist2
                         [statementblock-2]]
                     .
                     .
                     .
                     [Case Else
                         [statementblock-n]]
                 End Select

Each expressionlist is a list of one or more values. If there is more than one value in a single list, the
values are separated by commas.
 Each statementblock contains zero or more statements. If more than one Case matches the test
expression, only the statement block associated with the first matching Case will execute. Visual
Basic executes statements in the Case Else clause (which is optional) if none of the values in the
expression lists matches the test expression.

For example above program using Select Case:




        Private Sub optColor_Click(Index As Integer)
                 Select Case Index
                          Case 0
                             txtMessage.ForeColor = vbRed
                          Case 1
                            txtMessage.ForeColor = vbGreen
                          Case 2
                            txtMessage.ForeColor = vbBlue
                  End Select
        End Sub




                                                                                                             2
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)




        Tips while using Select Case:
        Constant [, Constant . . . ]              Case 2, 4, 6
        Constant to Constant                      Case 25 to 50
        Is relational-operator Constant           Case Is < 10




Single Dimensional Arrays
Arrays allow you to refer to a series of variables by the same name and to use a number (an index)
to tell them apart.
 Arrays have both upper and lower bounds, and the elements of the array are contiguous within
those bounds, Because Visual Basic allocates space for each index number.

Arrays are also known as subscripted variables.

Syntax:
Dim ArrayName( [LowerSubscript To] UpperSubscript ) [As DataType]

Examples:
       Dim arr(4) ‘arr is of type variant and its index ranges from 0 to 4.
       Dim arrName(1 to 4) As String ‘arrName is of type String and its index ranges from 1 to 4.


Storing values in an Array using Index/Subscript
        Syntax: arrname(index)=value

        ‘ arrAlphabets is String array containing alphabets.
        Dim arrAlphabets(1 to 26) as String
         arrAlphabets(1)=”A”         ‘Storing String “A” at subscript/index 1
        arrAlphabets(2)=”B”          ‘Storing String “A” at subscript/index 2
        arrAlphabets(3)=”C”         ‘Storing String “A” at subscript/index 3
        .
        .
        .
        arrAlphabets(26)=”Z”          ‘Storing String “A” at subscript/index 26

Getting values from an Array using Index/Subscript

        Print arrAlphabets(26)    ‘Prints Z on the form
        Print arrAlphabets(1)     ‘Prints A on the form




                                                                                                     3
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


For Each Statement

Repeats a group of statements for each element in an array.

Syntax
        For Each element In group
              [statements]
        [Exit For]
              [statements]
        Next [element]
The For...Each...Next statement syntax has these parts:
Part                       Description

element                    Required. Variable used to iterate through the elements of the collection
                           or array. For collections, element can only be a Variant variable, a generic
                           object variable, or any specific object variable. For arrays, element can
                           only be a Variant variable.

group                      Required. Name of an object collection or array (except an array of user-
                           defined types).

statements                 Optional. One or more statements that are executed on each item in
                           group.



Example:
      Dim arrAlphabets(1 to 26) as String
       arrAlphabets(1)=”A”      ‘Storing String “A” at subscript/index 1
      arrAlphabets(2)=”B”       ‘Storing String “A” at subscript/index 2
      .
      .
      arrAlphabets(26)=”Z”       ‘Storing String “A” at subscript/index 26

          Dim str as Variant
          For each str in arrAlphabets
                  Print str
          next

output:        A
               B
               C
               D
               E
               .
               .
               .
               .
               .
               Z
Note: str should always be Variant.


                                                                                                          4
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


User Defined Data Types
User-defined types are useful when you want to create a single variable that records several
related pieces of information.
You create a user-defined type with the Type statement, which must be placed in the
Declarations section of a module.
* User-defined types should be declared as Private in a form module and Public in Standard
Module.
 For example:
        Private Type MyDataType
        -or-
        Public Type MyDataType

For example, you could create a user-defined type that records information about a Student:
       Private Type Student
               Name as String
               RollNo as Integer
               Age as Integer
       End Type


Declaring Variables of a User-Defined Type
You can declare local, private module-level, or public module-level variables of the same user-
defined type:
Dim s1 As Student                   ‘ Student variable s1
Dim s1(1 to 10) As Student         ‘ Student Array s1 of 10 students

Example:




       Private Type Student
               name As String
               rollno As Integer
       End Type

       Private Sub cmdOK_Click()
               Dim s1 As Student
               s1.name = txtname.Text
               s1.rollno = Val(txtrollno.Text)
               MsgBox "name of Student is : " & s1.name & " and Roll Number is : " & s1.rollno
       End Sub

                                                                                                  5
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


USING ARRAYS ELEMENTS FOR ACCUMULATORS




Dim arr(1 To 5) As Integer


Private Sub cmdSale_Click()
  Dim level As Integer
  Dim tickets As Integer

  level = Val(cboLevel.Text)
  tickets = Val(txtTickets.Text)

  If level >= 1 And level <= 5 Then
    arr(level) = arr(level) + tickets
  End If

 Cls
 Print Space(5) & "level" & Space(5) & "tickets"
 i=1
 For i = 1 To 5
    Print Space(5) & i & Space(5) & arr(i)
 Next


End Sub




                                                                              6
VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)


TABLE LOOKUP




Private Type Stadium
  level As String
  ticket As Integer
End Type

Dim udtStadium(1 To 5) As Stadium

Private Sub Form_Load()
  udtStadium(1).level = "A"
  udtStadium(2).level = "B"
  udtStadium(3).level = "C"
  udtStadium(4).level = "D"
  udtStadium(5).level = "E"
End Sub

Private Sub cmdSale_Click()
  Dim found As Boolean
  Dim nooftickets As Integer
  Dim userlevel As String
  found = False
  userlevel = cboLevel.Text
  nooftickets = Val(txtTickets.Text)
  i=1
  Do While found = False Or i <= 5
    If userlevel = udtStadium(i).level Then
       udtStadium(i).ticket = udtStadium(i).ticket + nooftickets
       found = True
    End If
    i=i+1
  Loop
  If found = False Then
    MsgBox "Invalid Stadium Level"
  End If
 Cls
 Print Space(5) & "level" & Space(5) & "tickets"
 i=1
 For i = 1 To 5
    Print Space(5) & udtStadium(i).level & Space(5) & udtStadium(i).ticket
 Next
End Sub



                                                                             7

Contenu connexe

Tendances

Vb6 ch.7-3 cci
Vb6 ch.7-3 cciVb6 ch.7-3 cci
Vb6 ch.7-3 cci
Fahim Khan
 

Tendances (17)

User define data type In Visual Basic
User define data type In Visual Basic User define data type In Visual Basic
User define data type In Visual Basic
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
Controls events
Controls eventsControls events
Controls events
 
GUI programming
GUI programmingGUI programming
GUI programming
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
INPUT BOX- VBA
INPUT BOX- VBAINPUT BOX- VBA
INPUT BOX- VBA
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
Visual C# 2010
Visual C# 2010Visual C# 2010
Visual C# 2010
 
Vb6 ch.7-3 cci
Vb6 ch.7-3 cciVb6 ch.7-3 cci
Vb6 ch.7-3 cci
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
Program by Demonstration using Version Space Algebra
Program by Demonstration using Version Space AlgebraProgram by Demonstration using Version Space Algebra
Program by Demonstration using Version Space Algebra
 
Part 12 built in function vb.net
Part 12 built in function vb.netPart 12 built in function vb.net
Part 12 built in function vb.net
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slidesC# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
 

Similaire à Vb6 ch.8-3 cci

Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
robertbenard
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
robertbenard
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath
 

Similaire à Vb6 ch.8-3 cci (20)

Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
Advanced VB: Review of the basics
Advanced VB: Review of the basicsAdvanced VB: Review of the basics
Advanced VB: Review of the basics
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Programming in Scala - Lecture Three
Programming in Scala - Lecture ThreeProgramming in Scala - Lecture Three
Programming in Scala - Lecture Three
 
Java Script Introduction
Java Script IntroductionJava Script Introduction
Java Script Introduction
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.ppt
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arrays
 
Introduction to System verilog
Introduction to System verilog Introduction to System verilog
Introduction to System verilog
 
Day2
Day2Day2
Day2
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
MA3696 Lecture 5
MA3696 Lecture 5MA3696 Lecture 5
MA3696 Lecture 5
 
Overview of verilog
Overview of verilogOverview of verilog
Overview of verilog
 
Ast transformation
Ast transformationAst transformation
Ast transformation
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Vb6 ch.8-3 cci

  • 1. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) CHAPTER 8 ARRAYS Control Arrays A control array is a group of controls that share the same name and type. They also share the same event procedures. Common uses for control arrays include menu controls and option button groupings. Why Use Control Arrays? Adding controls with control arrays uses fewer resources than simply adding multiple controls of the same type to a form at design time. Control arrays are also useful if you want several controls to share code. For example, if three option buttons are created as a control array, the same code is executed regardless of which button was clicked. Example: Steps for creating Control Array of Option Button: 1. Place an option button control on the form. 2. Copy and paste the same option button control, a message box is displayed which ask for creating control array of option button. 3. Click YES. Private Sub optColor_Click(Index As Integer) If Index = 0 Then txtMessage.ForeColor = vbRed ElseIf Index = 1 Then txtMessage.ForeColor = vbGreen ElseIf Index = 2 Then txtMessage.ForeColor = vbBlue End If End Sub Select Case Visual Basic provides the Select Case structure as an alternative to If...Then...Else for selectively executing one block of statements from among multiple blocks of statements. A Select Case statement provides capability similar to the If...Then...Else statement, but it makes code more readable when there are several choices. 1
  • 2. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) A Select Case structure works with a single test expression that is evaluated once, at the top of the structure. Visual Basic then compares the result of this expression with the values for each Case in the structure. If there is a match, it executes the block of statements associated with that Case: Select Case testexpression [Case expressionlist1 [statementblock-1]] [Case expressionlist2 [statementblock-2]] . . . [Case Else [statementblock-n]] End Select Each expressionlist is a list of one or more values. If there is more than one value in a single list, the values are separated by commas. Each statementblock contains zero or more statements. If more than one Case matches the test expression, only the statement block associated with the first matching Case will execute. Visual Basic executes statements in the Case Else clause (which is optional) if none of the values in the expression lists matches the test expression. For example above program using Select Case: Private Sub optColor_Click(Index As Integer) Select Case Index Case 0 txtMessage.ForeColor = vbRed Case 1 txtMessage.ForeColor = vbGreen Case 2 txtMessage.ForeColor = vbBlue End Select End Sub 2
  • 3. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Tips while using Select Case: Constant [, Constant . . . ] Case 2, 4, 6 Constant to Constant Case 25 to 50 Is relational-operator Constant Case Is < 10 Single Dimensional Arrays Arrays allow you to refer to a series of variables by the same name and to use a number (an index) to tell them apart. Arrays have both upper and lower bounds, and the elements of the array are contiguous within those bounds, Because Visual Basic allocates space for each index number. Arrays are also known as subscripted variables. Syntax: Dim ArrayName( [LowerSubscript To] UpperSubscript ) [As DataType] Examples: Dim arr(4) ‘arr is of type variant and its index ranges from 0 to 4. Dim arrName(1 to 4) As String ‘arrName is of type String and its index ranges from 1 to 4. Storing values in an Array using Index/Subscript Syntax: arrname(index)=value ‘ arrAlphabets is String array containing alphabets. Dim arrAlphabets(1 to 26) as String arrAlphabets(1)=”A” ‘Storing String “A” at subscript/index 1 arrAlphabets(2)=”B” ‘Storing String “A” at subscript/index 2 arrAlphabets(3)=”C” ‘Storing String “A” at subscript/index 3 . . . arrAlphabets(26)=”Z” ‘Storing String “A” at subscript/index 26 Getting values from an Array using Index/Subscript Print arrAlphabets(26) ‘Prints Z on the form Print arrAlphabets(1) ‘Prints A on the form 3
  • 4. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) For Each Statement Repeats a group of statements for each element in an array. Syntax For Each element In group [statements] [Exit For] [statements] Next [element] The For...Each...Next statement syntax has these parts: Part Description element Required. Variable used to iterate through the elements of the collection or array. For collections, element can only be a Variant variable, a generic object variable, or any specific object variable. For arrays, element can only be a Variant variable. group Required. Name of an object collection or array (except an array of user- defined types). statements Optional. One or more statements that are executed on each item in group. Example: Dim arrAlphabets(1 to 26) as String arrAlphabets(1)=”A” ‘Storing String “A” at subscript/index 1 arrAlphabets(2)=”B” ‘Storing String “A” at subscript/index 2 . . arrAlphabets(26)=”Z” ‘Storing String “A” at subscript/index 26 Dim str as Variant For each str in arrAlphabets Print str next output: A B C D E . . . . . Z Note: str should always be Variant. 4
  • 5. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) User Defined Data Types User-defined types are useful when you want to create a single variable that records several related pieces of information. You create a user-defined type with the Type statement, which must be placed in the Declarations section of a module. * User-defined types should be declared as Private in a form module and Public in Standard Module. For example: Private Type MyDataType -or- Public Type MyDataType For example, you could create a user-defined type that records information about a Student: Private Type Student Name as String RollNo as Integer Age as Integer End Type Declaring Variables of a User-Defined Type You can declare local, private module-level, or public module-level variables of the same user- defined type: Dim s1 As Student ‘ Student variable s1 Dim s1(1 to 10) As Student ‘ Student Array s1 of 10 students Example: Private Type Student name As String rollno As Integer End Type Private Sub cmdOK_Click() Dim s1 As Student s1.name = txtname.Text s1.rollno = Val(txtrollno.Text) MsgBox "name of Student is : " & s1.name & " and Roll Number is : " & s1.rollno End Sub 5
  • 6. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) USING ARRAYS ELEMENTS FOR ACCUMULATORS Dim arr(1 To 5) As Integer Private Sub cmdSale_Click() Dim level As Integer Dim tickets As Integer level = Val(cboLevel.Text) tickets = Val(txtTickets.Text) If level >= 1 And level <= 5 Then arr(level) = arr(level) + tickets End If Cls Print Space(5) & "level" & Space(5) & "tickets" i=1 For i = 1 To 5 Print Space(5) & i & Space(5) & arr(i) Next End Sub 6
  • 7. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) TABLE LOOKUP Private Type Stadium level As String ticket As Integer End Type Dim udtStadium(1 To 5) As Stadium Private Sub Form_Load() udtStadium(1).level = "A" udtStadium(2).level = "B" udtStadium(3).level = "C" udtStadium(4).level = "D" udtStadium(5).level = "E" End Sub Private Sub cmdSale_Click() Dim found As Boolean Dim nooftickets As Integer Dim userlevel As String found = False userlevel = cboLevel.Text nooftickets = Val(txtTickets.Text) i=1 Do While found = False Or i <= 5 If userlevel = udtStadium(i).level Then udtStadium(i).ticket = udtStadium(i).ticket + nooftickets found = True End If i=i+1 Loop If found = False Then MsgBox "Invalid Stadium Level" End If Cls Print Space(5) & "level" & Space(5) & "tickets" i=1 For i = 1 To 5 Print Space(5) & udtStadium(i).level & Space(5) & udtStadium(i).ticket Next End Sub 7