اهلا وسهلا بك فى بوابة الثانوية العامة ... سجل الان

العودة   بوابة الثانوية العامة المصرية > المرحلة الاعدادية > الفصل الدراسى الثانى > الصف الثالث الاعدادى > الكمبيوتر وتكنولوجيا المعلومات 3 ع ترم 2 2017 > حاسب آلى 3ع ترم2

إضافة رد
 
أدوات الموضوع انواع عرض الموضوع
  #1  
قديم 28-05-2013, 08:40 PM
الصورة الرمزية hassanalhawy
hassanalhawy hassanalhawy غير متواجد حالياً
مــٌــعلــم
 
تاريخ التسجيل: Sep 2010
المشاركات: 1,515
معدل تقييم المستوى: 15
hassanalhawy is on a distinguished road
افتراضي مرة أخرى الدالة والقيمة الراجعة (Return Value)


مرة أخرى الدالة والقيمة الراجعة (Return Value)
هذه ترجمة لأحد مشاركات الأستاذ / سيف
عسى أن تنفعنا فى فهم الإعلان عن الدالة وإستدعائها :

================================================== ========

Function procedure performs a task and then returns control to the calling code. When it returns control, it also returns a value to the calling code.
إجراء الدالة تنفذ مهمة ثم يعود التحكم إلى كود الاستدعاء.عندما يعود التحكم، فإنها أيضا ترجع قيمة إلى كود الاستدعاء.
Each time the procedure is called, its statements run, starting with the first executable statement after the Function statement and ending with the first End Function, Exit Function, or Return statement encountered.
في كل مرة يتم استدعاء الإجراء، جملها تنفذ ،بدءا من جملة التنفيذ الأولى بعد جملة الدالة وتنتهي مع أول End Function ، و Exit Function ،أو جملة Return.
You can define a Function procedure in a module, class, or structure. It is Public by default, which means you can call it from anywhere in your application that has access to the module, class, or structure in which you defined it.
يمكنك تعريف إجراءالدالة في وحدة نمطية module ، وتصنيف class ،أوبنية.Structure هى بصفة عامة افتراضياً،مما يعني أنه يمكنك إستدعاؤها من أي مكان في التطبيق الخاص بك للوصول إلى الوحدة النمطية module ، والتصنيف class ،أوالبنية.Structure الذي قمت بتعريفه عليه.
A Function procedure can take arguments, such as constants, variables, or expressions, which are passed to it by the calling code.
إجراءالدالة يمكن أن تأخذ قيم للمعاملات arguments ،مثل الثوابت constants والمتغيرات variables ،أوالتعبيرات expressions ،التي يتم تمريرها إليه بواسطة كود الاستدعاء.
Declaration Syntax

بناء جملة الإعلان
The syntax for declaring a Function procedure is as follows:
بناء جملة الإعلان عن إجراءالدالة يتم على النحو التالي:
[modifiers] Function function name[(parameter list)] Asreturn type
' Statements of the Function procedure.
'جمل إجراء الدالة.
End Function
The modifiers can specify access level and information regarding overloading, overriding, sharing, and shadowing. For more information, see Function Statement (Visual Basic).
الصفات التعريفية تمكن من تحديد مستوى الوصول والمعلومات المتعلقة بثقل التحميل، والهيمنة، والمشاركة،وظلها. لمزيد من المعلومات ، انظر Function Statement (Visual Basic).
You declare each parameter the same way you do for Sub Procedures.
تقوم بتعريف كل معامل parameter بنفس الطريقة التي تفعلها للإجراءات الفرعية.
Data Type نوع البيانات
Every Function procedure has a data type, just as every variable does. This data type is specified by the As clause in the Function statement, and it determines the data type of the value the function returns to the calling code. The following sample declarations illustrate this.
كل إجراء دالة له نوع بيانات، تماما كما لكل متغير. يتم تحديد نوع البيانات هذا من قبل كلمة As في إجراء الدالة ، وهو (نوع البيانات ) يحدد نوع البيانات للقيمة الراجعة للدالة إلى أمرالاستدعاء.المثال التالى يوضح هذا الإستدعاء .
Copy Code
Function yesterday() As Date
End Function
Function findSqrt(ByVal radicand As Single) As Single
End Function
For more information, see "Parts" in Function Statement (Visual Basic).
لمزيد من المعلومات أنظر الأجزاء فىFunction Statement (Visual Basic)
Returning Values
إرجاع القيم
The value a Function procedure sends back to the calling code is called its return value. The procedure returns this value in one of two ways:
قيمة إجراء الدالة يرسل مرة أخرى إلى كود الإستدعاء ويطلق عليه قيمتها الراجعة. الإجراء يقوم بإرجاع هذه القيمة في واحدة من طريقتين:
1) It assigns a value to its own function name in one or more statements of the procedure. Control does not return to the calling program until an Exit Function or End Function statement is executed. The following example illustrates this.
يتم تعيين قيمة إلى دالة خاصة بها اسمها في واحد أوأكثرمن عبارات الإجراء.التحكم لا تعيد إلى برنامج الاستدعاء حتى يتم تنفيذ Exit Function أو عبارةEnd Function . المثال التالي يوضح هذا.
Function function name[(parameterlist)] As returntype
' The following statement does not transfer control back to the calling code.
'الجملة التالية لا تنقل التحكم مرة أخرى إلى كود الاستدعاء.
function name = expression
' When control returns to the calling code, expression is the return value.
'عندما يعود التحكم إلى كود الاستدعاء ، التعبير هي القيمة الراجعة.
End Function
2) It uses the Return statement to specify the return value, and returns control immediately to the calling program. The following example illustrates this.
وتستخدم عبارة الرجوع إلى تحديد القيمة الراجعة ، ويعود التحكم مباشرة إلى برنامج الاستدعاء .المثال التالي يوضح هذا.
Function function name[(parameter list)] As return type
' The following statement immediately transfers control back to the calling code and returns the value of expression.

