vbpjtip5 面向VisualBasic程序员的杂志 第5版.docx
《vbpjtip5 面向VisualBasic程序员的杂志 第5版.docx》由会员分享,可在线阅读,更多相关《vbpjtip5 面向VisualBasic程序员的杂志 第5版.docx(69页珍藏版)》请在三一办公上搜索。
1、WelcometotheFifthEditionoftheVBPJTechnicaltipsSupplement!ThesetipsandtricksweresubmittedbyprofessionaldevelopersusingVisualBasic3.0,VisualBasic4.0,VisualBasic5.0,VisualBasicforApplications,andVisualBasicScript.ThetipswerecompiledbytheeditorsatVisualBasicProgrammer,sJournal.SpecialthankstoVBPJTechnic
2、alReviewBoardmembersFrancescoBalenaandPhilWeberfortestingallthecode.IfyoudliketosubmitatiptoVisualBasicProgrammer,sJournal,pleasesendittoUsertips,FawcetteTechnicalPublications,209HamiltonAvenue,PaloAlto,California,USA,94301-2500.Youcanalsofaxitto415-853-0230orsenditelectronicallytoVbpjeditQor74774.3
3、050CompuS.Pleaseincludeaclearexplanationofwhatthetechniquedoesandwhyitisuseful,indicateifit,sforVBA,VBS,VB3zVB416-or32-bitzorVB5.Pleasetrytolimitcodelengthto20lines.Dontforgettoincludeyoure-mailandmailingaddress.We,11payyou$25ifwepublishyourtipVB3,VB416/321.evel:BeginningCOMBOBOXEVENTHAND1.INGTwopro
4、blemscanarisewhenaconfuseduserscrollsupordownwiththemouseandthenmakesaselectionwiththeEnterKey.First,thedownarrowfirestwoevents:ChangeandClick.Second,theEnterkeymovesfocustothenexttabstop,whilethemouseclickdoesn,tcausealossoffocusfromthecombobox.Therefore,ifyouplaceyouractioncodeintheChangeevent,anU
5、porDownarrowwillfireit,whichyoudon,twant.Onthecontrary,ifyouplaceyouractioncodeonlyinthe1.ostFocuseventandtheuserclicksonaselection,focuswon,tmovefromthecombobox,andtheuserisleftstaringattheselectedtextinthecomboboxandwonderingwhynoactionoccurred.ThissolutionfiltersoutClickeventsgeneratedwitharrowke
6、ys,andforcesthecontroltolosefocus.IntheDeclarationssectionoftheform,enterthiscode:Note:UseanIntegerflagvariablein,VB3DimbNoiseasBoolean,TruedenotesaNoiseEventwhichisto,beignoredEnterthiscodeintheForm_1.oadevent:bNoise=FalseEnterthiscodeinthecomboboxKeyDownevent:PrivateSubcbTest_KeyDown(KeyCodeAs_Int
7、eger,ShiftAsInteger),Iftheuserisbrowsingwiththe,arrows,ignoretheClickEventsIfKeyCode=VbKeyDownOrKeyCode_=VbKeyUpThenbNoise=TrueEndSubevent:EnterthiscodeinthecomboboxClickPrivateSubcbTest_Click()IfbNoiseThen,IgnoreNoiseevents,(upordownarrow)bNoise=FalseElseForcelossoffocusSendKeys”TAB”,TrueEndIfEndSu
8、bWritecodethatreactstoanewuserselectioninthecombobox1.ostFocusevent.Don,tsendaTabkeystrokebecausefocushasalreadyshifted,andthecombobox,sbehaviorisconsistentregardlessofhowtheuserselectsanewvalue.-1.esSmith,Concord,NorthCarolinaVB51.evel:BeginningCOMMENTANDUNCOMMENTB1.OCKSOFCODEVisualBasic5.0letsyouc
9、ommentablockofcodeinasnapanduncommentitlater.Thisfeatureisusefulinthedebugphase,whenyoudon,twanttoexecuteanumberofstatements,butyoudon,twanttophysicallydeletethemeither.However,theComment/Uncommentcommandpairisn,tpresentinanymenuoftheenvironment,andyoucanonlyreachitbyenablingtheEdittoolbar.Todothisq
10、uickly,right-clickonanytoolbarintheenvironmentandselecttheEditcommand.-FrancescoBalena,Bari,ItalyVB51.evel:BeginningDEFAU1.TVA1.UESFOROPTIONA1.PARAMETERSIfyoueverprogrammedunderVB4,youprobablytookadvantageofthepowerfulOptionalparameters.VB5enhancedtheminseveralways:theycanbeofanytypenow(notonlyVaria
11、nts),andtheycanappearinPropertyprocedures.Interestingly,youcannowstateadefaultvalueforthem:PropertyGetValue_(OptionalindexAs1.ong=1)EndPropertyYoucandothiswithoutanexplicit(andslower)IsMissingtest:PropertyGetValue_(OptionalindexAs1.ong)IfIsMissing(index)Thenindex=1EndProperty-FrancescoBalena,Bari,It
12、alyDON*TCREATEA1.IASEDVARIAB1.ESNeverpassaglobalvariableasanargumenttoaprocedurethatalsoaccessesthevariabledirectly.Ifyou,re100percentsureyouadheredtothisrulewithinyourapplication,checktheAssumeNoAliasingoptionintheAdvancedOptimizationsdialogthatyouinvokefromtheCompiletaboftheProjectPropertiesdialog
13、.Ifthenativecodecompilerknowsnoaliasedvariablesexist,itcanfreelycachevariablevaluesintofasterCPUregisters,andstorethembacktoRAMmemoryonlywhenleavingtheprocedure.Thisimprovestheexecutionspeedofcompiledprograms.-FrancescoBalena,Bari,ItalyVB51.evel:BeginningCENTERFORMSONSCREENApopularcodesnippetletsyou
14、centeranyformonthescreen,regardlessofthecurrentscreenresolution.YounowcanreachthesameresultbysimplyassigningthevalueVbStartUpScreen(=2)totheformsStartUpPositionnewproperty.YoucanevencenteraformwithinitsparentwindowbyassigningtheVbStartUpOwner(=1)value.YoucansetthispropertyfromthePropertywindow.Whena
15、formissupposedtobecenteredwithinitsparentwindow,remembertoaddasecondargumenttotheShowmethod:Form2.ShowVbModalzMe-FrancescoBalena,Bari,Italy0N-E16aDON,TAUTO-OPTIMIZEFORFASTCODEIfyoutakealookatVB,snativecodeoptimizationoptionsforthefirsttime,youmightbetemptedtoclick,onOptimizeforFastCoderightaway.Stra
16、ngeasitmaysound,though,thisdoesnotalwaysguaranteethebestperformance.Applicationsoptimizedforperformancegenerallydon,trunthatmuchfaster,butdohavealargermemoryfootprint.Thiscausesthemtoloadslower,especiallyonmemory-constrainedmachines,givingtheusertheimpressionthatyourappisactuallyslowerthanoneoptimiz
17、edforcompactcode.Forthesamereason,considerleavingyourapplicationscompiledasp-codeanyway.Especiallyforlarge,UI-anddatabase-intensiveapplications,theperformancegainofcompilingtonativecodewon,toutweightheincreaseinapplicationsize.Todetermineexactlywhichcompilationoptionisrightforyou,usetheVBApplication
18、PerformanceExplorer(APE)includedonyourVBCD.-MichieldeBruijn,Rotterdam,TheNetherlandsVBA51.evel:BeginningNOTA1.1.TEMP1.ATESARECREATEDEQUA1.UnliketemplatesinotherOffice97products,Word97templatesprovideabusiness-applicationenginethatremainsseparatefromthedocumentsthatusethatengine.TemplatebasedExcelwor
19、kbooksandPowerPointpresentationsincludeacopyofthatengine.Inpractice,allWorddocumentstwoVBAprojects:thefirstprojectisfromtheunderlyingtemplate),templateandthedocumentitself.On(allWorddocumentsarebasedonasecondprojectbelongstotheWordtheotherhand,ExcelworkbooksandPowerPointpresentationsbasedonatemplate
20、haveonlyoneVBAproject.Everyfilecontainsitsowncopyoftheprojectintheoriginaltemplate.Changesmadetothiscopydon,taffecttheunderlyingtemplate.InExcel,PowerPoint,andAccess,add-insprovidecodeenginesthatremainseparatefromtheworkbooksandpresentationsthatusethoseengines.TocreateanExcelorPowerPointadd-in,useth
21、eSaveAscommandontheFilemenuandsavethefileasaspecifictype:thenAdd-in11type.EachproductusesaspecificAdd-inextension(X1.AforExcel,PPAforPowerPoint,andMDAforAccess).There,snocanonicallocationforstoringadd-ins,buttoloadadd-insautomaticallywhenyoulaunchanOfficeproduct,storethemintheX1.StartfolderorintheSt
22、artUpfolder.Youcanloadadd-insmanuallywiththeAdd-inscommandontheToolsmenu,oryoucanautomatetheprocessincode.TocreateanAccessadd-in,usethecommandMakeMDEfileavailablethroughtheDatabaseUtilitiescommandontheToolsmenu.-ChristineSolomon,NewYork,NewYorkVB51.evel:BeginningCUSTOMIZEVBTOO1.BARSHereareafewsimple
23、waysyoucancustomizeyourVB5IDE:?AddtabstothecustomcontroltoolboxbyrightclickingontheGeneralbuttonandselectingtheAddTabcommand.Youcanalsomovetabsaroundanddeletethem,aswellasmovecontroliconsfromonetabtotheotherusingthedrag-and-dropmethod.?Createtoolbarbuttonsforanymenucommandbyrightclickingonanytoolbar
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- vbpjtip5 面向VisualBasic程序员的杂志 第5版 面向 VisualBasic 程序员 杂志
链接地址:https://www.31ppt.com/p-7146639.html