انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة
الكلية كلية هندسة المواد
القسم قسم هندسة المعادن
المرحلة 2
أستاذ المادة رفاه ابراهيم جبار
10/03/2019 14:57:08
1. Introduction An array is a storage area which is used to store a set of data values that are of the same kind with one variable name.
2. Array types Array in visual basic can be as follow : • One – Dimensional Arrays • Control Arrays • Two – Dimensional Arrays
2.1 One –Dimensional Arrays An example of one- dimensional array is shown in figure below. This figure illustrates an array named A contains four elements and subscript named (I).
A(I)=A(4)=
1. Array Declaration
• A Dim statement is Used to declare an array. • A Dim statement must occur before the first reference to the array elements. • The following format can be used to declare the one dimensional array: Dim arrayName(m (start value) To n ( end value)) As varType where m and n are integers.
Example1: Write a VB program to input and print the elements for the array A(4). Solution : Private Sub Form_Click() Dim A(1 To 4) As Single For I = 1 To 4 A(I) = Val(InputBox("Enter element of A", I)) Print A(I( Next I End Sub
Example2:
Write a VB program to generate the elements randomly [0,10] for the array C(8).
Solution : Private Sub Form_Click() Dim C(1 To 8) As Integer For I = 1 To 8 C(I) = 10 * Rnd Print C(I( Next I End Sub
Example3: Write a VB program to enter the elements for the array A(6) then display the array B(6) which contain the reversed A elements.
Solution: Private Sub Form_Click() Dim A(1 To 6), B(1 To 6) As Single For I = 1 To 6 A(I) = Val(InputBox("Enter element of A", I(( Next I For I = 1 To 6 B(I) = A(7 – I( Next I For I = 1 To 6 Print A(I); Spc(8); B(I( Next I End Sub
Example4: Write a VB program to enter the elements of two arrays A and B. Each array contains (14) elements then display the array C(14) contain the mean between opposite numbers in two arrays. Solution: Private Sub Form_Click() Dim A(1 To 14), B(1 To 14), C(1 To 14) As Single For I = 1 To 14 A(I) = Val(InputBox("Enter element of A", I)) B(I) = Val(InputBox("Enter element of B", I)) Next I For I = 1 To 14 C(I) = A(I) + B(I) / 2 Next I For I = 1 To 14
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
الرجوع الى لوحة التحكم
|