'الجملة التالية ينقل على الفور التحكم مرة أخرى إلى كود الإستدعاء وإرجاع قيمة التعبير.
Return expression
End Function

The advantage of assigning the return value to the function name is that control does not return from the procedure until it encounters an Exit Function or End Function statement. This allows you to assign a preliminary value and adjust it later if necessary.
ميزة تعيين قيمة راجعة إلى اسم الدالة هو أن التحكم لايعود من الإجراء حتى يصادف Exit Function أو عبارة End Function. هذايسمح لك لتعيين قيمة أولية وضبطها في وقت لاحق إذا لزم الأمر.
For more information, see "Return Value" in Function Statement (Visual Basic).
لمزيد من المعلومات أنظر"Return Value" in Function Statement (Visual Basic).
Returning Arrays إعادة المصفوفة
If the Function procedure returns an array data type, you cannot access the individual elements of the array within the function. If you attempt to do this, the compiler interprets it as a recursive call to the procedure. The following example illustrates this.
إذا كان إجراءالدالة يرجع نوع بيانات المصفوفة،لا يمكنك الوصول إلى العناصرالفردية للمصفوفة ضمن الدالة..إذا حاولت القيام بذلك،المترجم يفسر ذلك كاستدعاء الإعادة ( التكرار ) إلى هذا الإجراء.المثال التالي يوضح هذا.
Function allOnes(ByVal n As Integer) As Integer()
For i As Integer = 1 To n - 1
' The following statement generates a COMPILER ERROR.

' العبارة التالية ينشأ عنها خطأ للمترجم
allOnes(i) = 1
Next i
' The following statement generates a COMPILER ERROR.

' العبارة التالية ينشأ عنها خطأ للمترجم
Return allOnes()
End Function
In the preceding example, the compiler interprets the attempted assignment allOnes(i) = 1 as a call to allOnes on the left side of an assignment statement. It interprets the attempted Return allOnes() as a call with no argument. Both statements generate compiler errors.
فيالمثال السابق،يفسرالمترجم محاولة تعيين allOnes(i) = 1 كاستدعاء لـ allOnesعلى الجانب الأيسرمن عبارة التعيين . وهو يفسرالمحاولة Return allOnes() كاستدعاء من غير قيمة معامل .argument وكلا العبارتين توليد أخطاء المترجم.
Calling Syntax إستدعاء بناء الجملة
You invoke a Function procedure by including its name and arguments either on the right side of an assignment statement or in an expression. You must provide values for all arguments that are not optional, and you must enclose the argument list in parentheses. If no arguments are supplied, you can optionally omit the parentheses.
استدعاء كإجراء الدالة متضمناً ذلك اسمها وقيمة كل المعاملات argumentsعلى الجانب الأيمن من عبارة التعيين أو في التعبير . يجب توفيرالقيم لجميع المعاملات التي ليست اختيارية ، ويجب عليك إحاطة قائمة الوسيطة بين قوسين. إذا لم يتم توفرالمعاملات ،يمكنك حذف الأقواس اختياريا.
The syntax for a call to a Function procedure is as follows:
بناء الجملة من أجل الإستدعاء إلى إجراء الدالة على النحو التالي:
lvalue = function name[(argument list)]
If ((function name[(argument list)] / 3) <= expression) Then
When you call a Function procedure, you do not have to use its return value. If you do not, all the actions of the function are performed, but the return value is ignored. MsgBox is often called in this manner.
عند استدعاء إجراء الدالة ، لم يكن متاح لك استخدام قيمتها الراجعة. إذا لم تقم بذلك ، يتم تنفيذ كافة إجراءات الدالة، ولكن يتم تجاهل القيمة الراجعة. وغالبا ما يستدعى الـMsgBox بهذه الطريقة.
Illustration of Declaration and Call
توضيح لـ الإعلان والإستدعاء

