... 253.2.5Lưuvàđặttênđềán 26VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:9/2602222LLLLààààmmmmquenquenquenquenvvvvớớớớiiiivisual visual visualvisualbasic basic basic basic6 .06.06.06.02.12.12.12.1XXXXââââyyyyddddựựựựngngngngứứứứngngngngddddụụụụngngngngbanbanbanbanđầđầđầđầuuuu2.1.12.1.12.1.12.1.1ViViViViếếếếttttứứứứngngngngddddụụụụngngngngbanbanbanbanđầđầđầđầuuuuCáchtốtnhấtđểhọclậptrìnhlàviếtchươngtrình.Vậyhãythửviếtchươngtrìnhhiểnthịlịchbiểu,trongđóchophépngườisửdụng:•Hiểnthịlịchbiểucủathánghiệnhành•Duyệtquacáctháng•HiểnthịđồnghồbáogiờhiệnhànhNếubạnchorằngchươngtrìnhnàycóvẻnặngnềchongườimớihọc,đừnglolắng.Visualbasiclàmhếtmọiviệcchobạn.KhácvớingônngữC++,bạnphảiviếtmỗithứmộtít,Visualbasiccungcấpmứcđọcaohơncủalậptrìnhtựđộng.Nhưvậy,bạncóthểlàmnhiềuthứmàkhôngphảilậptrìnhnhiều.Tuynhiên,đừnghiểusai“khônglậptrìnhnhiều”nghĩalà“khôngcónhiềutínhnăngmạnh”Visualbasiclàmộtngônngữrấtmạnh.Tacóthểlậptrìnhđểlàm“mọithứ”nếucần.TacũngcóthểkhaitháckhảnăngtựđộngcủaVisualbasicđểviếtchươngtrìnhthậtnhanh.Chọnlựalàởngườilậptrình.Visualbasicđủlinhhoạtđểhỗtrợchongườilậptrìnhtừngườimớihọcđếnlậptrìnhchuyênnghiệp.2.1.22.1.22.1.22.1.2XXXXââââyyyyddddựựựựngngngngttttíííínhnhnhnhnnnnăăăăngngngngCalendarCalendarCalendarCalendarBâygiờtabắtđầuxâydựngcáctínhnăngcủaứngdụng.Đầutiên,tacầnmộtlịchbiểu.TacóthểtựtạonóhoặcsửdụnglịchbiểucósẵncủaVisualbasic(đâylàmộtđiềukhiểnActiveX).Tachọncáchthứ2.TừmenuProject,chọnComponents.Bởivì,mặcđịnhtấtcảcácđiềukhiểnActiveXcủaVisualbasickhôngđượcnạptựđộng.MuốndùngbạnphảichọntừmenuComponents.TronghộpthoạiComponentschọnWindowsCommonControls2.6.0vànhấnOK.VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:26/2603.HoặclàtừmenuProperties,chọnProjectNameProperties3.2.53.2.53.2.53.2.5LLLLưưưưuuuuvvvvààààđặđặđặđặttttttttêêêênnnnđềđềđềđềáááánnnn3.2.5.13.2.5.13.2.5.13.2.5.1LLLLưưưưuuuuđềđềđềđềáááánnnnKhilưuđềántừngtậptintrongđềánsẽđượclưutrướckếtiếplàtệptinđềán.Tronglầnlưuđềánđầutiên,VisualBasicđềnghịtênchotừngtệptin,thườngnólấytênbiểumẫuvàcóphầnmởrrộngtuỳthuộcvàoloạitệptin1.từmenufilechọnSaveProject2.nếuđâylàlầnđầulưuđềánhoặctavừathêmmộtbiểumẫuhoặcmodule,hộpthoạisaveFileasxuấthiệnlầnlượtchotừngtệptin3.2.5.23.2.5.23.2.5.23.2.5.2ĐổĐổĐổĐổiiiittttêêêênnnnTakhôngnhấtthiếtdùngtênmàVisualBasicđềnghị,màcóthểđặttuỳý.tuynhiênnêndặttênsaochogợinhớ1.Đưavàomộttênvàấnnútsave2.TậptincuốicùngđượclưulàtệptinđềánNếutađãđặttênchođềánthôngquahộpthoạiprojectproperties,VisualBasicsẽtựđộngđềnghịProject_Name.vbp.Lúcnày,tacóthểđổilạitênkháctuỳthích,vídụnhưSaveTest.vbp3.2.63.2.63.2.63.2.6MMMMởởởởđềđềđềđềáááánnnnccccóóóóssssẵẵẵẵnnnnTacómộtsốđềánđanglàmviệc.KhởiđộngVisualBasic,chọnmenuFile.Phầndướimenuliệtkêdanhsáchcácđềánmớinhấtmàtađãlàmviệc,chọnđềáncầnmở.nếuđềánkhôngxuấthiệntrongdanhsách,taphảichỉrađườngdẫn.3.2.6.13.2.6.13.2.6.13.2.6.1mmmmởởởởttttệệệệpppptintintintinvvvvààààoooollllúúúúcccckhkhkhkhởởởởiiiiđộđộđộđộngngngngVisual Visual VisualVisualBasic Basic Basic Basic LầnđầukhởiđộngVisualBasic,hộpthoạiNewprojectxuấthiện.tacóthểchọnmởđềánmớinhấthoặccósẵntrênđĩangaytừhộpthoạinày.nếukhôngmuốnhộpthoạinàyxuấthiệnmỗilầnkhởiđộngVisualBasic,xoáđánhdáutrênhộpđánhdấu(checkbox)nằmởbêndướihộpthoại.3.2.6.23.2.6.23.2.6.23.2.6.2MMMMởởởởđềđềđềđềáááánnnnccccóóóóssssẵẵẵẵnnnna.TừmenuFile,chọnOpenProject.b.trêntrangExisting,chuyểnđénthưmụcchứađềán.nếuđềáncầnmởlàđềánlưugầnnhất,chuyểnsangtrangRecentc.chọntêntệptinđềánvànhấnOKVisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:15/2602.3.82.3.82.3.82.3.8TrTrTrTrợợợợgigigigiúúúúppppKhôngnhữnglàmchủngônngữlậptrìnhVisualbasic,bạncũngcầnphảisửdụngthuầnthụcmôitrườngVisualbasiccũngnhưhiểucácthôngđiệpmàVisualbasicgửira.Microsoftcungcấpmộttrongnhữnghệthốngtrợgiúptốtnhấtchocáccôngcụpháttriểnứngdụng.TrTrTrTrợợợợgigigigiúúúúppppnhnhnhnhạạạạyyyyvvvvớớớớiiiingngngngữữữữccccảảảảnhnhnhnhTạimộtvịtríbấtkỳtrongVisualbasic,bạnnhấnphímF1,núttrợgiúp.NósẽkíchhoạthệthốngtrợgiúpcủaVisualbasic,nơicóthểgiảithíchhoặcđưaranhữnglờikhuyên,cũngnhưcácđoạnchươngtrìnhmẫu.VisualbasiccóhệthốngtrợgiúplàhệthôngthưviệnMSDNđượcsửdụngrộngrãichocáccôngcụpháttriểncủaMicrosoftđểcungcấptruycậpđếnsổtayhướngdẫnsửdụngsảnphẩmtrựctuyến.VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:21/260PrivateSubForm_Load()'SettheCaptionpropertyoftheCommandButtonscmdTopLeft.Caption="TopLeft"cmdTopRight.Caption="TopRight"cmdBottomLeft.Caption="BottomLeft"cmdBottomRight.Caption="BottomRight"'CleartheinitialtextofthelabellblNotify.Caption=""'Settheform'stitlebartextfrmMove.Caption="MoveIt"'Therestofthecodecenterstheformonthe'screen,setsthepositionofthefour'CommandButtons,andsetsthesizeand'positionofthelabel.'Centertheformonthescreen.Thisworksby'settingtheLeftsideoftheformtothecenter'ofthescreen,lesshalfthewidthoftheform.'Also,theTopoftheformissettothecenter'ofthescreen,lesshalftheheightoftheform.frmMove.Left=(Screen.Width-frmMove.Width)/2frmMove.Top=(Screen.Height-frmMove.Height)/2'SettheLeftedgeofthebuttons.The200setting'fortheleftbuttonssetsaspacebetweentheedge'oftheformandthebuttons.Therightbuttonsare'setbysubtractingthewidthofthebuttonfrom'thewidthoftheform,andsubtracting300to'setaspacebetweenthebuttonandtheformedge.cmdTopLeft.Left=200cmdBottomLeft.Left=200cmdTopRight.Left=frmMove.Width-cmdTopRight.Width-300cmdBottomRight.Left=frmMove.Width-cmdBottomRight.Width-300'SettheTopedgeofthebuttons.Thisisdone'similartosettingtheLeftedge.cmdTopLeft.Top=200cmdBottomLeft.Top=frmMove.Height-cmdBottomLeft.Height-500cmdTopRight.Top=200cmdBottomRight.Top=frmMove.Height-cmdBottomRight.Height-500'SetthesizeofthelabellblNotify.Height=360lblNotify.Width=3000VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:33/2603.3.33.3.33.3.33.3.3XoXoXoXoááááđềđềđềđềáááánnnntrongtrongtrongtrongnhnhnhnhóóóómmmmđềđềđềđềáááánnnn1.TrongcửasổProjectExplorer,chọnđềáncầnxoá2.Từmenufile,chọnREMOVEProjectTachỉdùngnhómđềánkhitạocácđiềukhiểnActiveX,vốnđòihỏinhiềuđềánmởcùngmộtlúc.VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:41/2605555NhNhNhNhậậậậppppmmmmôôôônnnnllllậậậậpppptrtrtrtrììììnhnhnhnhCácđiềukhiểntrênbiểumẫuchỉlàmộtphầnnhỏcủaquátrìnhlậptrìnhpháttriểnứngdụng,nhằmtạoragiaodiệnchoứngdụng.Sauđó,bạncầnviếtchươngtrìnhđểứngdụnghoạtđộng.Dođó,chươngnàysẽđisâuvàophầncôngviệcchínhcủaVisualBasic,viếtchươngtrình.VisualBasiclàngônngữlậptrìnhdựatrênđốitượng.Nếubạnlàngườimớihọc,chươngnàysẽgiớithiệucáckhốithiếtkếcơbảnđểxâydựngchươngtrình.Khiđãhiểuđượccáckháiniệmcơbản,bạncóthểtạoracácứngdụngrấtmạnhbằngVisual Basic. 5.15.15.15.1ChuChuChuChuẩẩẩẩnnnnllllậậậậpppptrtrtrtrììììnhnhnhnh(Coding(Coding(Coding(Codingconvention)convention)convention)convention)5.1.15.1.15.1.15.1.1CodingCodingCodingCodingconventionsconventionsconventionsconventionsObjectObjectObjectObjectNamingNamingNamingNamingConventionsConventionsConventionsConventionsObjectnamehas2parts:prefixanddescription.Theprefixthatmakesiteasytoidentifythetypeofobject,thedescriptionmentionsnameofobjects.-Conventionsofdescriptionpartare:+InEnglish.+Cancontainmanywords,eachwordiscontiguoustoothers(Nohyphen).+NoacronymexceptlistedintableAcronyms(see4.Acronym).+Capitalizethefirstletterofeachword.(Note:Theseconventionswillbeappliedtoallofnametypesmentionedafterinthisdocument)-PrefixconventionsforsomeoftheobjectssupportedbyVisualBasicarelistedbelow(Sortedbycontrolname):ControlControlControlControltypetypetypetypePrefixPrefixPrefixPrefixExampleExampleExampleExample3DPanelPnlpnlGroupADODataAdoadoBiblioAnimatedbuttonAnianiMailBoxCheckboxChkchkReadOnlyCombobox,drop-downlistboxCbocboEnglishCommandbuttonCmdcmdExitCommondialogdlgdlgFileOpenCommunicationscomcomFaxControl(usedwithinprocedureswhenthespecifictypeisunknown)ctrctrCurrentDatadatdatBiblioVisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:36/2604.1.1.44.1.1.44.1.1.44.1.1.4LLLLướướướưới(grid)i(grid)i(grid)i(grid)đđđđiiiiểểểểmmmmtrongtrongtrongtrongbibibibiểểểểuuuummmmẫẫẫẫuuuuĐểtạosựthuậntiệncholậptrìnhviênkhithiếtkếcácđiềukhiển,VisualBasichiểnthịbiểumẫuvớicáckhungkẻthẳnghàngbằngcácđiểmnhỏ.Tacóthểsửalạikíchcỡhoặclàloạibỏhẳncácônàybằngcách:từmenuTool,chọnOption,chontabGeneral4.1.1.54.1.1.54.1.1.54.1.1.5KhoKhoKhoKhoáááá(Lock)(Lock)(Lock)(Lock)đđđđiiiiềềềềuuuukhikhikhikhiểểểểnnnnĐểgiữcácđiềukhiểncốđịnhtạivịtrícủanó,tadùngtínhnăngLock.Lock.Lock.Lock.Chọnđiềukhiển,sauđó,từmenuFormat,chọnLockControlshoặclànhấnchuộtvàobiểutượngvàobiểutượngôkhoátrênFormEditor.Khiđó,takhôngthểdùngchuộtđểđiềuchỉnhkíchcỡđiềukhiển.Tuyvậy,tavẫncóthểdùngtổhợpphím.4.1.1.64.1.1.64.1.1.64.1.1.6ThuThuThuThuộộộộccccttttíííínhnhnhnhvvvvààààssssựựựựkikikikiệệệệnnnna.Thuộctính(Property):làbộcácthôngsốmàtacóthểgánchođiềukhiển,vídụnhưtên,chiềurộng,chiềucao, ... 26VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:9/2602222LLLLààààmmmmquenquenquenquenvvvvớớớớiiiivisual visual visualvisualbasic basic basic basic6 .06.06.06.02.12.12.12.1XXXXââââyyyyddddựựựựngngngngứứứứngngngngddddụụụụngngngngbanbanbanbanđầđầđầđầuuuu2.1.12.1.12.1.12.1.1ViViViViếếếếttttứứứứngngngngddddụụụụngngngngbanbanbanbanđầđầđầđầuuuuCáchtốtnhấtđểhọclậptrìnhlàviếtchươngtrình.Vậyhãythửviếtchươngtrìnhhiểnthịlịchbiểu,trongđóchophépngườisửdụng:•Hiểnthịlịchbiểucủathánghiệnhành•Duyệtquacáctháng•HiểnthịđồnghồbáogiờhiệnhànhNếubạnchorằngchươngtrìnhnàycóvẻnặngnềchongườimớihọc,đừnglolắng.Visualbasiclàmhếtmọiviệcchobạn.KhácvớingônngữC++,bạnphảiviếtmỗithứmộtít,Visualbasiccungcấpmứcđọcaohơncủalậptrìnhtựđộng.Nhưvậy,bạncóthểlàmnhiềuthứmàkhôngphảilậptrìnhnhiều.Tuynhiên,đừnghiểusai“khônglậptrìnhnhiều”nghĩalà“khôngcónhiềutínhnăngmạnh”Visualbasiclàmộtngônngữrấtmạnh.Tacóthểlậptrìnhđểlàm“mọithứ”nếucần.TacũngcóthểkhaitháckhảnăngtựđộngcủaVisualbasicđểviếtchươngtrìnhthậtnhanh.Chọnlựalàởngườilậptrình.Visualbasicđủlinhhoạtđểhỗtrợchongườilậptrìnhtừngườimớihọcđếnlậptrìnhchuyênnghiệp.2.1.22.1.22.1.22.1.2XXXXââââyyyyddddựựựựngngngngttttíííínhnhnhnhnnnnăăăăngngngngCalendarCalendarCalendarCalendarBâygiờtabắtđầuxâydựngcáctínhnăngcủaứngdụng.Đầutiên,tacầnmộtlịchbiểu.TacóthểtựtạonóhoặcsửdụnglịchbiểucósẵncủaVisualbasic(đâylàmộtđiềukhiểnActiveX).Tachọncáchthứ2.TừmenuProject,chọnComponents.Bởivì,mặcđịnhtấtcảcácđiềukhiểnActiveXcủaVisualbasickhôngđượcnạptựđộng.MuốndùngbạnphảichọntừmenuComponents.TronghộpthoạiComponentschọnWindowsCommonControls2.6.0vànhấnOK.VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:26/2603.HoặclàtừmenuProperties,chọnProjectNameProperties3.2.53.2.53.2.53.2.5LLLLưưưưuuuuvvvvààààđặđặđặđặttttttttêêêênnnnđềđềđềđềáááánnnn3.2.5.13.2.5.13.2.5.13.2.5.1LLLLưưưưuuuuđềđềđềđềáááánnnnKhilưuđềántừngtậptintrongđềánsẽđượclưutrướckếtiếplàtệptinđềán.Tronglầnlưuđềánđầutiên,VisualBasicđềnghịtênchotừngtệptin,thườngnólấytênbiểumẫuvàcóphầnmởrrộngtuỳthuộcvàoloạitệptin1.từmenufilechọnSaveProject2.nếuđâylàlầnđầulưuđềánhoặctavừathêmmộtbiểumẫuhoặcmodule,hộpthoạisaveFileasxuấthiệnlầnlượtchotừngtệptin3.2.5.23.2.5.23.2.5.23.2.5.2ĐổĐổĐổĐổiiiittttêêêênnnnTakhôngnhấtthiếtdùngtênmàVisualBasicđềnghị,màcóthểđặttuỳý.tuynhiênnêndặttênsaochogợinhớ1.Đưavàomộttênvàấnnútsave2.TậptincuốicùngđượclưulàtệptinđềánNếutađãđặttênchođềánthôngquahộpthoạiprojectproperties,VisualBasicsẽtựđộngđềnghịProject_Name.vbp.Lúcnày,tacóthểđổilạitênkháctuỳthích,vídụnhưSaveTest.vbp3.2.63.2.63.2.63.2.6MMMMởởởởđềđềđềđềáááánnnnccccóóóóssssẵẵẵẵnnnnTacómộtsốđềánđanglàmviệc.KhởiđộngVisualBasic,chọnmenuFile.Phầndướimenuliệtkêdanhsáchcácđềánmớinhấtmàtađãlàmviệc,chọnđềáncầnmở.nếuđềánkhôngxuấthiệntrongdanhsách,taphảichỉrađườngdẫn.3.2.6.13.2.6.13.2.6.13.2.6.1mmmmởởởởttttệệệệpppptintintintinvvvvààààoooollllúúúúcccckhkhkhkhởởởởiiiiđộđộđộđộngngngngVisual Visual VisualVisualBasic Basic Basic Basic LầnđầukhởiđộngVisualBasic,hộpthoạiNewprojectxuấthiện.tacóthểchọnmởđềánmớinhấthoặccósẵntrênđĩangaytừhộpthoạinày.nếukhôngmuốnhộpthoạinàyxuấthiệnmỗilầnkhởiđộngVisualBasic,xoáđánhdáutrênhộpđánhdấu(checkbox)nằmởbêndướihộpthoại.3.2.6.23.2.6.23.2.6.23.2.6.2MMMMởởởởđềđềđềđềáááánnnnccccóóóóssssẵẵẵẵnnnna.TừmenuFile,chọnOpenProject.b.trêntrangExisting,chuyểnđénthưmụcchứađềán.nếuđềáncầnmởlàđềánlưugầnnhất,chuyểnsangtrangRecentc.chọntêntệptinđềánvànhấnOKVisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:15/2602.3.82.3.82.3.82.3.8TrTrTrTrợợợợgigigigiúúúúppppKhôngnhữnglàmchủngônngữlậptrìnhVisualbasic,bạncũngcầnphảisửdụngthuầnthụcmôitrườngVisualbasiccũngnhưhiểucácthôngđiệpmàVisualbasicgửira.Microsoftcungcấpmộttrongnhữnghệthốngtrợgiúptốtnhấtchocáccôngcụpháttriểnứngdụng.TrTrTrTrợợợợgigigigiúúúúppppnhnhnhnhạạạạyyyyvvvvớớớớiiiingngngngữữữữccccảảảảnhnhnhnhTạimộtvịtríbấtkỳtrongVisualbasic,bạnnhấnphímF1,núttrợgiúp.NósẽkíchhoạthệthốngtrợgiúpcủaVisualbasic,nơicóthểgiảithíchhoặcđưaranhữnglờikhuyên,cũngnhưcácđoạnchươngtrìnhmẫu.VisualbasiccóhệthốngtrợgiúplàhệthôngthưviệnMSDNđượcsửdụngrộngrãichocáccôngcụpháttriểncủaMicrosoftđểcungcấptruycậpđếnsổtayhướngdẫnsửdụngsảnphẩmtrựctuyến.VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:21/260PrivateSubForm_Load()'SettheCaptionpropertyoftheCommandButtonscmdTopLeft.Caption="TopLeft"cmdTopRight.Caption="TopRight"cmdBottomLeft.Caption="BottomLeft"cmdBottomRight.Caption="BottomRight"'CleartheinitialtextofthelabellblNotify.Caption=""'Settheform'stitlebartextfrmMove.Caption="MoveIt"'Therestofthecodecenterstheformonthe'screen,setsthepositionofthefour'CommandButtons,andsetsthesizeand'positionofthelabel.'Centertheformonthescreen.Thisworksby'settingtheLeftsideoftheformtothecenter'ofthescreen,lesshalfthewidthoftheform.'Also,theTopoftheformissettothecenter'ofthescreen,lesshalftheheightoftheform.frmMove.Left=(Screen.Width-frmMove.Width)/2frmMove.Top=(Screen.Height-frmMove.Height)/2'SettheLeftedgeofthebuttons.The200setting'fortheleftbuttonssetsaspacebetweentheedge'oftheformandthebuttons.Therightbuttonsare'setbysubtractingthewidthofthebuttonfrom'thewidthoftheform,andsubtracting300to'setaspacebetweenthebuttonandtheformedge.cmdTopLeft.Left=200cmdBottomLeft.Left=200cmdTopRight.Left=frmMove.Width-cmdTopRight.Width-300cmdBottomRight.Left=frmMove.Width-cmdBottomRight.Width-300'SettheTopedgeofthebuttons.Thisisdone'similartosettingtheLeftedge.cmdTopLeft.Top=200cmdBottomLeft.Top=frmMove.Height-cmdBottomLeft.Height-500cmdTopRight.Top=200cmdBottomRight.Top=frmMove.Height-cmdBottomRight.Height-500'SetthesizeofthelabellblNotify.Height=360lblNotify.Width=3000VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:33/2603.3.33.3.33.3.33.3.3XoXoXoXoááááđềđềđềđềáááánnnntrongtrongtrongtrongnhnhnhnhóóóómmmmđềđềđềđềáááánnnn1.TrongcửasổProjectExplorer,chọnđềáncầnxoá2.Từmenufile,chọnREMOVEProjectTachỉdùngnhómđềánkhitạocácđiềukhiểnActiveX,vốnđòihỏinhiềuđềánmởcùngmộtlúc.VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:41/2605555NhNhNhNhậậậậppppmmmmôôôônnnnllllậậậậpppptrtrtrtrììììnhnhnhnhCácđiềukhiểntrênbiểumẫuchỉlàmộtphầnnhỏcủaquátrìnhlậptrìnhpháttriểnứngdụng,nhằmtạoragiaodiệnchoứngdụng.Sauđó,bạncầnviếtchươngtrìnhđểứngdụnghoạtđộng.Dođó,chươngnàysẽđisâuvàophầncôngviệcchínhcủaVisualBasic,viếtchươngtrình.VisualBasiclàngônngữlậptrìnhdựatrênđốitượng.Nếubạnlàngườimớihọc,chươngnàysẽgiớithiệucáckhốithiếtkếcơbảnđểxâydựngchươngtrình.Khiđãhiểuđượccáckháiniệmcơbản,bạncóthểtạoracácứngdụngrấtmạnhbằngVisual Basic. 5.15.15.15.1ChuChuChuChuẩẩẩẩnnnnllllậậậậpppptrtrtrtrììììnhnhnhnh(Coding(Coding(Coding(Codingconvention)convention)convention)convention)5.1.15.1.15.1.15.1.1CodingCodingCodingCodingconventionsconventionsconventionsconventionsObjectObjectObjectObjectNamingNamingNamingNamingConventionsConventionsConventionsConventionsObjectnamehas2parts:prefixanddescription.Theprefixthatmakesiteasytoidentifythetypeofobject,thedescriptionmentionsnameofobjects.-Conventionsofdescriptionpartare:+InEnglish.+Cancontainmanywords,eachwordiscontiguoustoothers(Nohyphen).+NoacronymexceptlistedintableAcronyms(see4.Acronym).+Capitalizethefirstletterofeachword.(Note:Theseconventionswillbeappliedtoallofnametypesmentionedafterinthisdocument)-PrefixconventionsforsomeoftheobjectssupportedbyVisualBasicarelistedbelow(Sortedbycontrolname):ControlControlControlControltypetypetypetypePrefixPrefixPrefixPrefixExampleExampleExampleExample3DPanelPnlpnlGroupADODataAdoadoBiblioAnimatedbuttonAnianiMailBoxCheckboxChkchkReadOnlyCombobox,drop-downlistboxCbocboEnglishCommandbuttonCmdcmdExitCommondialogdlgdlgFileOpenCommunicationscomcomFaxControl(usedwithinprocedureswhenthespecifictypeisunknown)ctrctrCurrentDatadatdatBiblioVisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:36/2604.1.1.44.1.1.44.1.1.44.1.1.4LLLLướướướưới(grid)i(grid)i(grid)i(grid)đđđđiiiiểểểểmmmmtrongtrongtrongtrongbibibibiểểểểuuuummmmẫẫẫẫuuuuĐểtạosựthuậntiệncholậptrìnhviênkhithiếtkếcácđiềukhiển,VisualBasichiểnthịbiểumẫuvớicáckhungkẻthẳnghàngbằngcácđiểmnhỏ.Tacóthểsửalạikíchcỡhoặclàloạibỏhẳncácônàybằngcách:từmenuTool,chọnOption,chontabGeneral4.1.1.54.1.1.54.1.1.54.1.1.5KhoKhoKhoKhoáááá(Lock)(Lock)(Lock)(Lock)đđđđiiiiềềềềuuuukhikhikhikhiểểểểnnnnĐểgiữcácđiềukhiểncốđịnhtạivịtrícủanó,tadùngtínhnăngLock.Lock.Lock.Lock.Chọnđiềukhiển,sauđó,từmenuFormat,chọnLockControlshoặclànhấnchuộtvàobiểutượngvàobiểutượngôkhoátrênFormEditor.Khiđó,takhôngthểdùngchuộtđểđiềuchỉnhkíchcỡđiềukhiển.Tuyvậy,tavẫncóthểdùngtổhợpphím.4.1.1.64.1.1.64.1.1.64.1.1.6ThuThuThuThuộộộộccccttttíííínhnhnhnhvvvvààààssssựựựựkikikikiệệệệnnnna.Thuộctính(Property):làbộcácthôngsốmàtacóthểgánchođiềukhiển,vídụnhưtên,chiềurộng,chiềucao, ... 52VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:20/2603.1.73.1.73.1.73.1.7ViViViViếếếếttttchchchchươươươươngngngngtrtrtrtrììììnhnhnhnhssssửửửửddddụụụụngngngngthuthuthuthuộộộộccccttttíííính,nh,nh,nh,phphphphươươươươngngngngththththứứứứccccvvvvààààssssựựựựkikikikiệệệệnnnnTathửviếtchươngtrìnhMoveltdùngđểdichuyểncửasổ.MoveltcómộtcửasổtênlàfrmMove,chứa4nútlệnhở4gócmànhình.khithihnàhnhấnvàomoọttrongcácnútnàysẽlàmcửasổdichuyểntớigócmànhìnhtươngứng.giữamànhìnhsẽlàmộtnhãnhiệusẽthôngbáotứcthờicácdichuyểncủachuộtcũngnhưnútlệnhnàođượcFocus.cácbướctổngquátdểtạoMovelt:a.Tạogiaodiệnngườisửdụng(GUI)b.ViếtthủtụcForm_Load()c.Viếtthủtụcclick()d.thêmcácthôngbáosựkiện3.1.7.13.1.7.13.1.7.13.1.7.1TTTTạạạạooooGUIGUIGUIGUI1.từmenuFile,chọnNewProjectđểmởhộpthoạiđềán.ChọnkiểustandardEXE2.vàocửasổProperties,sửatênbiểumẫuthànhfrmMove3.thêm4nútlệnhvào4gócbiểumẫu.tasẽxửalạivịtríchínhxáchiưnchođíngbằngchươngtrình4.nhấnđúpchuộtlênbiểmẫuđểtạothủtụcForm_Load()5.ĐổithuộctínhBorderStylecủabiểumẫuthành1-FixedSingleđểcấmbiểumẫucogiãnkhichươngtrìnhthihành.sauđóđổicácthuộctínhAlignmentcủanhãnthành2-CentervàBorderStylecủanhãnthành1-FixedSingle6.LưubiểumẫuvớitênlàfrmmovevàlưuđềánvớitênlàMovelt.vbp3.1.7.23.1.7.23.1.7.23.1.7.2ViViViViếếếếttttththththủủủủttttụụụụccccFormFormFormForm_Load_Load_Load_LoadThủtụcnàychuẩnbịmộtsốkhởitạochobiểumẫutrướckhinóđượchiểnthịa.ĐặtthuộctínhCaptionchoCommandButtionb.Dặtchuỗikýtựkhởitạochonhãnc.Đặtchuỗikýtựchothanhtiêuđềcủabiểumẫud.Đặtvịtrícho4nútlệnhnhãnvàbiểumẫutrênmànhìnhe.Đưavàođoạnchươngtrìnhsau:VisualBasic6.0TrịnhKhắcThanhhttp://www.minset.tkTrang:13/260Cácbiểumẫu(Form)-khốixâydựngcácchươngtrìnhVisualbasic-xuấthiệntrongcửasổform.Hộpcôngcụđểthêmcácđiềukhiểnvàocácbiểumẫucủađềán.Projectexplorerhiểnthịcácđềánmàbạnđanglàmcũngnhưcácthànhphầncủacácđềán.Bạnduyệtvàcàiđặtcácthuộctínhcủađiềukhiển,biểumẫuvàmoduletrongcửasổproperty.Cuốicùng,bạnbốtrívàxemxétmộthoặcnhiềubiểumẫutrênmànhìnhthôngquacửasổformlayout.2.3.22.3.22.3.22.3.2ThThThThêêêêmmmmvvvvààààxoxoxoxoááááccccááááccccthanhthanhthanhthanhccccôôôôngngngngccccụụụụtrongtrongtrongtrongIDEIDEIDEIDEccccủủủủaaaaVisual Visual VisualVisualbasic basic basic basic Thanhcôngcụlàtậphợpcácnútbấmmangbiểutượngchứatrongmộtthanhthườngđặtdướithanhmenu.CácnútnàyđảmnhậncácchứcnăngthôngdụngtrongcấutrúcmenucủaVisualbasic.Thanhcôngcụrấthửuích,thayvìphảilầnlượtchọnquamenuvàmenucon,tanhấnmộtnútbấmnàođótrongthanhcôngcụđểgọimộtchứcnăngtươngtựtrênmenu.SSSSửửửửddddụụụụngngngngthanhthanhthanhthanhccccôôôôngngngngccccụụụụdebug:debug:debug:debug:Thanhcôngcụdebugdùngđểkiểmtrachươngtrìnhvàgiảiquyếtcáclỗicóthểxảyra.Khigỡrốichươngtrình,talàmmộtsốviệcnhưchạytừngdònglệnhchươngtrình,kiểmtragiátrịcácbiến,vàdừngchươngtrìnhtạimộtđiểmnghingờhoặcdướinhữngđiềukiệnnàođó.SSSSửửửửddddụụụụngngngngthanhthanhthanhthanhccccôôôôngngngngccccụụụụEdit:Edit:Edit:Edit:ThanhcôngcụEditđượcdùngđểviếtchươngtrìnhtrongcửasổcode.CáctínhnăngcủathanhcôngcụEdittươngtựnhưcáctínhnăngkhácởmenuedit.BạncóthểCut,Pastevănbản...