Automating Tasks with Visual Basic
Số trang: 32
Loại file: pptx
Dung lượng: 166.58 KB
Lượt xem: 14
Lượt tải: 0
Xem trước 4 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.Example:Modify a whole batch of records at once.Perform complex calculations.Interact with other programs on computer. Write even more complicated validation routines that lock out bad data.
Nội dung trích xuất từ tài liệu:
Automating Tasks with Visual BasicAutomatingTaskswithVisualBasicIntroductionqWhencan’t findareadymademacroactionthat doesthejobyouwant,youcanuseVisualBasic code.qExample: − Modifyawholebatchofrecordsatonce. − Performcomplexcalculations. − Interactwithotherprogramsoncomputer. − Write even more complicated validation routinesthatlockoutbaddata.UnderstandingVBATerminologyqSomebasicVBAterminology: − Statement: A word or combination of words thatconstitutesaninstructiontobeperformed bytheVBAengine. − Procedure: A collection of VBA statements thataregroupedtogethertoperformacertain task.Therearetwotypesofprocedures: Subroutines: perform a single task, no § return. Functions: performataskandthenreturna §UnderstandingVBATerminology− Module:Proceduresliveinmodules.Amodule consistsofoneormoreprocedures− Variable:isnothingmorethananameapplied to represent a data value. Variable is used to hold values such as customer names, dates, and numeric values manipulated by the VBA code.TheVisualBasicEditorqVisual Basic code is stored in database, but it need a different tool to view and edit it, called theVisualBasiceditor.qOpentheVisualBasiceditor: In the Access ribbon, choose Database § Tools➝Macro➝VisualBasicTheVisualBasicEditorqThe Visual Basic editor window is divided into threemainregions. − Projectwindow:showsallthemodulesinyour database. − Properties window: which shows settings for the currently selected item in the Project window. − Documentwindow:Editcoderegion.AddingaNewModuleqIntheVisualBasiceditor’smenu,chooseInsert ➝Module.AddingaNewModuleqWhenaddanewmodule,theVisualBasiceditor automatically opens a code window that shows thecontentsofthatmodule.qInitially,abrandnewmodulehasjustonelineof code: OptionCompareDatabase − ThislineisaninstructionthattellsVisualBasic howtohandleoperationsthatcomparepieces oftext.AddingaNewModuleqBefore write code you should add one more instructiontothetopofcodefile: OptionExplicitqThis instruction tells Visual Basic to use stricter error checking, which catches common typos whenusingvariables.SimplestPossibleCodeRoutineqEvery module are one or more subroutines. A subroutineisanamedunitofcodethatperforms adistincttask.qSubroutinesstartwiththeword Sub followedby the name of the subroutine and end with the statementEndSubqExample: SubMyCodeRoutine() MsgBoxWitnessthepowerofmycode. EndSubModuletypesqAccessstorescodeintwoplaces: − Classmodules:attachedtotheformorreport, itexecuteswhentheformorreportisopened, the class module does not appear in the modulessection. − Standard modules: Code can also be stored in modules section. Standard modules is accessibletoallobjectsinyourdatabase.RespondingtoaFormEventqOpenaforminDesignmode.qTurnoffControlwizardbutton.qAddanewbutton.qIn the Property Sheet, choose the Event tab, andthenselectthebutton’sOnClick eventqClicktheellipsis(…)intheOnClickEventboxqSelectCodeBuilderandclickOK
Nội dung trích xuất từ tài liệu:
Automating Tasks with Visual BasicAutomatingTaskswithVisualBasicIntroductionqWhencan’t findareadymademacroactionthat doesthejobyouwant,youcanuseVisualBasic code.qExample: − Modifyawholebatchofrecordsatonce. − Performcomplexcalculations. − Interactwithotherprogramsoncomputer. − Write even more complicated validation routinesthatlockoutbaddata.UnderstandingVBATerminologyqSomebasicVBAterminology: − Statement: A word or combination of words thatconstitutesaninstructiontobeperformed bytheVBAengine. − Procedure: A collection of VBA statements thataregroupedtogethertoperformacertain task.Therearetwotypesofprocedures: Subroutines: perform a single task, no § return. Functions: performataskandthenreturna §UnderstandingVBATerminology− Module:Proceduresliveinmodules.Amodule consistsofoneormoreprocedures− Variable:isnothingmorethananameapplied to represent a data value. Variable is used to hold values such as customer names, dates, and numeric values manipulated by the VBA code.TheVisualBasicEditorqVisual Basic code is stored in database, but it need a different tool to view and edit it, called theVisualBasiceditor.qOpentheVisualBasiceditor: In the Access ribbon, choose Database § Tools➝Macro➝VisualBasicTheVisualBasicEditorqThe Visual Basic editor window is divided into threemainregions. − Projectwindow:showsallthemodulesinyour database. − Properties window: which shows settings for the currently selected item in the Project window. − Documentwindow:Editcoderegion.AddingaNewModuleqIntheVisualBasiceditor’smenu,chooseInsert ➝Module.AddingaNewModuleqWhenaddanewmodule,theVisualBasiceditor automatically opens a code window that shows thecontentsofthatmodule.qInitially,abrandnewmodulehasjustonelineof code: OptionCompareDatabase − ThislineisaninstructionthattellsVisualBasic howtohandleoperationsthatcomparepieces oftext.AddingaNewModuleqBefore write code you should add one more instructiontothetopofcodefile: OptionExplicitqThis instruction tells Visual Basic to use stricter error checking, which catches common typos whenusingvariables.SimplestPossibleCodeRoutineqEvery module are one or more subroutines. A subroutineisanamedunitofcodethatperforms adistincttask.qSubroutinesstartwiththeword Sub followedby the name of the subroutine and end with the statementEndSubqExample: SubMyCodeRoutine() MsgBoxWitnessthepowerofmycode. EndSubModuletypesqAccessstorescodeintwoplaces: − Classmodules:attachedtotheformorreport, itexecuteswhentheformorreportisopened, the class module does not appear in the modulessection. − Standard modules: Code can also be stored in modules section. Standard modules is accessibletoallobjectsinyourdatabase.RespondingtoaFormEventqOpenaforminDesignmode.qTurnoffControlwizardbutton.qAddanewbutton.qIn the Property Sheet, choose the Event tab, andthenselectthebutton’sOnClick eventqClicktheellipsis(…)intheOnClickEventboxqSelectCodeBuilderandclickOK
Tìm kiếm theo từ khóa liên quan:
Visual basic module variable project window module types standard modulesGợi ý tài liệu liên quan:
-
Bài giảng Lập trình ứng dụng kinh tế: Phần 1 - ĐH CNTT&TT
73 trang 95 0 0 -
Lập trình trong excel với visual basic
92 trang 32 0 0 -
Giáo trình Visual Basic (Nghề Tin học ứng dụng - Trình độ Cao đẳng) - CĐ GTVT Trung ương I
70 trang 32 0 0 -
Bài giảng Lập trình ứng dụng kinh tế: Phần 2 - ĐH CNTT&TT
74 trang 26 0 0 -
Giáo trình Visual Basic (Nghề Tin học ứng dụng - Trình độ Trung cấp) - CĐ GTVT Trung ương I
70 trang 20 0 0 -
Chương Mười Bốn - Dùng Control Data
9 trang 20 0 0 -
Giáo trình Access và ứng dụng - Chương 6
42 trang 18 0 0 -
51 trang 17 0 0
-
BÀI TẬP LẬP TRÌNH HƯỚNG SỰ KIỆN - CHƯƠNG 1
37 trang 17 0 0 -
Ebook ASP.Net 2.0 all-in-one desk reference for dummies
939 trang 17 0 0