The following Function procedure calculates the longest side, or hypotenuse, of a right triangle, given the values for the other two sides.
إجراء الدالة التالية يحسب الضلع الأطول ، أو الوتر ، لمثلث قائم الزاوية، وبالنظر إلى القيم الأخرى للجانبين.
Visual Basic Copy Code
Function hypotenuse(ByVal side1 As Single, ByVal side2 As Single) As Single
Return Math.Sqrt((side1 ^ 2) + (side2 ^ 2))
End Function
The following example shows a typical call to hypotenuse
553b-4cb6-9. يظهر المثال التالي إستدعاء نموذجى لـ hypotenuse.
Visual Basic Copy Code
Dim test Length, test Hypotenuse As Single
tes tHypotenuse = hypotenuse(test Length, 10.7)
Visual Basic Runtime Functions
The Visual Basic runtime provides many functions, located in the Microsoft
يوفر وقت تشغيل Visual Basic العديد من الدوال ، وتقع في مايكروسوفت
ms-help://MS.VSCC.v90/MS.msdnexpress.v90.en/dv_vbalr/html/1b9f632c-20a-ded117ead8c0.htm

__________________
يخطئ من يظن أن للذئاب ديناً
رد مع اقتباس
  #2  
قديم 28-05-2013, 09:20 PM
سيف سالم سيف سالم غير متواجد حالياً
مــٌــعلــم
 
تاريخ التسجيل: Jul 2008
المشاركات: 4,644
معدل تقييم المستوى: 20
سيف سالم is on a distinguished road
افتراضي

طبعا نقل الموضوعات الى طلبات الاعضاء قضى عليها تماما
وطبعا نحن هنا فقط اقصد مصر اختلافنا في نوع القيمة الراجعة هل هو ما بعد as في سطر التعريف
اما ما بعد as في تعريف المتغيرات داحل كود الدالة
والى الان لم يتم الاتفاق
واعتقد لن يتم
رد مع اقتباس
  #3  
قديم 29-05-2013, 09:36 AM
الصورة الرمزية hassanalhawy
hassanalhawy hassanalhawy غير متواجد حالياً
مــٌــعلــم
 
تاريخ التسجيل: Sep 2010
المشاركات: 1,515
معدل تقييم المستوى: 15
hassanalhawy is on a distinguished road
افتراضي

فعلاً أستاذ / سيف لن نستطيع التوصل لحل تلك المشكلة
طالما لم يكن بين أيدينا المرجع الذى ينهى هذا الخلاف
__________________
يخطئ من يظن أن للذئاب ديناً
رد مع اقتباس
  #4  
قديم 29-05-2013, 09:43 AM
الصورة الرمزية hassanalhawy
hassanalhawy hassanalhawy غير متواجد حالياً
مــٌــعلــم
 
تاريخ التسجيل: Sep 2010
المشاركات: 1,515
معدل تقييم المستوى: 15
hassanalhawy is on a distinguished road
افتراضي

ولكن هل يمكن أن نعرف السبب فى حدوث الخطأ فى هذا الكود . الذى أشار إليه الأستاذ تامر بسببه من قبل ولكن لم أستوعب أسباب هذا الخطأ
كود:
Dim A As Byte = 200
Dim B As Byte = 100
Dim C As Short
C = A+ B
MsgBox (C)
__________________
يخطئ من يظن أن للذئاب ديناً
رد مع اقتباس
  #5  
قديم 29-05-2013, 12:23 PM
الصورة الرمزية hassanalhawy
hassanalhawy hassanalhawy غير متواجد حالياً
مــٌــعلــم
 
تاريخ التسجيل: Sep 2010
المشاركات: 1,515
معدل تقييم المستوى: 15
hassanalhawy is on a distinguished road
افتراضي

طريقة أخر لكتابة كود الدالة
كود:
Function sum(byval first as Byte, byval second as Byte) as Short sum = first + second End function
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click msgbox(sum(255, 1)) End sub
__________________
يخطئ من يظن أن للذئاب ديناً
رد مع اقتباس
إضافة رد

العلامات المرجعية


ضوابط المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا يمكنك اضافة مرفقات
لا يمكنك تعديل مشاركاتك

BB code متاحة
كود [IMG] متاحة
كود HTML معطلة

الانتقال السريع


جميع الأوقات بتوقيت GMT +2. الساعة الآن 07:48 AM.