1 / 64

Visual Basic

Visual Basic. משתנה - הנו מאגר מידע זמני למרות ש- VB לא מחייבת הגדרת משתנים (כברירת מחדל) רצוי לעשות זאת. ודא שאופציה Required Variable decleration בתפריט Tools, Options בכטיסיה Editor מסומנת כפעילה , זה יגרום ל- VB לדווח על שגיאות

nora
Télécharger la présentation

Visual Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic

  2. משתנה - הנו מאגר מידע זמני למרות ש- VBלא מחייבת הגדרת משתנים (כברירת מחדל) רצוי לעשות זאת. ודא שאופציה Required Variable decleration בתפריט Tools, Optionsבכטיסיה Editor מסומנת כפעילה, זה יגרום ל- VB לדווח על שגיאות ניתן להוסיף את הפקודה Option Explicit בראש הקוד בכל אחד מהטפסים והמודולים משתנים - variables

  3. S מחרוזת (String) nמספר שלם (Integer) lשלם שלם ארוך (Long integer) fנקודה צפה (floating point) dנקודה צפה cמטבע (Currency) b בולאני (Boolean) vמשתנה מסוג Variant סוגי משתנים - (Data Types)

  4. משתנה לוקלי באזור השיגרה או הטופס : Dim i As integer, name as string Private i As integer משתנה גלובלי באזור המודול : Public i As Currency משתנה סטטי באזור השיגרה (שומר את ערכו) : Static name As String (שימוש במילה static בראש השיגרה הופכת את משתניה לסטטיים. הגדרת משתנים

  5. Const meters=1000 public const progtitle=“my program” מילת המפתח public גורמת לקבועים להיות זמינים בכל התוכנית, בהנחה שההצהרה ב- module הגדרת קבועים

  6. Dim Counter(15) as integer Public Counter(15) as integer Dim counter(1 to 16) as integer Dim sums(100 to 120) as strings כדי לשנות את ברירת המחדל של הערך הנמוך ביותר של האינדקס מ- 0 ל- 1 ניתן להגדיר במודול: option base 1 הגדרת מערכים בעלי אורך קבוע

  7. Dim arr(9,9) as Double Static matrixa(1 to 10, 1 to 10) as integer Dim Multid(3, 1 to 10, 1 to 15) מערך רב-ממדי

  8. Dim Arr() as Double הקצאת מספר האיברים האקטואלי ע”י משפט redim בתוך פרוצדורה sub calc() . . Redim Arr(19,25) End Sub מערך דינמי

  9. Private type person Public type person private type person id as string name as string age as integer end type הגדרת סוגי משתנים חדשים

  10. Dim myrecord as person, yourrecord_ as person הגדרת משתנים של סוגי משתנים חדשים

  11. If statements • If...Then • If...Then...Else • Select Case

  12. If statements If condition Thenstatements End If If condition1 Then[statementblock-1][ElseIf condition2 Then[statementblock-2]] ...[Else[statementblock-n]] End If

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

  14. Do...Loop For...Next For Each...Next Loop Statement

  15. Repeats a block of statements while a condition is True or until a condition becomes True. Do [{While | Until} condition][statements][ExitDo][statements]Loop Do...Loop Statement

  16. Do[statements][ExitDo][statements]Loop [{While | Until} condition] Do...Loop Statement

  17. Loop zero or more times Loop at least once Do Until conditionstatementsLoop DostatementsLoop Until condition Do...Loop Statement Do While n < 100 n = n + n Loop

  18. While condition [statements] Wend Dim Counter Counter = 0 While Counter < 20 Counter = Counter + 1 Wend' End While loop when Counter > 19. While...Wend Statement

  19. MsgBox “Hello Users” Dim mystr as string mystr = “Hello” & “Users” MsgBox mystr MsgBox(Prompt,[,buttons][,title][,helpfile,context]) הצגת הודעה

  20. ניתן לשלב בתיבת ההודעה אחד מבין ארבעה סמלים אפשריים המציינים את מהות ההודעה: הודעה חשובה ביותר - מורה על התרחשות שגיאה חמורה(16) שאילתה - מורה על שהתוכנית זקוקה למידע נוסף מהמשתמש (32) אזהרה - מעיד על של שגיאת תוכנית העלולה להוביל לתוצאות בלתי רצויות(48) הודעת מצב - מיידעת את המשתמש לגבי מצב התוכנית (ציון סוף תהליכים שונים)(64) הצגת הודעה vbcritical vbquestion

  21. ניתן להתריע בפני בעיות שונות או להודיע למשתמש לבצע מהלך מסוים וזה מתבצע ע”י החזרת ערך. Result = MsgBox(“the printer is not_ responding”, vbretriycancel,”priter_ error”) הצגת הודעה - ערך מוחזר

  22. מערכת לחצניםערך קבוע OK 0 vbOkonly Cancel, OK 1 vbOkCancel Ignor,Retry,Abort 2 vbAbortRetryCcancel Cancel, No, Yes 3 vbYesNoCancel No, Yes 4 vbYesNo Cancel, Retry 5 vbCancelRetry הצגת הודעה - מערכת לחצנים

  23. לחצן ערך קבוע OK 1 vbOk Cancel 2 vbCancel Abort 3 vbAbort Retry 4 vbRretry Ignor 5 vbIgnor Yes 6 vbYes No 7 vbNo הצגת הודעה - ערך מוחזר

  24. הצגת הודעה - דוגמה Dim smsg as string dim nbuttons as integer Dim nresult as integer smsg=“are you sure you want to exit?” nbutton=vbyesno+vbquestion nresult=MsgBox(smsg,nbuttons,”my program”) if nresult=vbyes then end enif

  25. תיבת קלט – Input Box InputBox(prompt[, title][, default][, xpos] [, ypos][, helpfile, context]) Private Sub Form_Load() Dim input1 As String input1 = InputBox("Enter your name", "Name Win") MsgBox "Your name is:" & input1, vbInformation, "Name Win" End Sub

  26. תיבת קלט – Input Box

  27. Combo Box • שלושה סוגים של Combo Box: • Style 0 (default) - drop-down combo box • המשתמש יכול להוסיף אפשרויות לרשימה או ללחוץעל החץ לבחירה מרשימת האפשרויות • Style 1 - Simple combo box • הרשימה מופיעה, אין חץ פתיחה. מאפשר למשתמש להוסיף אפשרויות • Style 2 - Drop down list box • הרשימה אינה מופיעה עד שלוחצים על החץ. אין אפשרות להוסיף אפשרויות לרשימה

  28. Combo Box - גישה • box.list(index) • Text1.Text = List1.List(2) • התכונה ListIndex - מציינת את המיקום של האלמנט הנבחר • ListIndexיהיה (1-) , אם לא נבחרה אפשרות או שהמשתמש הוסיף אפשרות • התכונה ListCount מציינת את מספר האלמהנטים ברשימה

  29. Combo Box - גישה • AddItem • Removeitem • Clear • ListIndex • ListCount List1.additem “germany” List1.additem “japan”, 0 List1.removeitem 0 List1.clear

  30. By using the menu editor Creating Menus

  31. שלוש דרכים להוסיף תיבות דו-שיח ליישום שלך: הוספת בקרים לטפסים שימוש בתיבות קלט ופלט (InputBox, MsgBox) שימוש בפקד CommonDialog על מנת להשתמש בתיבות דו-שיח סטנדרטיות כמו: Print, File open תיבות דו-שיח

  32. Common Dialogמאפשר להציג את תיבות הדו-שיח הבאות: Open Save As Color Font Print תיבות דו-שיח נפוצותפקד CommonDialog

  33. כדי להשתמש בפקד Common Dialogיש להוסיפו לסרגל הפקדים כך: לבחור Project Components לסמן את Microsoft Common Dialog Control תיבות דו-שיח נפוצותפקד CommonDialog

  34. בזמן ריצה ניתן להשתמש בשיטות הבאות: Methods Dialog Displayed ShowOpen Open ShowSave Save As ShowColor Color ShowFont Font ShowPrinter Print ShowHelp Help תיבות דו-שיח נפוצותפקד CommonDialog

  35. Private Sub mnuOpenItem_Click() CommonDialog1.Filter ="Metafiles_ (*.WMF)|*.WMF" CommonDialog1.ShowOpen Image1.Picture =_ LoadPicture(CommonDialog1.filename) mnuCloseItem.Enabled = True End Sub Open Dialog Box

  36. Private Sub command1_Click() CommonDialog1.ShowColor End Sub Color Dialog Box

  37. Modal Dialog Box must be closed before you can continue working A Dialog Box is Modal if you click OK or CANCEL before you can switch To display a form as a modal dialog box use a style argument of 1 form1.show 1 Modal Dialog Box

  38. Modeless Dialog Box let you shift the focus between the dialog box and another form without having to close the dialog box. Form1.show Modeless Dialog Box

  39. פרוצדורות מחלקות את התוכנית למספר תוכניות קטנות פרוצדורות שנכתבו עבור פרוייקט אחד יכולות להיות בשימוש עבור פרוייקט אחר Procedures • Sub procedures do not return a value • Function procedures return a value • Property procedures can return and assign a values, and set references to objects

  40. [Private|public][static]Sub procedurename (args) statements End Sub Sub Procedures • Sub is Public by default • call MyProc(arg1,arg2) • MyProc arg1,arg2

  41. [Private|public][static]Function procname (args) [As Type] statements End Function Function Procedures • As type is variant type by default • Label1.Caption = func(y)

  42. Function func(ByVal x As Integer) As Integer x = 3 func = 4 End Function Private Sub Form_Load() Dim y As Integer y = 5 Label1.Caption = func(y) & "---" & y End Sub By Value

  43. Function func(Byref x As Integer) As Integer x = 3 func = 4 End Function Private Sub Form_Load() Dim y As Integer y = 5 Label1.Caption = func(y) & "---" & y End Sub By Reference

  44. נשתמש בסוג זה של פרוצדורות כאשר יוצרים תכונות חדשות לאובייקטים או רוצים לשייך קוד מסוים לתכונה Property Procedures • VBמספק שלושה סוגים של פרוצדורות property: • Property Let - sets the value of a property • Property Get - returns the value of a property • Property Set - Set a reference to an object

  45. במקרים מסוימים יהיה צורך לאחסן ולאחזר נתונים מבלי להידרש לעוצמה של מסד נתונים. במקרים כאלה, קבצי טקסט יהוו את הפתרון הרצוי. MDI- Multiple Document Interface

  46. במקרים מסוימים יהיה צורך לאחסן ולאחזר נתונים מבלי להידרש לעוצמה של מסד נתונים. במקרים כאלה, קבצי טקסט יהוו את הפתרון הרצוי. קבצי טקסט

  47. לקבצים סדרתיים אין מבנה מסודר כלשהו. פתיחת קובץ לקריאה (input), לכתיבה (Output) ולהוספה (Append) Open pathname for [input|Output|Append] As filenumber [len=buffersize] פתיחת קובץ לא קיים לקריאה תהווה שגיאה פתיחת קובץ לא קיים לכתיבה או הוספה, תיצור אותו. גישה סדרתית - פתיחת קובץ

  48. Line input # filenum, line קריאת שורה מהקובץ input #filenum,str,int,date קריאה לתוך משתנים מתאימים. פ’ זו מחפשת את תווי ההפרדה (פסיקים, גרשיים, ו-#) “text”,100,#1999-12-31# str=Input(chnum,#filenum) קריאת chnumתווים מקובץ filenum str=input(4,#filenum) קורא 4 תווים מהקובץ גישה סדרתית - קריאה מקובץ

  49. Print #filenum, “hello” hello write #filenum “hello” “hello” גישה סדרתית - כתיבה לקובץ

  50. גישה אקראית מתאימה לקבצים המכילים רשומות בעלי אורך ומבנה זהים Type worker lastname as string*10 title as string*7 rank as string*2 End Type public employee as worker גישה אקראית

More Related