انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

Control Structures

Share |
الكلية كلية تكنولوجيا المعلومات     القسم قسم شبكات المعلومات     المرحلة 1
أستاذ المادة انوار جعفر موسى جعفر       22/01/2013 09:25:43
Control Structures
In this chapter, you will learn how to write VB6 code that can make decision when it process input from the users, and control the program flow in the process. Decision making process is an important part of programming because it will help solve practical problems intelligently so that it can provide useful output or feedback to the user. For example, we can write a VB6 program that can ask the computer to perform certain task until a certain condition is met, or a program that will reject non-numeric data. In order to control the program flow and to make decisions, we need to use the conditional operators and the logical operators together (see section 3.9) with the If control structure. To effectively control the VB6 program flow, we shall use the If control structure together with the conditional operators and logical operators. There are basically three types of If control structures, namely:
• If …..Then
• If – Then –Else
• Select Case

4.1 If....Then Statement: This is the simplest control structure which ask the computer to perform a certain action specified by the VB expression if the condition is true. However, when the condition is false, no action will be performed. The general format for the (If- Then) statement is
4.1-1 If Condition Then Statement Where, Condition is usually a comparison, but it can be any expression that evaluates to a numeric value, this value as true or false. If condition is True, Visual Basic executes all the statements following the Then keyword.
Example 4-1: Write a program to enter the value of two variables (X and Y). Find and print the maximum value for two variables. Design form window and select all the control objects are used.
Solution(1): or Solution(2):
Private Sub Command1_Click Private Sub Command1_Click Dim X , Y , Max Dim X , Y , Max
X =Val (Text1.Text ) X =Val (Text1.Text )
Y =Val (Text2.Text) Y =Val (Text2.Text)
Max=X If X> Y Then Max= X
If Y> X Then Max= Y If Y> X Then Max= Y
Text3.Text= Cstr (Max) Text3.Text= Cstr (Max)


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
download lecture file topic