tips_6 面向VisualBasic程序员的杂志 第6版.docx

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

《tips_6 面向VisualBasic程序员的杂志 第6版.docx》由会员分享,可在线阅读,更多相关《tips_6 面向VisualBasic程序员的杂志 第6版.docx(56页珍藏版)》请在优知文库上搜索。

1、WE1.COMETOTHESIXTHEDITIONOFTHEVBPJTECHNICA1.TIPSSUPP1.EMENT!ThesetipsandtricksweresubmittedbyprofessionaldevelopersusingVisualBasic3.0,VisualBasic4.0,VisualBasic5.0,VisualBasicforApplications(VBA),andVisualBasicScript(VBS).VB416/321.evel:IntermediateUSEBOO1.EANVARIAB1.ESFORCHECK-BOXVA1.UESVisualBasi

2、cspecifiesaBooleansdefaultvaluesaszeroforFalseand-1forTrue.Youmaysaveandsetthevalueofacheckbox,basedontheabsolutevalueofaBooleanvariable,asthesecorrespondtotheintrinsicconstantsVbUncheckedandVbChecked:DimbBoolasBooleanbBool=True/IfbBool=0thecheckboxwillbe/unchecked,ifitisanythingelseitwill,/bechecke

3、d.Checkl.Value=Abs(bBool)-JeremyBoschen,Branchburg,NewJerseyVB416/321.evel:IntermediateDISP1.AYHORIZONTA1.SCRO1.1.BARUnliketheWindows95commoncontrols,thestandardlistboxdoesnthaveahorizontalscrollbarwhenlistitemsaretoowidetofitwithinthelistbox.Fortunately,itsnothardtodirectalist-boxcontroltodisplayah

4、orizontalscrollbar.Addthiscodetoaforms1.oadevent.Itfillsalistboxwith100longstringsandcallsSetHScroIItoshowahorizontalscrollbarinthelistbox:PrivateSubForm_1.oad()DimiAsIntegerFori=1To1001.istl.AddItemCStr(i)&_ubottle(三)ofbeeronthewall.uNextiSetHScrollMe,1.istl,1.istl.1.ist(0)EndSubAddthiscode,whichin

5、cludestherequiredAPIdeclarationsandtheSetHScroIIroutine,toaBASmodule.TheSetHScroIIroutineusestheSendMessageAPIfunctiontosendthe1.B_SETHORIZONTA1.EXTENTmessagetoalistbox.Thelastargumentisanitemfromthelist,preferablyoneofthelongestitems.SetHScroIIdeterminesthestringswidthinpixelsandpassesthisvaluetoth

6、elistboxalongwiththe1.B_SETHORIZONTA1.EXTENTmessage.Thelistboxsetsitshorizontalextenttothisvalue,andifitiswiderthanthelist-boxcontrol,thelistboxdisplaysahorizontalscrollbar:#IfWin32ThenDeclareFunctionSendMessage1.ib11user3211_AliasnSendMessageAn(_ByValhwndAs1.ong,ByValwMsgAs1.ong,ByValwParamAs1.ong,

7、IParamAs1.ong)As1.ong#ElseDeclareFunctionSendMessage1.ib,user3211_AliasSendMessageAn(_ByValhwndAsInteger,ByValwMsgAsInteger,ByValwParamAsInteger,IParamAs1.ong)As1.ong#EndIf,Defineconstantformessagetolist-boxcontrolConst1.B_SETHORIZONTA1.EXTENT=&H194PublicSubSetHScroll(FrmAsForm,CtrlAs_Control,StrTex

8、tAsString)DimnScaleModeAsIntegerDimnTextWidthAsInteger,ScaleinpixelsforwindowmessagenScaleMode=Frm.ScaleModeFrm-ScaleMode=3,Getthewidth,inpixels,ofthetextstringnTextWidth=Frm.TextWidth(StrText),SendamessagetothelistboxSendMessageCtrl.hwnd,1.B_SETHORIZONTA1.EXTENT,nTextWidth,O,Restorepreviousscalemod

9、eFrm.ScaleMode=nScaleModeEndSub-PeterGomis,Shelton,ConnecticutVB416/32,VB51.evel:BeginningGETTHETRUEMEMBEROFANOPTIONARRAYSettinganelementinanarrayofoptionbuttonstoTrueiseasy.Clickontheoptionbutton,orusethiscode:OptionArray(ThisOne)=TrueThisOneistheIndexofthememberyouwanttobeselected.GettingtheTrueme

10、mberofanoptionarrayisnotsosimple.Becauseyouneedtoperformthiskindoftaskinalmostanyreasonablycomplexprogram,addingthisfunctiontoyourcodelibraryorgenericmodulesimplifiesthetask.Youdon,tneedtoknowthearraysizeinadvance:FunctionOptionTrueIs(OptionArrayNameAs_Variant)AsInteger,ReturnstheindexoftheTrue,memb

11、erofanoptionarrayDimCtlasControlForEachCtlinOptionArrayNameIfCtl.Value=TrueThenOptionTruels=Ctl.IndexExitForEndIfNextEndFunctionYoucanusetheroutinetosetaPublicvariablefromaPropertiessheetusingthisformat:SomePublicVariable=OptionTrueIs(SomeOptionArray()Orusethiscodetosaveaprogramvariablebetweenruns:S

12、aveSetting(uMyAppu,uOptionSettingsu,_OptionKeyn,OptionTrueIs(SomeOptionArray()1.oadtheroutineusingthiscode:SomeOptionArray(GetSetting(uMyAppu,uuzOptionsettings,OptionKeyn,O)j=TrueOryoucanloadtheroutineusingthiscode:SomePublicVariable=GetSetting(uMyAppu,11zOptionSettings,nOptionKeyn,O)Usethiscodetoco

13、ntrolaSelectCasestructure:SelectCaseOptionTrueIs(SomeOptionArray()CaseO:,ThiscodewillexecuteifelementO,ofSomeOptionArray()isselected.EndSelectUsethiscodetotestacondition:IfOptionTrueIs(SomeOptionArray()=SomeValueThen,Thiscodewillexecuteifelement,SomeValueofSomeOptionArray()is,selected.EndIf-RogerGil

14、christ,Ourimbah,NewSouthWales,AustraliaVB416/32,VB51.evel:IntermediateDEBUGERRORHAND1.ERSVisualBasicgivesyoutheoptiontoturnofferrortrappinginyourprojects.Thisisusefulwhenyoususpectthatyourerrorhandlerscontainerrorsthemselves.Toturnofferrorhandlingglobally,chooseOptionsfromtheToolsmenu.SelecttheGener

15、altab,andselectBreakonAllErrors.Thenexttimeyourunyourprojectinthedevelopmentenvironment,VisualBasicwillbreakwheneveranerroroccursinyourcode,whethertheerroristrappedornot.-JeffreyP.McManus,SanFrancisco,CaliforniaVB3,VB416/32,VB51.evel:BeginningPROTECTDATAWITHINMODU1.ESUsePrivatevariablesinBASmodulest

16、oprotectdatathatthemodulesroutinesmustaccess,butwhichshouldbehiddenfromtherestoftheapplication:Dimhidden_dataAsIntegerFunctionGetData()AsIntegerGetData=hidden_data*2EndFunction-RodStephens,Boulder,ColoradoVB3,VB416/32,VB5,VBA1.evel:IntermediateCONVERTATEXTFI1.EINTOACCESSMDBItcanbetroublesometoconvertatext

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

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

copyright@ 2008-2023 yzwku网站版权所有

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

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