visual basic - university of technology, iraq
TRANSCRIPT
Visual basic Integrated Development Environment
(IDE)بيئه التطوير المتكامل
جول بيسك يسمى التطبيقيأي برنامج يدل في الف هي المكان الذي يكتب فيه الجمل البرمجية :نافذة الشفرة
هي جمل برمجيه تؤدي وظائف محدودة: الشفرة
يه والقياسية لإنشاء التطبيقالخطوات الاساس
Form)(إنشاء لواجهه 1- )properties windows(وضع الخصائص - 2
)code windows(آتابة الشفرة3-
Design time- ) design time( عند التغير يكون في نافذة الخصائص Run time)( يكون التغير في وقت التنفيذ
Form ساحة العمل الرئيسية فيVB
Properties windows نافذة الخصائص
Menu bar شريط القائمة
Tool bar دواتشريط الا
Layout window
Text box مربع نص
Command زر الأوامر
Project explorer مستعرض المشروع
Eevent procedure)(الإجراء ألحدثي اسطر الشفرة يتم تنفيذها عندما يعالج المستخدم آائنا ما في البرنامج -
tool box)(صندوق الأدوات
Sub (command1-clicke) { End sub.
Property commmand1. caption =" "
check add item List
(Rules change the name of object): للأدوات ألتسميهقواعد
a) Name:
يبدأ بحرف -1 حرف 40 قد يكون الاسم متكون من -2 @ # $ دلا يحتوي على الإشارات الموجودة في الكي بور-3 لا يجوز أن نسمي الأداتين باسم واحد في التطبيق-4
b) Location and size الموقع والحجم خصائص
value)قيمة( )الخاصية(value )اسم الأداة(
طريقه اسم الأداة القيمة
twip=1/20 top
left height
width
c)Font: command1.font name="time new roman" command1.caption="press" command1.font bold=true command1.font size=20
عند التغير في وقت التنفيذ يجب آتابة جمله برمجيه
=VB Text1.textقد يأتي سؤال ماهية أدوات الإدخال والإخراج المستخدمة في"visual basic " Text1="program"}
Text1.back color=VB white
Text1.fore color=VB black لتغير جمله خصائص في ان واحد with text) ( العبارةتستخدم
With text1 .Text="program" Back color=VBwhite Fore color =vb black End with
Red green
blue
blackyellow
method طرق مشترآه
Label (يستخدم فقط للإخراج إذ توجد قيمة فقط) 1- Move:
:لأجل تحريك الأداة نكتب Label1.move 100 ,200, 4000 3000
Label1.left=100 label1.top=200 Label1.width=4000 Label1.height=3000
: set Focus 2)
Command1.setfocus
command1.zorder 03) command1.zorder 1
حدثي للبرنامج إجراء باستخدام بيسك للفيجوااآتب تطبيق
Write vb application that using haven't procedure for command and button to write form caption of example and has location of 100,200,9000,4000 for the left, top, width, height respectively use a text box with text of "visual basic" in bold ,size18,font name "time new roman "and move it in run time to200,300,8000,2000,for the left ,top, width& height ,green back color ,black fore color set the focus on command button at(design time ,run time) it is assumed that the command button caption in the design time is "ok" and form caption at the run time is "Ex" also" the word "application's used as infinitude word the appear at run time
لتغير المراد يعني واحد
منها أو المعطى
المعنية للأداةلنقل الترآيز
الأدواتفوق جميع
الأدواتتحت جميع
-Solution: form inter face:إنشاء الواجهة - 1
change properties:تغير الخصائص - 2
الإعداد الخاصية الأداة
object property setting Form caption example Text Text Visual basic Text Font bold True
Font size 18 Font name Time new roman
Command1 Set focus True Command1 Caption ok
code:آتابة الشفرة -3
Private sub command1_click( ) form1.move 200,300,8000,2000 With text1 .back color=VB green .fore color=VB black .font size=20 .font name="verdantly" .text="application" End with
command events (3الاحداث المشترآه command button command1,command2
form Text box command
الاسم الافتراضي
private sub command1_click() { End sub
a)mouse event
clickنقر DB click نقر مزدوج mouse moveحرآه الماوس
mouse down الأسفل إلىحرآه الماوس mouse up الأعلى إلى سوالماحرآه
Private sub command1_mouse down(Button as integer-Shift as integer-X as single-Y as single) { End sub
Button
Shift=1 (shift)
Shift=2 (cth1)
Shift=4 (Alt)
Use text box to describe the mouse events which aver
Mouse up ,mouse down ,mouse move ,on command button
Solution:
الواجهة إنشاء -1
Text box
command
2) code
Private sub command _mouse down(Button As integer, shift As integer ,x As
single, YAs single)
If button=1 then
Text1="left Button of mouse is down"
Else if Button=2 then
Text1.text="Right Button of mouse down"
Else if Button=4 then
Text1.text="middle Button of mouse down"
End if
End sub
Private sub command1_ mouse move(Button As integer , shift As integer , xAs
single ,y As single)
If shift=1 then
Text3="move"
Text3="shift mouse down"
End if
End sub
key board events)(لوحه المفاتيح إحداثWe will 3 type of events on key board
(key press ) زر في لوحة المفاتيح أيالنقر على
key down) ( زر في لوحة المفاتيح أيعلى الضغط
key up) ( )الضغطعادة يسبقه حث (تحرير الزر
Private sub command1_key down(key code as integer, shift as integer)
End sub
Private sub command1_key press(key ascii as integer)
ascii) ( س قابله للمفاتيح آما يعرف في مقيايساوي قيمه م أنيمكن
الاستخدام لاحظ في الجدول وحسب
Command1 Mouse down
Key ascii A 65
a 67
لوحة المفاتيح أحداثمثال يبين
Design An application in VB that use the key board events which are:
1) key press
2)key up
3) key down
With text box
To show the suitable word at each events use R whose its ascii code is 82 for 2
and 3 events
1)design form
3) code
Private sub text _key down(key code as integer ,shift as integer)
If key code=VBkeyf1 then
Text1.="f1 is down"
End if
End sub
Private sub text1_key press(key ascii as integer)
If key ascii=82
Text="R is pressed"
End if
End sub
مهم
:ألمشترآهتكمله الطرق Set focus (2 الأداةيحدث عندما يكون المطلوب من
3) Z order
4) Refresh
Got focus (5الترآيز أداةيحدث عند تشغيل
Change (6 الخاصية أونص آال الأداةيحدث بمجرد تغير محتويات
( initialize) الشفرةاستخدام النموذج في
Resize)( جتغير حجم النموذ
Activate)( مباشرة Resize) (يحث بعد الحث
Paint)إخفاءها بعد ذةالنافرسم إعادة
) Activate )Deactivate عكس المؤقت الإخفاءوليس ألذاآرهمن ألنهائيهعلى وشك الازاله النافذة
Unload )( تنهي العمل على النموذج
Terminate) ( التام لوجود النموذج في التطبيق الإنهاء
Load)( يحدث اليا يحدث بمجرد تحميل آائن النموذج في التطبيق
Private sub form _load()
Text1="visual basic"
End sub
Private sub form _Resize()
Form. Move 200 ,300, 5000 ,8000
Text .move 100 ,100 ,5000 ,7000
End sub
العمل على النموذج نكتب إنهاءعندما يكون المطلوب Unloadform1.
Hide)( النموذج وهو ظاهر هي لإخفاء
Show)( هو مخفيالنموذج و لإظهار
constant)(الإعلان عن الثوابت Option explicit
)(Query load
dim constant pi as single=3.14619 ,h=5.667E-8
العوامل ألرياضيه الاساسيه + ,- ,* ,/ ,^ Z=x+y Z=x-y Z=x*y Z=x/y
Z=(x,y)^2 z=(x/y)2
z=(x ,y,^2) z=x/y2
:العوامل ألمتقدمه الأخرى هي
/= )قسمة العدد الصحيح(
mod= )باقي القسمة(
&= )علامة دمج النصوص(
)الويه العوامل(
الأقواس - 1
أنشاء العدد والعدد السالب- 2
الضرب والقسمة - 3
قسمه العدد الصحيح - 4
باقي القسمة - 5
الجمع والطرح- 6
للتحكم بسير العمليات تستخدم الأقواس- 7
أذا لم يكتب فيه شئ فهو public وإذا يوجد شئ
contأسلوب فهو
Library function)(الدوال المكتبية
رياضيا برمجيا
sin(x) sinx
cos x cos(x)
tan(x) tan x
atan(x) 1- tanx Exp(x) ex
Sqrt(x) )- (sign(x) علامة متغيرx
val(x)إلى رقم قابل للإجراء الحسابات عليه x) (لتحويل المتغير Lux log(x)
دوال لتحويل البيانات CDBL إلى دقه مضاعفه
Cintإلى عدد صحيح C lngإلى عدد صحيح طويل
Csngإلى صفه اعتيادية Cstrإلى نص
Cvarإلى مستوى yوضعه في متغير اسمه xحول من دقه اعتيادية إلى دقه مضاعفه اسمه
EX: X=10+15*2/4^2 =10+15*2/16 =10+ 10+18 11.8 R=1+2^3/4 =1+8/4 =1+2 3 الأقواس تتحكم في سير العملياتN3= ((8-5)*3)^2-(3*3)^2-81 =81-81-81 = -81
EX: TRANSFORMATION OF MATHMATICAL EQUATION TO CODE:-
log(x)+((x+2*7)/3)^1/2
Ex:-
y= sqrt((2*x+3.4*log(x+1)/(2+y+3.1*x/y+2))
y= cos (x)*sin(x)/exp(x^2)+log(z)
EX :use text box to input the value angle in degrees used so 3
labels command button so that after click on it application will
writ sin , cos & tan in labels?
solution:-
option explicit
const pi as single=3.14156
private sub command1_ click()
dim x as single
x=(sng(text))
x=x*pi/180
label1.caption="sinx&sin(x)"
label2="cos&cos(x)"
label3=tan(x)
end sub
EX :use text box to input true of y also use input the value of x
in degree transform it to radian, z=3.2 use this values to obtain
the value of m in this equation:
write the value of m in label, use message box with button number
of 1 so that cancel will repeat procedure to input the value again.
solution:-
private sub command1_click()
y=val (text1.text)
x=input box ("Example ","value of x", Go)
X=X*3.1415/180
Z=3.73
M=((COS(X)+SIN(X)/EXP(X)+ATN(X)/Y+LOG(X)/Z/SQRT(Z^
2+Yp^(Z-X))
X2=msg box(ms ,"button ,title) If x2=VB yes if x2=7 then
x2=7 yes نطبق الشئ الذي نريده X2=6 No
input box) (في مربع الإدخال Ok 0
Ok, cancel 1 Abort, retry, ignore 2
No ,yes 4 Stop(8) 16 ? 32
! 48 Information sign 64
Response:
VB Ok 1 ok Cancel VB cancel 2
Abort VB abort 3 Retry VB retry 4
Ignore VB ignore 5 Yes VB yes 6
No no 7 انواع البيانات
شروط انواع البياناتيجب تحديد نوع البيان عند استخدام تطبيقات في الفيجول بيسك وذلك لحجز مسافه الازمه فقط
يقللتطبي# +-1017,7*10 8byte double
قد ياتي بالسؤال ما معنى رمز من الرموز اعلاه فنكتب ومعناه هكذا
% integer 2byte+-32767 such as
العلامه المدى الحجم نوع البيانinteger 2byte 32767 ± % long integer 4byte ±2,147, 488,643 & single 4byte ± 3,402823*10 !
0 65535 8byte string Variant 16آل شئ يستخدمbyte آل انواع البيانات
قد ياتي بالسؤال لماذا تحدد نوع البيانات في الفيجول بيسك يكون الجواب :الجواب هذا المثال
For I= 110,10000 X=x+I next
A=1 B=2 C=A+B A=1
لربط بين جمل عده وجعلها تكتب في سطر و احد اختصارا للحجم : collon تستخدم A=1:B=2 :C=A+B
فراغ لربط بين سطريين بجمله برمجيه واحده)-(تستخدم ʘ this program is used to calculate…
comment تستخدم للاعلان عن جمل التعليق
Rules of naming procedure, variable , and constant الاسم لا يبدا برقم
)حرف او رقم 256( إلىمن المرآز يمتد ! ، #،$ و تعريف لا يحتوي على رمز
( )لتجنب اختيار التعابير المشابهه لل (variable) ن عن المتغيراتالاعلا
Implicit ) الاعلان الداخلي( X=0 فمهناها X في حاله عدم اعطاء قيمه ل
X=x+1 وقد يحتوي على اآثر من loopفيرجع فيكون الناتج
Explicit الاعلان الخارجي option explicit اول شئ يكتب في الاعلان الخارجي
المبرمجون لتجنب الاخطاء في آتابة المتغيراتيستخدمها
To explicit declaration of variables جمله الاعلان الخارجي x.ʘحرف x.ʘرقم
2*10000=20000 byte 16*10000=160000 byte
dim )اسم المتغير(AS)نوع البيان( x yلللاعلان عن متغير اسمه
Dim xy
Option explicit public x yلايجوز آتابه
الاجراء يصح آتابتها داخل وخارج dimلكن public x yآيف تعلن عن متغير معرف خلال آل التطبيق input boxصندوق الادخال
M=input box (message, title , default) Ex :use command button so that when click on message it the message it application will use input box to write the input value such as number 2 on form Solution: Private sub command _click ( ) Message="inter value" Title="example input box" Default="2" X=input box (message ,title , default) قبل آل شئ والا تكون نتيجه البرنامج فارغهPrint x End sub Msg box "x1 ,button ,"title" 0 → ok
Ok cancel → 1 Abort retry ignore → 2
yes → 7 نظغط على No → 6 Private sub cheked2_click If check2.value =VB checked then Text1.font italic= true Else Text1.font italic=false End if End sub Private sub option1_ click( )
If option1=true then text1.font name="time new roman" End sub Private sub option2_click( ) If option2= true then Text1.font name="verdane" End if End sub if ( ) then
←العلامه الرياضيه اتجاهها < >, =>, >, <, = Y=B2+X X=2 a>3 Y=B+X X=3 a=3 Y=1/B+X X=4 a<3 Solution: If a >3 and x=2 then y=b^2+x If a=3 and x=3 then y=b +x If a<3 an x=4 then y=1/b+x
andيتطلب تحقيق الشرطين or , andلمرآب يحتوي على الشرط ا orيعتبر الشرط المرآب متحققا ويتطلب تحقيق الشرط واحد في
ويعتبر الشرط المرآب متحققاEx :use 3 text box to show that the number that exist greater than that which exist in text2 and greater than exist in text3 write the result in label?
Solution: Private sub command1_click A=val text1)
B= val (text2) C=val(text3) If a>b and a>c then Label .caption="A is biggest" Else Label="A is not the biggest" End if End sub
Example: say if the code is true or false
Dim 3 (2,3) 1) if x>2 then go to 20 2) end if 3)
x=cdng(text1) 4) opton exiplicit 4) option base 5) label 1=val(text) 6)
7)
Its code is x=y^2+cos(z)/2*log(y) Z=msg box(masg, little,button) 8) Y=input box(msg ,title ,default) 9)
Const xz as single=5.231 10) Ex: Label1=m R=msg box ("do it again" ,1 ,"example) If R=VB ok then End sub If R=VB cancel then End End sub
ok cancelاو VB ok رقم ولا نضع = Rاذا آانت R=5 then end
)Array(المصفوفات تبلكي نتخلص من الصفر في المصفوفه نك
Option basic This code will start all the matrix from Dim A(5) ,B(4,3)
اذا آتبت داخل الاجراء او تكون معرفه داخل الاجراء فقط اذا آتب اعلى الوحده التي تشمل عده اجراءات تكون خلال معرفه خلال اي آل الاجراءات لها اسلوب خاص للكتابه
1 to 5 dim A)( to 4 ,1 to 3 1)(اسلوب اخر للكتابه
if statementتستخدم للتحكم في سير العمايات داخل التطبيق وهي على عدة انواع
) ifشرط ( then جمله تنفيذيه if ( ) thenجمله تنفيذيه تنفذ عند تحقيق الشرط
Else 1عدم تحقيق الشرط جمله تنفيذيه تنفذ عندEnd if
)if 1شرط( then جمله تنفذ عند تحقيق الشرط Else if 2جمله تنفذ عند تحقيق شرط
Else 2وشرط 1 جمله تنفذ عند عدم تحقيق شرطEnd if
) ifشرط ( then جمله تنفذ عند تحقيق شرط End if
اسم افتراضي الاداة Check box
داخل المربع) صح(يوضع علامه checkعند استعمال الاداة VB checked=1 VB checked= VB checked= VB checked =1ʘ
EX: use text box &2 option button & 2 check box To write a string of "visual basic6"in text box Use the 2 option button to select the name of the font which is either "time new roman"&"verdana" use the 2 check box to select that the font is italic or not and the second check box to select that the font is bold or not. Initially let the font size 14 fore color is red , back color is black. Font name is "Tahoma".
Private sub form_ load( ) With text .text="visual basic" .font size=14 .fore color=VB Red .back color=VB Black .font name="Tahoma" End with End sub Private sub check1_ click( ) If check 1.value=VB checked then Text1.font bold=true End if End sub
EX :use 2 command button one to write time for running the program (20 sec)and the second for using the message box yes to start a timer for 20second after which write a message box to write time stop to run another events (command1) other wise the program is term method ?
Private sub command2_ click( ) D=20 Debug. Print p End sub Private sub command1 _ click ( ) M= msgbox("press" , 4 ,"try") If m= 6 then If m= VB yes then P=20 S=timer Do while timer < s +p Do events Loop]
7. Condition statement "الجمل الشرطيه" 7.1 if then 7.2 select case -:تستخدم عندما يكون تنفيذ مجموعه جمل يعتمد على قيمة متغير واحد وتاخذ الشكل التالي
Select case( test value)
, variable( لسله نصيه يمكن ان يكون المتغير س string (
Case ( value 1) { Case (value2) { End select EX:- design an application to enter the degree at a student from a text box and test this value so that using select case , show the result on message box Solution:
Private sub command1 _ click ( ) X=value (text) Select case x Case 90 to 100 Msg box "Exc." Case 80 to 89 Msg box: "v. Good" Case 70 to 79 Msg box "Good" Case 60 to 69 Msg box "med" Case 50 to59 Msgbox "pass" Case 40 to 49 Msg box "fail"
form Text box command
Case else Msgbox "Error" End select End sub 8. loop's 8.1 for next
Step ( no)] [ )القيمه النهائيه (to ) اسم العدد )= القيمه الابتدائيهfor جمل تنفيذيه تاخذ قيم التغير في العدلد Next [ اسم العدد] For i= 1 to 10 step 3 X= i+1 i=1 ,x=2 Print x Next Point on form 2 I=4 , x=5 I=7 , x=8 I=10 ,x=11 EX: a list of number from the biggest to the lowest the list is (1.1, 2 , 3.2 , 4 ,5 ,6 ,7 ,8 ,1 ,2 ,3 ,7 ) print the result on the form Private sub command 1 _ click ( ) Dim n as integer , I as integer , J as integer ,K as integer X=array(1.1 ,2 ,302 ,4 ,5 ,6 ,7 ,8 ,1 ,2 ,3 ,7) N=12 For I=1 to n-1 For J=I+1 to n If (J) >= x(I) then K=x(I) X(I)=x(J) X(J)=k End if Next J nextI for I=1to n print x(I) next
End sub 2) Do loop a) Do while ( شرط( جمل متغيره تنفذ عند تحقيق الشرط Loop B ) do until 1جمل تنفذ عند تحقيق الشرط
Loop c) do { Loop until ( شرط( d) do
{ Loop until ( شرط( Ex :c=1 Do while c< =4 [ 4طالما قيمه اضغر او تساوي ] Print c Loop C=1 Yes 1 , c+1 2 , 1+1 3 Yes 2+1 4 Yes 3+1 1) for next 2) do loop b) do until loop
التاليياخذ الشكل Do until ( شرط( جمله تنفيذيهLoop Ex: note Dim x(3) For i=1 to 7 X(i)=i^2
Next i Print i Ex: C=1 Do until c > 1000 Print c C=c+1 Loop do / loop while s=1 do print s s=s+3 loop while s <= 50 do / loop until s=1 do print s s=s+3 if x> 20 then do exit عبارة الخروج الشرطي* loop until s> 50 3) while
التالي تاخذ الشكل While ( شرط( جمل تنفيذيهWend Ex: C=0 While c < 20 C=c+1 Wend Print c
Note:
لايجوز تداخل الدورات .1 امكانيه الانهاء .23. Do exit للخروج الشرطي من دورهdo‐loop 4. Exit for للخروج الشرطي منfor next لايجوز القفز من داخل الدوره الى خارجها .5 next jقبل next iلايجوز آتابه .6
For i=1 to 5 For j=1 to 3 X(I,j)=i^2 Next j Next i
if x> 2 then exit forره الخروج الشرطي عبا
immediate window) نافذه الاوامر(1`)use to write result as we write the following
codeلكتابه النتائج على نافذه الاوامر debug.print) اسم المتغير(المراد آتابه قيمه على النافذه
to test same simple2(بسيطه لاجل الاختيار نختار جمله برمجيه نعني بها ثانيه واحده
msInterval=1000
timeياخذ من ساعه الحاسبه timerعدد الثواني منتصف الليل
)اي من بدايه يوم جديد(Ex:using timer event to set the timer interval to (1 sec) also use labels one to
show time and second form the mid of night Private sub form-load() Timer1.interval=1000 End sub Private sub timer1.timer() Label1.caption=time Label2.caption=timer End sub
F= timer Msg box("pause for"& of f-s&"second") Else End End if End sub اآتب برنامج يبين آم الوقت الباقي؟Private sub command2 _click() Print abs(p +s- timer) End sub اسئله امتحان
Q1) design an application to see if the student is pass or not assume the degree is form 100 if the degree > 50 then write pass in a massage box other write fail in a message box use select case a) for i=2 to 10 x=x+1 next i b)i=1 do while I<=4 i=i+1 c) complete or not for i=1 to 10 for j=2 to 30 a(I,J)=i^2 next i Next j
d) use timer event so that the program will run to 30 see with an event of command so that to write through the reaming time. Private sub command 1_click() P=30 Debug print p
ألحدثي الإجراء 1) subroutine 2) function 3) sub 1)subroutine Private sub command1 _click()
subroutine Go sub 95مج الفرعي لاستدعاء البرنا{
exit sub .…………………………ه لتجنب الدخول غير المسيطر علي return .………………………………………الذي استدعاه ألحدثي الإجراء إلى ألعودهعبارة
subroutine أل end sub ..………………………ألحدثي الإجراء نهاية
2) function Private sub command1 _click() B= ZI=(x ,z ,b)
.
.
. End sub
Function ZI(x ,y) ألحدثي الإجراءتحدث خارج ZI= x^2+log(x)+x^2/sqr (z) . . . . End function
Sub (3العام الإجراءPrivate sub command1 _click()
call(Xo , Y o , Z())آيفيه استدعاء هذا العام للإجراءالبرنامج
End sub x as int y ] sub d(x, y ,z)تبيانها لكتبنا أرادلو
x=y +zمتغير واحد End sub
العام الإجراءعن Ex: Private sub command1_click() Dim x(8) ,y(8) ,z(8) Call sub d( x() ,y() ,z()) End sub
sub d(x(), y(), z()) ألحدثي الإجراءعام خارج إجراءFor I=1 to 8 Z(I)=x(I)+y(I) Next
Exit sub ألحدثي الإجراءالخروج من ألحاجهعند End sub
function أللكن لا تستخدم في subroutineو sub تستخدم فقط في Write proper event to use two matrices so that use function to define the elements of the first matrix which is equal to the sum of number or no. of row and number of column plus 1, then use subroutine to divide the value of element by square root of column so that put the result in another matrix with the same dimension as(5*5) after that asub to write no. of row , no . of column , value of old and new matrix in immediate window.
Option explicit Option base 1 Dim c(5,5) ,a(5,5), I ,j Private sub command 1 _click() For I 1 to 5 For j 1 to 5 A(I,J)=MS(I,J) Next Next
Go to 10 Call s print (a(), c()) Exit sub 10 for I=1 to 5 For j 1 to 5 C(I,J)=a(I,J)/SQR(J) Next Next return End sub Sub s print (a(), c()) For I 1 to 5 For J 1 to 5 Debug .print I,J ,a(I,J), C(I,J) Next Next End sub If the heat generation inside tissue from the top heat laser beam is q=MIoe-mz Q=heat generation (w/m3) Io=2p/πw2 P=power=10w W o=waist radius= 5*10-4 Z=depth(m) Design an application so that a scroll bar will change the depth from 1µm to1000µm and use it in the above equation to find the heat generation in tissue write in label , use tier to limit the run time to60 sec ,write the remain time to end the program in asecond label Solution: Private sub H scroll _change() Call heat End sub Private sub H scroll _scroll() Call heat End sub Sub heat() z=Hscroll1.value Z=z/1 E6 OR Z=Z*1E-6 P=10 µu=98000 Q= µu*p/(3.14*(55-4)^2*exp(-µu*z) Label="heat generation"&Q End sub Sub timer1 _timer() S=60 X=timer Do while x +s > timer Do events
Label 2 ="Remaining time"& x+s -timer Loop End End sub Ex: Use matrix having 7 rows in the same number of days 1 week an 2 column ,use input box to enter the value of temperature 2 per day for 7 day , each day have 2 value one for max and the other for min use msg box to write the max temp of the day at which it a accurse and so for min temp find the average .write it in immediate window , find the nearest temp to the average and the day at which it occurs write on the form 0
1نجعل المصفوفة تبدأ من Option Base 1 Private sub command 1 _ click() Dim day ul (7,2) Day=array("sat" ,"sun" ,"mon" ,"tus" ,"wen", "thu" , "fri") For i=1 to 7 For j=1 to 2 Day u (I ,j)=input box("enter temp") Next Next Max s=day u(1,1) K=1 For i=1 to 7 For j=1 to 2 If day u (I ,j) >max s then Max s = day u (I,j) K= I End if Next i Next j Msg box("max temp is" & max s &"at of day (k) So m=0 For i=1 to 7 For j=1 to 2 Sum =sum +day ul (I ,j) Next: next Av=sum/4 Debug .print "ave temp"& av Md =abs=(day ul (1,1)-av) K=1:s=1 For i=1 to 7 For j=1 to 2 If abs (day ul(I ,j)-av < md then Md =abs (day ul (I,j) - av) K=i:s=j End if Next: next
Print day ul(k,s)-day(k) End sub Ex: if MN is a 2 dimensions matrix (20, 20), the value of each element is equal to the sum of number or no. of column divide by 10 , use function to determine the value , use sub to do the following Changing the diagnose of the matrix Find the sum of each row and the sum of each column Find the maximum and min .value of write the result in immediate the window , use proper event to sort the programs? Solution: Option base 1 Dim MN(20, 20) Private sub command 1 _click() For I 1 to 20 For j 1 to 20 Mn (I,j)=vx(I,j) Next : next Call inter change(MN()) Sub inter change (MN()) Dim a(20),b(20) For I 1 to 20 For j 1 to 20 If i=j then a(i)=MN(I,j) If I +j=21 then b( I )=MN(I ,j) Next: next For I 1 to 20 For j 1 to 20 If I =j the n MN (I,j)=b(i) If i+j=21 then MN (I,j)=a(i) Next :next End sub Function vx (I ,j) V x=(I,j)/10 End function Sub sum of r(MN()) For i=1 to 20 Sum=0 For j=1 to 20 Sum =sum +MN(I,j) Next Debug . Print I , sum Next For I 1 to 20 Sum=0 For j=1 to 20 Sum = sum +MN (j,i) Next Debug. Print I ,sum Next End sub
Call max min (MN()) End sub Sub max min(MN ()) Max s=MN(1,1) For i= 1to 20 For j 1 to 20 If MN(I,j)> max s then Max s ==MN(I ,j) End if Next :next Debug . Print "max"&max s Min=MN(1,1) For i=1 to 20 For j 1 to 20 If MN (I ,j)< min then Min=MN(I ,j) End if End sub اسئله امتحان؟ Q1 : use command button and three text to design an application showing the mouse events which are mouse down , mouse up, move write proper sentence in text box s Q2: having a value of x=2 a van dine of y input to application from textbox a value of z input to the application from the input box then use a proper events so that to start the application that read x , y ,z and input then to the following?
Q3: using a proper events design an application so that to use 2 matrix each of which have(20,20) dimension the element of the first matrix is no. of row plus no. of column PLUS 2 use sub to calculate to sum of the matrix an average use sabtrine to calculate element of matrix no.2 which is equal to the value of element divide by no. of row use sub to write the no .of row , no. of column value of matrix , value of matrix no.2 in immediate? Ex: if the heat generation inside a sub stance from top hat beam can written as g=µI0e-mz(w/m3) I0=p/πw0
2 (w/m2) , p=power in watt=10 W0= width of beam (m)=5*10 ^-4(radius) -µ=absorption coefficient(m^-1)=9800 tissue µ =8000 low carbon steel. For far Ir laser design an application use scroll bar to change the depth from(1-10^3)µm so that to enter the values in the above eq . to find heat generation and write it in label 1 so that one must know first if the required calculation is steel or tissue by choosing option button use timer to
write the time and second from the mid of night in label 2 also limit the running time to 60 sec. sol: private sub H-scroll 1 _change() call heat end sub private sub H-scroll 1_scroll() call heat end sub sub heat() pi =3.145 z=H scroll . value z=z*1e -6 p=10 if option 1 =true then µ u= 9800 Io=p/(pi*w^2) Q= µ u*Io*exp(-µ u*z) Label 1=" heat generation"&q Else if option 2 =true µ u =8000 Io=p/ (pI *w^2) Q= µ u*Io*exp(-µ u*z) Label 2="heat generation"&q End if End sub Private sub timer 1_ timer() S=60 P=timer Do while s +p> timer Do events Label3="remaining timer"& s+p – timer Loop End End sub Ex: use 2 scroll bar so that to input the value of thickness which is from (1-100) *10^-6 And second scroll bar to input the value of radius for gassian beam (r,z) write them in labels input these value to equation
Which model the heat generation inside tissue where for this wavelength µ=54000m^-1 Io=2p/πWo^2 P=10 W= waist radius =5*10^-4m Write the result on label , use timer to limit the remaining time to 40 sec , use third scroll bar to take the value of the remaining time to end the program and indicate it on the third scrollbar
Solution: Private sub H scroll 1_change() Call heat End sub Private sub Hscroll1_scroll() Call heat End sub Private sub Hscroll2_scroll() Call heat End sub Sub heat() Z=H scroll 1.value Pi =3.1456 z=z*10 e-6 label 1="r"&r w=5 e-4 p=10 µu=5400 Io=2*p/(pi*w^2) Q= µu*Io*exp(-µu*z)*exp(-2*r^2/w^2) Label 3="q" &q End sub Private sub timer _timer() S=10 B=timer Do while s +b > timer Do events X= int (b +s-timer) V scroll .value=x Loop :end: end sub