vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx
《vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx》由会员分享,可在线阅读,更多相关《vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx(82页珍藏版)》请在三一办公上搜索。
1、WelcometotheFourthEditionoftheVBPJTechnicalTipsSupplement!ThesetipsandtricksweresubmittedbyprofessionaldevelopersusingVisualBasic3.0,VisualBasic4.0,VisualBasicforApplications,andVisualBasicScript.ThetipswerecompiledbytheeditorsatVisualBasicProgrammer,sJournal.SpecialthankstoVBPJTechnicalReviewBoardm
2、embersDougHaynes,KarlE.Peterson,andPhilWeberfortestingallthecode.Ifyou,dliketosubmitatiptoVisualBasicProgrammer,sJournal,pleasesendittoUserTips,FawcetteTechnicalPublications,209HamiltonAvenue,PaloAlto,California,USA,94301-2500.Youcanalsofaxitto415-853-0230orsenditelectronicallytovbpjedil.Pleaseinclu
3、deaclearexplanationofwhatthetechniquedoesandwhyitisuseful,indicateifit,sforVBA,VBS,VB3,orVB4,16-or32-bitversion.Pleasetrytolimitlimitcodelengthto20lines.Do11,tforgettoincludeyoure-mailandmailingaddresses.We,11payyou$25ifwepublishyourtip.VB3,VB416/321.evel:BeginningEasyCR/1.FPaddingWhenIwritetextinme
4、ssageboxes,labels,andsoon,and1needtoincludeacarriagereturn/1inefeed,Iusethisfunction,passingitthenumberofCR/1.FsIneed.ThissavesalotoftypingandlookingupofASCIIvalues:SubcmdDelete_Click()msg=Areyousureyouwant_,todeletethisitem?”&N1.(2)&Press0K”rc=MsgBox(msg,4+32+256,ConfirmDelete*)endsubFunctionN1.(nu
5、m_linesAsInteger)AsStringThisfunctionreturnsaNew1.inecharacterforthenumberoftimespassedtothefunction.*DimmsgsStringDimiAsIntegerFori=1Tonumlinesmsg=msg&Chr(13)&Chr(IO)NextN1.-msgEndFunction-BretCutler,1.ayton,UtahVB3,VB416/321.evel:BeginningAutoSelectTextBoxContentsUsersoftenfinditfastertoretypethee
6、ntirecontentsofatextboxratherthanpositionthecursorwithinthedata,andtheneditthedata.Thisisespeciallytrueifthelengthofthedataisshortorifthedataisn,tvisible,aswithapasswordfield,forexample.Doubleclickingorusingamousetoselectthecontroscontentsisslowandinconvenient.Icreatedthissmallroutinetoautomatically
7、selectalldatawithinacontrol.Iplacethisroutineinacodemodulesothatit,saccessiblefromallforms.Icallthisroutinefromacontrol*sGotFocusevent.Thisway,thedataisselectediftheusertabstoorclicksonthecontrol,orifadatavalidationroutinedoesaSetFocus:PrivateSubMyTextBox_GotPocus()AutoSelectMyTextBoxEndSubTheAutoSe
8、lectroutineisquitesimple:SubAutoSelect(SelObjectAsControl)TheAutoSelectroutine,selectsthecontrosentirecontentsasifitweredoubled-clicked.SelObject.SelStart=OIfTypeOfSelObjectIsMaskEdBoxThenSelObject.Sel1.ength=1.en(SelObject.FormattedText)ElseIfTypeOfSelObjectIsTextBoxThenSelObject.Sel1.ength=1.en(Se
9、lObject.Text)EndIfEndIfEndSub-KevinForth,St.ClairShores,MichiganVB416/321.evel:BeginningCleartheClutterProvideyouruserswithaquickwaytocleartheirmessydesktopofextraneousformsbydroppingthiscodeintotheClickeventofacommandbutton:ForEachFormInFormsIfForm.NameMe.NameThenUnloadFormEndIfNextForm-JamesBell,C
10、harlotte,NorthCarolinaVB3,VB416/321.evel:BeginningCalculateAgeUsingDateDiffUsethefunctionDateDifftocalculateanindividuasexactagebasedonbirthdate.DateDifffirstcalculatesthetotalnumberofdaysanindividualhasbeenaliveandthendividesby365.25toaccountforleapyears.TheIntfunctiontruncatesthedivisionresultsbyr
11、emovingthedecimalandnotrounding:FunctionCalcAge(datEmpDateOfBirthasVariant)asIntegerCalcAge=Int(DateDiff(*y*,datEmpDateOfBirth,Date()_/365.25)EndFunction-MichaelFinley,ClarendonHiIls,IllinoisVB416/321.evel:IntermediatePreventUnwantedRecursionAbugaffectingtheSheridan3DControlsappearsinVB4.0a.Ido11,tb
12、elieveitwasin4.0,andIamcertainitwasnotin3.0.Inanycase,evenifyouuse4.0,youshouldpayattentionbecausethenewerOCXmaybeinstalledalreadyonusers*machineswhenyourappsaredistributed.IusetheSheridancommandbuttonsquiteabitfortheirabilitytodisplayaniconaswellastext,andIranintothisproblemwhenIinstalledVB4.0a.Ift
13、heuserdouble-clicksonacommondialogbox(forexample,toselectafile),andthedoubleclickisphysicallylocatedaboveaSheridan3Dcommandbutton,theClickprocedureofthatcommandbuttonwillbefired.Totestthis,startanewprojectandplaceaSheridancommandbuttonandacommondialogcontrolonForml.IntheClickprocedureofthecommandbut
14、ton,includethiscode:PrivateSubSSCommand1_C1ick()ConstCDERR_CANCE1.;&H7FF3ConimonDialogl.DialogTitle=OpenFile”CommonDia1og1.fiIename=*.*ConimonDialogl.DefaultExt=ConimonDialogl.CancelError=TrueCommonDialogl.Filter=,A11Files(*.*)*.*OnErrorResumeNextConimonDialogl.Action=1IfErr=CDERR_CANCE1.ThenExitSub
15、EndIfOnErrorGoToOEndSubRuntheprogram,clickonthecommandbutton,andwhenthecommondialogappears,moveitsothatthenameofanyfileappearsoverthebutton.Double-clickonthefilename.Thecommondialogwilldisappearandanewonewillappear,resultingfromtheSSCommandlClickeventfiringagain.Thesolutionistodeclareastaticflagvari
16、able,FalseClick,withinthebutton*sClickevent.ThenchangethecodeintheSSComniandlClickproceduretoread:PrivateSubSSCOmInand1.CliCkoConstCDERR.CANCE1.=&II7FF3StaticFalseClickAsBooleanIfFalseClickThenExitSubFalseClick=TrueCommonDialogl.DialogTitle=OpenFile”ConimonDialogl.filename=CommonDialogl.DefaultExt=.
17、*CommonDialogl.CancelError=TrueConimonDialogl.Filter=AllFiles(*.*)*.*OnErrorResumeNextCommonDia1og1.Action=1IfErr=CDERR_CANCE1.ThenFalseClick=FalseExitSubEndIfOnErrorGoToODoEvents,allowforrecursionFalseClick=FalseEndSubTheDoEventsfunctionisrequiredinanyprocedurethatissoshortthatthelaststatementexecu
18、tesbeforetherecursionbegins.Ihopethisworkaroundcanhelpothersfixthesameproblem.-MichaelP.Rose,Kingwood,TexasVB31.evel:IntermediateObtainingSystemDateFormatTheDateCheckfunctionisusefulwhenyouusetheMaskedEditcontrolforenteringthedateaccordingtothesystemformat.SomecountriesusetheMM/DD/YYYYformat,andothe
19、rcountries,likeIndia,usetheDD/MM/YYYYformat.Insteadofhard-codingtheMaskedEditcontrolsformataswel1asmaskproperties,usethisfunctiontosettherequireddateformataccordingtothecontrolpanelsettings.IntheGeneraldeclarationsectionofthemodule,definethis:DeclareFunctionGetProfiIeString1.ib_“Kernel”(ByvalSname$,
20、ByValKname$,ByvalDef$,ByvalRet$,ByvalSize%)asintegerglobaldatemaskasvariantglobaldateformatasvariantSubDateCheck()DimStrsecnamcasstringDimStrkeynameasstringDimVarsuccessasvariantDimStrretdateasstringDimStrretsepasstringDimStrcharasstring*1Strsecnamc=Tntl”Strkeyname=sShortDate”Strretdate=string$(11,0
21、)Varsuccess=GetProfilestring_(Strsecname,Strkeyname,Strretdate,_(Strretdate)Strsecname二Strkeyname=sDate”Strretsep=StringS(2,O)Varsuccess=GetProfiIeString_(Strsecname,Strkeynane,“,.Strretsep,1.en(Strretsep)Strretsep=1.eftS(strretsep,1)Strchar=Ucase$(1.eftS(strretdate,1)datemask=#&Strretsep&Strretse
22、pSelectcasestrcharcaseD:dateformat=DD_&Strretsep&Strretsep&YYYYcaseM:dateformat=MM”_&Strretscp&DD&Strretsep&YYYYcaseY:datemask=#_&Strretsep&Strretsepdateformat=YYYY&_Strretsep&MM&Strretsep&DD”EndselectEndSubIntheForm_1.oadevent,calltheDateCheckproceduretogetthecurrentdateformat,andassignformat
23、andmaskpropertiesoftheMaskedEditcontrol:SubFonn_1.oad()DateCheckCallthedatecheckprocedureMskdd.format=dateformatMskdd.mask=datemaskEndSub-S.Saravanan,Selaiyur,Madras,IndiaVB4321.evel:Intermediate1.ongFileNamesCanBeConfusingIfyouwanttoopenPaintwithafilefromyourapplication,it,sbettertoconvertthepathof
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- vbpjtip4 面向VisualBasic程序员的杂志 第4版 面向 VisualBasic 程序员 杂志
链接地址:https://www.31ppt.com/p-7146638.html