tips_7 面向VisualBasic程序员的杂志 第7版.docx
《tips_7 面向VisualBasic程序员的杂志 第7版.docx》由会员分享,可在线阅读,更多相关《tips_7 面向VisualBasic程序员的杂志 第7版.docx(41页珍藏版)》请在三一办公上搜索。
1、WelcometotheSeventhEditionoftheVBPJTechnicalTipsSupplement!VB3,VB416/32,VB51.evel:BeginningDeletinganArrayElementConventionalwisdomsuggeststhattodeleteanarrayelement,youmustmoveupallthesubsequentelementstoclosethegapleftbythedeleteditem.However,ifthesequenceoftheelementsisntsignificant(asinanunsorte
2、darray),thisalgorithmquicklydeletesanitem:,Elementtodelete(Delete=5NumberofelementsbeforedeletionnElements三UBound(Array)ReplaceiDeletewithlastiteminarrayArray(IDeIete)=Array(nElements)*UseReDimPreservetoshrinkarraybyoneReDimPreserveArray(1.Bound(Array)_TonElements-1)一BasilHubbard,Hammon,Omario,Canad
3、aVB432,VB5,VBA1.evel:IntermediateInvokehOpenWith.,DialogBoxWhenlaunchingadatafilewiththeSheIIExecuteOfunction,Windowstriestofindtheassociatedapplicationandopenthedatafilewiththisapplication.Butwhathappensifnoassociationexists?SheIIExecuteOsimplyreturnserrorde31(noassociation)andnothinghappens.Wouldn
4、titbeniceifyourprograminvokedthe41Openwith.dialogboxsoyoucanchsewhichapplicationyouwanttoassociatewithyourdatafile?Heresasolution-calltheSheIIDocroutineandpassafullyqualifiedpath/filenameofthedatafileyouwishtoopen:OptionExplicitDeclareFunctionGetDesktopWindow1.ib,tuser32,()As1.ongDeclareFunctionSheI
5、IExecute1.ib_,shell32.drAliasSheIIExecuteA.(ByVaIhW11dAs1.ong,ByVaIIpOperation_AsString,ByVaIIpFiIeAsString,_ByVaIIpParametersAsString,_ByVaIIpDirectoryAsString,_ByVaInShowCmdAs1.ong)As1.ongDeclareFunctionGetSystemDIrectoryUb_“kemel32AliasGetSystemDirectoryA_(ByVaIIpBufferAsString,ByVaInSize_As1.ong
6、)As1.ongPrivateConstSE-ERR-NOASSOC=31PublicSubShellDoc(strFileAsString)DimIngRetAs1.ongDimStrDirAsStringIngRet=SheHEXeCUte(GetDeSktoPWindOw,_open”,StrFiIe,_VbNuIIString1VbNuIIString.VbNormaIFocus)IfIngRet=SE_ERR_NOASSOCThennoassociationexistsStrDir三Space(260)IngRet=GetSyStemDireCtOry(StrDir,_1.en(St
7、rDIr)StrDir三1.eft(strDir,IngRet)showtheOpenwithdialogboxCallShellExecutefGetDesktopWindow,_VbNuIIString,RUND1.1.32.EXE-,Mshell32.dll,OpenAs.RunD1.1.”&_StrFite1StrDir1VbNormaIFocus)EndIfEndSub-ThomaSWeidmannjeceivedbyemailVB432,VB51.evel:BeginningSSTABVs.OptionButtonsAlthoughVB,sSSTabntrolbehavesasif
8、eachtabpageisacontainer,itactuallyusesasinglecontainerforalltabpages.Thiscancauseunexpectedbehaviorifyouhavegroupsofoptionbuttonsondifferentpages.Clickingonanoptionbuttonononepageclearsalltheuncontainedoptionbuttonsontheother,seeminglyunrelated,pages.Solvethisproblembyaddingyourowncontainersframesor
9、pictureboxes)foreachgroupofoptionsyouwanttobemutuallyexclusive.SteveCiSCoandROIandSOUtharaFranklin,TenneSSeeVB432,VB51.evel:BeginningChangetheAppearancePropertyofaTextBoxatRunTimeSorry,youcantchangetheAppearancepropertyofatextboxatruntimebutyoucanmakeitlooklikeyouhave!Ifsettonone,a3-Dpictureboxhasaf
10、latBorderStyIeproperty.Putyourtextbox(withaflatappearance)insideapicturebox(witha3-Dappearance)andchangethepictureboxsborderstyle.UsethiscompletecodebesureyouplaceText1insidePicturel:Privatem_TextVAppearanceAs1.ongPrivateSubForm_1.oad()WithText1Picturel.Width=.WidthPicturel-Height三.Height.MoveO,OEnd
11、WithText1_Appearance1,3DEndSubPublicProperty1.et_Text1_Appearance(nAppearanceAs1.ong)WithPicturelSelectCasenAppearanceCaseOFlat.BorderStyIe三nAppearanceCase1,3D.BorderStyIe=nAppearanceEndSelectm_Text1_Appearance三.BorderStyIeEndWitfCEndPropertyPublicPropertyGetText1_AppearanceOAs1.ongTeXt1.APPearanCe三
12、m_Text1_AppearanceEndPropertyJimDeutch,CaZenOvia,NeWYorkVB432,VB51.evel:BeginningDealingWithNullValuesReturnedFromRDOResultsetsIfyou,rassigningthevaluesoflumnsyoureturnfromRDOqueriesintostringvariables,you,llgetanInvaliduseofNulerrorifoneofthecolumnshasaNullvalue.Formostpurposes,dratherhavethevaluea
13、sanemptystringanyway.RatherthancodeforthateachtimeIaccessacolumn,l,vewrittenafunctioncalledCleanthatturnsNullvaluesintoemptystrings.Icallitlikethis:strMyString=Clean(rdoResultset(MMyVarCharColumnM)IalsoconvertEmptyvaluesaswell,forusewithVariants:PublicFunctionClean(ByValvarDataAsVariant)AsStringIfIs
14、NuII(VarData)ThenClean三ElselfIsEmpty(VarData)ThenClean=ElseClean=CStr(VarData)EndlfEndFunction-JameST.Stanley,MuncieJndianaVB3,VB416/32,VB51.evel:BeginningInSearchofSampleCodemalwayslookingforsamplecode,andthesetup1.vbpfileisanexcellentsourceofreusablecode.ItcomeswithVBandispartoftheVBsetupkit.Theco
15、ntentsvary,dependingonwhatversionofVByouhave,butyoullfindusefulexamplesineachversion.Forexample,theVB5filesamplecodedoesthesethings: GetstheWindowsdirectory. GetstheWindowsSystemdirectory. Determinesifafileordirectoryexists. DeterminesifyourerunningWinNTorWin95.,Determinesdrivetype. Checksdiskspace.
16、 Createsanewpath. ReadsfromanINIfile. Parsesdateandtime. Retrievestheshortpathnameofafilentaininglongfilenames.Plus,awholemoduleworkstologerrorstoanerrorfile.Thisdeiswell-commentedandcaneasilybecutandpastedintoyourproject.CaroleMCCIlISke1.Seattle,WaShingtOnVB416/32,VB51.evel:IntermediateFloatinganEd
17、itBoxTominimizethenumberofcontrolsonmyforms,IuseatextboxasafloatinginputcontrolthatIeitheroverlayontoagridorswapwithalabel.Hereismyswapsubroutine:PublicSubSW叩COntrOIS(CHideAsControl,_eShowAsControl,OptionalValue)WithcHlde.Visible三FalsecShow.Move.1.eft,.Top,.Width,.HeightEndWithIfIsMIssing(VaIue)Then
18、WTypeOfeShowIsTextBoxOr_TypeOfeShowIs1.abelTheneShow=cHideEndIfEISeeShow=ValueEndIfWitheShow.Visible三True.ZOrderHTypeOfeShowIsTextBoxThen.SeIStart三O.SeI1.ength=1.n(cShow)If.VisibleThen.SetFocusEndHEndIfEndWithEndSubWhenIenterthestatementwSwapControIsIbIData,txtData,IbIDatadisappearsandtxtDataappears
19、initsplacewiththevalueofIbIDataselectedandthefocussettoit.Afteryoumakeyourentry,executethestatementSwapControlstxtData,IbIData.-CaIogeroS.Cumbo,Waterloo,Ontario,CanadaVB432,VB51.evel:IntermediateYetAnotherCenterFormRoutineIntheApril1997issueofVBPJ,youpublishedatipcalledConsidertheTaskbarWhenCenterin
20、gForms.YoucancenterformsmoreeasilywiththeSystemParametersInfoAPIcall:PrivateDeclareFunction_SystemParametersInfo1.ibuser32Allas_SystemParametersInfoAt(ByVaIuAction_As1.ong,ByVaIuParamAs1.ong,RAsAny,_ByVaIfuWinlniAs1.ong)As1.ongPrivateTypeRECT1.eftAs1.ongTopAs1.ongRightAs1.ongBottomAs1.ongEndTypePriv
21、ateConstSPI_GETWORKAREA=48PublicSubCenterForm(frmAsForm)DimRAsRECT,IResAs1.ong,DimIWAs1.ong,IHAs1.ongIRes三SystemParameterslnfo(_Splgetworkarea,o,r,o)IfIResThenWithR.1.eft=Screen-TwipsPerPixeIX.1.eft.Top=Scrn.TwlpsPrPlxlY.Top.RightsScreensTwipsPerPixeIXw.Right.Bottom=Screen.TwipsPerPixeIY*.BottomIW=.
22、Right-.1.eftIH=.Bottom-.Topfrm.Move.1.eft(IW-frm.Width)2,_.Top(IH-frm.Height)2EndWithEndIfEndSubNiCholaSSorokin,Sarasota,FloridaVB51.evel:IntermediateTieaMessageBoxtoDebg.AssertforAdvancedDebuggingPlacingamessageboxinanerrortrapcanprovideusefuldebugginginformation,butitdoesntallowyoutoreturntothesub
23、routineorfunctiontopokearoundandfurtherdebugthecode.Thisversionofamessageboxexpeditesdesign-timedebuggingbybreakingexecutionifthedeveloperpressesOK:PrivateFunctionMyDebugMsg(ByValaMessage_AsString)AsBooleanThisfunctionisusedforexpeditingdevelopmentIfMSgBOX(aMessage,VbOKCanceI,_,0KputsyouintotheError
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- tips_7 面向VisualBasic程序员的杂志 第7版 面向 VisualBasic 程序员 杂志
链接地址:https://www.31ppt.com/p-7145847.html