vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx

上传人:p** 文档编号:1030241 上传时间:2024-06-15 格式:DOCX 页数:82 大小:124.40KB
下载 相关 举报
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第1页
第1页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第2页
第2页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第3页
第3页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第4页
第4页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第5页
第5页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第6页
第6页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第7页
第7页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第8页
第8页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第9页
第9页 / 共82页
vbpjtip4 面向VisualBasic程序员的杂志 第4版.docx_第10页
第10页 / 共82页
亲,该文档总共82页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《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.Thesolutionistodeclareastaticflagvariable,FalseClick,withinthebutton*sClickevent.ThenchangethecodeintheSSComniandlClickproceduretoread:PrivateSubSSCOmInand1.CliCkoConstCDERR.CANCE1.=&II7FF3StaticFalseClickAsBooleanIfFalseClickThenExitSubFalseClick=TrueCommonDialogl.DialogTitle=OpenFile”ConimonDialogl.filename=C

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > Java

copyright@ 2008-2023 1wenmi网站版权所有

经营许可证编号:宁ICP备2022001189号-1

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。第壹文秘仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知第壹文秘网,我们立即给予删除!