Interac iunea cu utilizatorul prin InputBox, MsgBox
Loca ie: http://www.mvps.org/dmcritchie/excel/inputbox.htm Pagina de start: http://www.mvps.org/dmcritchie/excel/excel.htm !ezi "#r# $ame% Exemplu, folosind att InputBox i MsgBox Op iunea Sub explicit test01 () Dim o, rspuns Att timp ct lung a = Application.InputBox (_ Prompt: = !ntro"uce i #o$number, % &itle: = terge ro$number:, Tip: = 1) 'n ca(ul )n care un *+ ,alse Apoi rspuns = MsgBox ("Sigur.", vb!s"o) Dac rspunsul = -b.es Apoi rn"uri (a) /Delete 0n" !1 0n" Sub Poate un pic mai conven ie este &' sau (ancel de pe MsgBox #spunsul "im atta timp rspuns = 2sg3ox (prompt: = o4 sau anula, butoane: = -bo4cancel) )n ca(ul )n care rspunsul = -bo4 atunci /// MsgBox )prompte , butoane% , title% , help"ile, context%* Simplu MsgBox Exemplu (e) "i e de lucru )+* , pentru prima "oaie "oi de lucru )-.heet+-* , pentru "oaie cu numele vb/es(ancel , poate "i utilizat 0n locul Sub sta5%O#%S6eet1 () 2sg3ox 7u -rei s mergi S6eet1, -b.es7o Pe "e eroare 89 :rmatorul Dac -b.es Apoi, 1i e "e lucru (s6eet;)/ Acti-ea(a Dac 0rr/7umber = < Apoi 2sg3ox 7e pare rau, "ar nu s6eet; ie iri mai lungi, a a stau aici, oricum S1r it Pe 0rror =o&o 0 O"i6n #em "e co" 0n" Sub Mai explicit Exemplu pentru InputBox (#explicit) InputBox v# permite s# seta i o valoare implicit#, i de a plasa un titlu 0n caseta de dialog, precum i prompt. 1u pre"er s# speci"ica i "iecare din aceste lucruri. !ezi 21LP pentru in"orma ii speci"ice parametru: expresie. InputBox (Prompt, titlul, implicit, Left, Top, HelpFile, HelpContextId, tip) 3vertisment urm#torul exemplu implicite la tergerea toate r4ndurile, 0n intervalul ini ial de selec ie, 0n cazul 0n care este selectat# o singur# celul# care ar "i r4ndul (1L activ. &est01 Sub () Dim un 8a -ariant, rspuns 8a 9ariant a = Selection (1) /ro$ > : > Selection (1) /Special8ells (xl?ast8ell) /ro$ a = Application.InputBox (_ !ntro"uce i inter-alul #o$number trebuie s 1ie eliminat, % Delete ro$number:, un,,,, #) @ pentru o gam 2sg3ox 9ar&5pe (a) @ = string, 11 = 3oolean Dac o *+ ,alse &6en utili(a i ,als "ac o este "e1init ca un numr rspuns = 2sg3ox (Sigur, -rei nu terge i rn" i un, -b.es7o) Dac rspunsul = -b.es Apoi rn"uri (a) /Delete 0n" Dac 0n" Sub Seriei multiple de selec ie n InputBox (#multi) Sub !nput3ox%2ulti#ange () Dim -ar#ange 8a #ange, )n sub(ona 8a #ange, AreasStr 8a String AB Cona "e selec ie ini ial (e) -a 1i utili(at ca sugestie Pe "e eroare 89 :rmatorul Set -ar#ange = % Application.InputBox (Alegeti game unice sau multiple:, % &est multirange, S!l!ction.A$$r!ss (%, %), Tip: = #) Pe 0rror =o&o 0 Dac -ar#ange este nimic Apoi 0xit Sub Pentru 1iecare sub#ange 'n -ar#ange/Areas AreasStr = AreasStr > 86r (10) > sub#ange/#o$s/8ount % > ran"uri si sub#ange/A""ress (0, 0) Sub#ange :rmatorul MsgBox Domenii: > -ar#ange/Areas/8ount > , > % rn"uri: > -ar#ange/#o$s/8ount > AreasStr 0n" Sub 5ohn 6al7enbach are un exemplu, 1xcel 8eveloper ."at: (opierea o selectie multipla )9ip :;* , care ob ine o gam# multipl# "#r# InputBox, cu un MsgBox va cere sa selectati interval )e*, i apoi "ace o past# interval multiplu, care nu este disponibil 0n 1xcel. op!p sau Box de a"erti#are, de scurt durat (#popup) 5im $ech postat cod ) <===,=>,<= * pentru a pune o cutie de avertizare de p4n# timp de dou# secunde i apoi dispar. !# mul umim pentru 8ave Peterson pentru a men iona acest lucru 0n grupuri de tiri Sel18losing2sg3ox Sub () 8reateObDect (EScript/S6ell)/ Popup 3un (iua, % F, Acest lucru se )nc6i"e )n F secun"e 0n" Sub arametrii pentru InputBox i apoi pentru MsgBox (#parameters) arametru de tip pentru InputBox (#t$pe) expresie. InputBox (prompt %, title& %, implicit& %, xos& %, $os& %, 'elpfile, tip&) parametru op ional xPos de la st4nga la punctele parametru ?Pos op ional de top din In"orma iile tip de a@utor 9ip &p ional !ariant. .peci"ic# tipul de date de punctele (aloarea )eea ce nseamn pentru 9ip = & "ormul# + An num#r < 9ext )un ir* , implicit B & valoare logic# (ade"rat sau fals) C & celul# de re"erin #, ca obiect *ange +; & valoare de eroare, cum ar "i D E / 3 ;B & serie de valori 0ntoarcere. 8ac# acest argument este omis, caseta de dialog se 0ntoarce de text. Pot "i unul sau o sum# a valorilor de tip. Pute i utiliza suma valorilor admisibile pentru Type. 8e exemplu, pentru o cutie de intrare care poate accepta text i numere, seta i Type la + F <. arametru Buton pentru MsgBox (#msg+ox) MsgBox (prompte %, +utoane& %, title& %, 'elpfile, context&) )onstant de Butoane (aloareaButon ,escriere (s) "+-.-nl$ = 3"i eaz# doar butonul &'. "+-.)ancel + 3"i area &' i (ancel butoane. "+/+ort*etr$Ignore < 3"i area 3bort, $etr?, i Ignore butoane. "+0es1o)ancel : 3"i area 8a, Eu, i anula butoane. "+0es1o B 3"i area 8a i nu butoane. "+*etr$)ancel G 3"i area $etr? i (ancel butoane. "+)ritical +; 3"i eaz# pictograma Mesa@ critic. "+2uestion :< 3"i a@ 3ten ie icon Huer?. "+Exclamation BC 3"i are avertizare icon mesa@. "+Information ;B 8ispla?,ul de in"ormare mesa@. "+,efaultButton3 = Primul buton este implicit. "+,efaultButton4 <G; 3l doilea buton este implicit. "+,efaultButton5 G+< Buton al treilea r4nd este implicit. "+,efaultButton6 I;C Buton al patrulea este implicit. "+/pplicationModal = Modal de aplicareJ utilizatorul trebuie s# r#spund# la caseta de mesa@ 0nainte de a continua munca 0n aplica ia curent#. "+S$stemModal B=>; Modal sistemJ toate aplica iile sunt suspendate p4n# c4nd utilizatorul r#spunde la caseta de mesa@. "+MsgBox7elpButton +;:CB 3daug# butonul de a@utor la caseta de mesa@e (+MsgBoxSet8oreground ;GG:; .peci"ic# "ereastra de caset# de mesa@ ca "ereastra de prim,plan "+MsgBox*ig't G<B<CC 3cest text este aliniat la dreapta "+MsgBox*tl*eading +=BCGI; .peci"ic# textul ar trebui s# apar# ca de la dreapta la st4nga de lectur# pe sistemele de ebraic# i arab# (arT$pe )onstante (#"art$pe) dim o ca variant# a K -abc- MsgBox vart?pe )a* , s,ar a"i a C pentru string Arm#toarele constante pot "i utilizate oriunde 0n cod 0n loc de valorile actuale: Constant Valoarea Descriere vbEmpty 0 Neinitializata (implicit) vbNull 1 Nu con ine date valide vbInteger 2 Integer vbLong 3 ntreg lung vbSingle 4 Single-precizie numr n virgul moil vbDouble ! "ulu-precizie numr n virgul moil vbCurrency # $oneda vbDate % "ata vbString & String vbObject ' (iect vbError 10 )roare vbBoolean 11 *oolean vbVariant 12 +arianta (utilizat doar pentru talouri de variante) vbDataObject 13 (iect de acce, la date vbDecimal 14 -ecimal vbByte 1% *.te vbUserDefinedype 3# +ariante care con in tipuri de/inite de utilizator vb!rray &1'2 0rra. TextBox An macro eveniment care va schimba toate casetele de text de pe "oaia de lucru pentru capace de selectare a "oii de lucru. )instala cu dreapta pe "ila "oaie, vizualiza cod, ...* Sub Pri-ate Eor4s6eet%Acti-ate () Sc6imba toate textboxes pe pagina "e capace ?a acti-are 1oaie "e lucru/ D2c# F00;B0GB1H A se -e"ea, "e asemenea, 4bi" = &box Dim 8a T!xtBox Pentru 1iecare tbox 'n Activ!S&!!t.T!xtBox!s tbox/&ext = :8AS0 (tbox/&ext) &box :rmatorul 0n" Sub InputBox, MsgBox and TextBox Interaction with user via InputBox, MsgBox Location: http://www.mvps.org/dmcritchie/excel/inputbox.htm 2ome page: http://www.mvps.org/dmcritchie/excel/excel.htm !iew without Lrames% Example using +ot' InputBox and MsgBox Option 0xplicit Sub test01() Dim a As ?ong, response As ?ong a = Application.InputBox( % Prompt:=0nter t6e #o$number, % &itle:=Delete ro$number:, T'p!:=1) !1 a *+ ,alse &6en response = MsgBox( Are 5ou sure/, -b.es7o ) !1 response = -b.es &6en #o$s(a)/Delete 0n" !1 0n" Sub Perhaps a little more convention is &7 or (ancel on the MsgBox "im response as long response = msgbox(prompt:=o4 or cancel,buttons:=-bo4cancel) i1 response = -bo4 t6en /// MsgBox)prompt, buttons% , title% , help"ile, context%* Simple MsgBox Example(s) wor7sheets)+* M "or "irst sheet wor7sheets)-sheet+-* N "or named sheet vb/es(ancel N might be used instead Sub sta5%O#%S6eet1() 2sg3ox Do 5ou $ant to go s6eet1, -b.es7o On 0rror #esume 7ext !1 -b.es &6en Eor4s6eets(s6eet;)/Acti-ate !1 0rr/7umber = < &6en 2sg3ox Sorr5 but s6eet; no longer exits, so sta5ing 6ere an5$a5 0n" On 0rror =o&o 0 #em rest o1 co"e 0n" Sub More Explicit Example for InputBox (#explicit) InputBox allows ?ou to set a de"ault, and to place a title on the dialog, as well as the prompt. I pre"er to speci"? each o" those things. .ee 21LP "or speci"ic parameter in"ormation: expression. InputBox( Prompt, Title, Default, Left, Top, HelpFile, HelpContextId, Type ) 6arning the "ollowing example de"aults to deleting all rows in the initial selection range, i" onl? one cell is selected that would the row o" the active cel. Sub test01() Dim a As 9ariant, response As 9ariant a = Selection(1)/ro$ > : > Selection(1)/Special8ells(xl?ast8ell)/ro$ a = Application.InputBox( % 0nter t6e #o$number range to be "elete", % Delete ro$number:, a, , , , @ ) A@ 1or a range A2sg3ox 9ar&5pe(a) A@=string, 11=3oolean !1 a *+ ,alse &6en A use ,alse i1 a is "e1ine" as a number response = 2sg3ox(Are 5ou sure, 5ou $ant "o "elete ro$ > a, -b.es7o) !1 response = -b.es &6en #o$s(a)/Delete 0n" !1 0n" Sub Multiple *ange Selection in InputBox (#multi) Sub !nput3ox%2ulti#ange() Dim -ar#ange As #ange, subArea As #ange, AreasStr As String ABB initial selection area(s) $ill be use" as suggestion On 0rror #esume 7ext Set -ar#ange = % Application.InputBox (Select single or multiple ranges:, % 2ulti#ange test, S!l!ction.A$$r!ss(%, %) , T'p!:=#) On 0rror =o&o 0 !1 -ar#ange !s 7ot6ing &6en 0xit Sub ,or 0ac6 sub#ange !n -ar#ange/Areas AreasStr = AreasStr > 86r(10) > sub#ange/#o$s/8ount % > ro$s in > sub#ange/A""ress(0, 0) 7ext sub#ange MsgBox Areas: > -ar#ange/Areas/8ount > , > % ro$s: > -ar#ange/#o$s/8ount > AreasStr 0n" Sub 5ohn 6al7enbach has an example, 1xcel 8eveloper 9ip: (op?ing a Multiple .election )9ip :;* , that obtains a multiple range without the inputbox, with a msgbox as7ing ?ou to select range)s*, and then does a multiple range paste that is not available in 1xcel. op!p or 9arning Box, s'ort duration (#popup) 5im $ech posted code ) <===,=>,<= * to put a warning box up "or two seconds and then disappear. 9han7s to 8ave Peterson "or mentioning this in newsgroups Sub Sel18losing2sg3ox() 8reateObDect(EScript/S6ell)/Popup Iello, % F, &6is closes itsel1 in F secon"s 0n" Sub arameters for InputBox and t'en for MsgBox (#parameters) T$pe parameter for InputBox (#t$pe) expression. InputBox(prompt%, title& %, default& %, xos& %, $os& %, 'elpfile, t$pe&) xPos optional parameter "rom Le"t in points ?Pos optional parameter "rom 9op in points (alue Meaning "or 9?pe = 3 "ormula + 3 number < 9ext )a string* ,, de"ault B 3 logical value ) True or 8alse * C 3 cell re"erence, as a *ange ob@ect +; 3n error value, such as DE/3 ;B 3n arra? o" values 9he t?pe in"ormation "rom 21LP 9?pe &ptional !ariant. .peci"ies the return data t?pe. I" this argument is omitted, the dialog box returns text. (an be one or a sum o" the t?pe values. /ou can use the sum o" the allowable values "or Type . Lor example, "or an input box that can accept both text and numbers, set Type to + F <. Button parameter for MsgBox (#msg+ox) MsgBox(prompt%, +uttons& %, title& %, 'elpfile, context&) )onstant for Buttons (alue Button ,escription(s) "+-.-nl$ = 8ispla? &' button onl?. "+-.)ancel + 8ispla? &' and (ancel buttons. "+/+ort*etr$Ignore < 8ispla? 3bort, $etr?, and Ignore buttons. "+0es1o)ancel : 8ispla? /es, Eo, and (ancel buttons. "+0es1o B 8ispla? /es and Eo buttons. "+*etr$)ancel G 8ispla? $etr? and (ancel buttons. "+)ritical +; 8ispla? (ritical Message icon. "+2uestion :< 8ispla? 6arning Huer? icon. "+Exclamation BC 8ispla? 6arning Message icon. "+Information ;B 8ispla? In"ormation Message icon. "+,efaultButton3 = Lirst button is de"ault. "+,efaultButton4 <G; .econd button is de"ault. "+,efaultButton5 G+< 9hird button is de"ault. "+,efaultButton6 I;C Lourth button is de"ault. "+/pplicationModal = 3pplication modalJ the user must respond to the message box be"ore continuing wor7 in the current application. "+S$stemModal B=>; .?stem modalJ all applications are suspended until the user responds to the message box. "+MsgBox7elpButton +;:CB 3dds 2elp button to the message box (+MsgBoxSet8oreground ;GG:; .peci"ies the message box window as the "oreground window "+MsgBox*ig't G<B<CC 9ext is right aligned "+MsgBox*tl*eading +=BCGI; .peci"ies text should appear as right,to,le"t reading on 2ebrew and 3rabic s?stems (arT$pe )onstants (#"art$pe) dim a as variant a K -abc- msgbox vart?pe)a* ,, would displa? C "or string 9he "ollowing constants can be used an?where in ?our code in place o" the actual values: Constant Value Description vbEmpty 0 1ninitialized (de/ault) vbNull 1 2ontain, no valid data vbInteger 2 Integer vbLong 3 3ong integer vbSingle 4 Single-preci,ion /loating-point numer vbDouble ! "oule-preci,ion /loating-point numer vbCurrency # 2urrenc. vbDate % "ate vbString & String vbObject ' (4ect vbError 10 )rror vbBoolean 11 *oolean vbVariant 12 +ariant (u,ed onl. /or arra., o/ variant,) vbDataObject 13 "ata acce,, o4ect vbDecimal 14 "ecimal vbByte 1% *.te vbUserDefinedype 3# +ariant, t5at contain u,er-de/ined t.pe, vb!rray &1'2 0rra. TextBox 3n 1vent macro that will change all text boxes on the wor7sheet to caps upon selection o" the wor7sheet. )install with right on sheet tab, view code, ...* Pri-ate Sub Eor4s6eet%Acti-ate() A c6ange all textboxes on t6e page to caps A upon $or4s6eet acti-ation/ D2c# F00;B0GB1H A also see 4bi"= Dim tbox As T!xtBox ,or 0ac6 tbox !n Activ!S&!!t.T!xtBox!s tbox/&ext = :8ase(tbox/&ext) 7ext tbox 0n" Sub 7bidK+G<:I> , 2ow to (op? the 9ext 6ithin a 9ext Box to a (ell, http://support.microso"t.com/O7bidK+G<:I> ) ?ou can Poogle 7bidK+G<:I>* )um se copia# textul intr:un Text Box pentru o celul Print 1,mail I8 articol: +G<:I> , !izualiza i produsele pentru care se aplic# acest articol. Pensionari 'B de con inut 8isclaimer 3cest articol a "ost publicat anterior sub H+G<:I> M#ri i totul Q $educe i totul ;n aceast pagin *E<!M/T 3cest articol con ine o !isual Basic prob# Microso"t pentru aplica ii macro )procedur# .ub* care copiaz# textul 0ntr,o caset# de text i paste,l 0ntr,o "oaie de calcul. 8up# urm4nd pa ii prezenta i 0n acest articol, ar trebui s# vede i textul apare 0n di"erite celule din coloana 3, 0ncep4nd cu celula 3+. Liecare celul# separat# va con ine textul de o caseta de text. E&9R: Sn Microso"t 1xcel I.= i mai devreme, 0n cazul 0n care o caset# de text con ine mai mult de <GG de caractere, date numerice va ap#rea 0n nota ie tiin i"ic#. Sn cazul 0n care datele 0n caseta de text este al"anumeric, celula va organiza numai primele <GG de caractere de date. Microso"t 1xcel >I i Microso"t 1xcel >C poate de ine un maxim de :<.=== de caractere per celul#. Snapoi la 0nceput Q 9rimite i "eedbac7 M/I M!=TE I18-*M/TII Microso"t "urnizeaz# exemple de programare pentru ilustrare numai, "#r# garan ie, "ie explicite sau implicite. 3ceasta include, dar nu se limiteaz# la, garan iile implicite de vandabilitate sau potrivire pentru un anumit scop. 3cest articol presupune c# sunte i "amiliarizat cu limba@ul de programare care este "iind demonstrat i cu instrumente care sunt utilizate pentru a crea i a depana proceduri. .peciali tii 0n asisten # Microso"t pot a@uta la explicarea "unc ionalit# ii unei anumite proceduri, dar ei nu va modi"ica aceste exemple pentru a o"eri "unc ionalitatea ad#ugat# sau construi procedurile pentru a 0ndeplini cerin ele dumneavoastr# speci"ice. Pentru a crea o caset# de text 0n Microso"t 1xcel, urma i ace ti pa i: +. Sntr,o nou# "oaie de lucru, punct spre Bare de instrumente din meniul !izualizare, apoi "ace i clic pe 8esen. Lace i clic pe &'. <. Pe bara de instrumente 8esen, "ace i clic pe butonul 9ext Box. :. Pozi iona i punctul de inserare 0n "oaia de calcul 0n cazul 0n care dori i s# apar# caseta de text, i 0n timp ce ine i ap#sat butonul st4ng al mouse,ului, glisa i indicatorul spre dreapta pentru a trage caseta de text. B. Lace i clic 0n caseta de text, i introduce i un text. G. $epeta i pa ii +,B de mai multe ori pentru a crea mai multe casete de text. (isual e antion procedura de +a# Snainte de a lucra cu mostre de cod, e"ectua i urm#torii pa i: 1/ 8eschide i un nou registru de lucru. F/ Sn Microso"t 1xcel >I sau Microso"t 1xcel >C, punct de Macro din meniul Instrumente, apoi "ace i clic pe 1ditor !isual Basic. Sn !isual Basic 1ditor, "ace i clic pe Module din meniul Insert. ,sau, Sn Microso"t 1xcel G.= i I.=, punctul de la Macro din meniul Inserare, apoi "ace i clic pe Module. J/ Introduceti codul macro prob# 0n "oaia modul: ;/ Sub 2ain () H/ ,oi (S6eet1)/ Selecta i K/ Atribuirea o -aloare ini ial rn" la g6i eu/ G/ x = 1 @/ 3ucla prin 1iecare caset "e text )n acti-es6eet/ </ Pentru 1iecare tbox )n Acti-eS6eet/&ext3oxes 10/ Selecta i rn"ul urmtor )n Dos i plasa i textul acolo/ 11/ #ange (o i x) = /-alue tbox/&ext 1F/ !ncrement contra 1J/ x = x L 1 1;/ &box :rmatorul End Sub 7o> to )op$ t'e Text 9it'in a Text Box to a )ell Print 1mail 3rticle I8: +G<:I> , !iew products that this article applies to. $etired 'B (ontent 8isclaimer 9his article was previousl? published under H+G<:I> 1xpand all Q (ollapse all -n T'is age S!MM/*0 9his article contains a sample Microso"t !isual Basic "or 3pplications macro ).ub procedure* that copies the text within a text box and pastes it into a spreadsheet. 3"ter "ollowing the steps outlined in this article, ?ou should see the text appear in the various cells in column 3, starting with cell 3+. 1ach separate cell will contain the text o" one text box. E&91: In Microso"t 1xcel I.= and earlier, i" a text box contains more than <GG characters, numeric data will appear in scienti"ic notation. I" the data in the text box is alphanumeric, the cell will onl? hold the "irst <GG characters o" data. Microso"t 1xcel >I and Microso"t 1xcel >C can hold a maximum o" :<,=== characters per cell. Bac7 to the top Q Pive Leedbac7 M-*E I18-*M/TI-1 Microso"t provides programming examples "or illustration onl?, without warrant? either expressed or implied. 9his includes, but is not limited to, the implied warranties o" merchantabilit? or "itness "or a particular purpose. 9his article assumes that ?ou are "amiliar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microso"t support engineers can help explain the "unctionalit? o" a particular procedure, but the? will not modi"? these examples to provide added "unctionalit? or construct procedures to meet ?our speci"ic reTuirements. 9o create a text box in Microso"t 1xcel, "ollow these steps: +. In a new wor7sheet, point to 9oolbars on the !iew menu, and then clic7 8rawing. (lic7 &'. <. &n the 8rawing toolbar, clic7 the 9ext Box button. :. Position the insertion point on the spreadsheet where ?ou want the text box to appear, and while holding down the le"t mouse button, drag the pointer to the right to draw the text box. B. (lic7 in the text box, and t?pe some text. G. $epeat steps +,B several times to create multiple text boxes. Sample (isual Basic rocedure Be"ore wor7ing with the sample code, per"orm the "ollowing steps: 1/ &pen a new wor7boo7. F/ In Microso"t 1xcel >I or Microso"t 1xcel >C, point to Macro on the 9ools menu, and then clic7 !isual Basic 1ditor. In the !isual Basic 1ditor, clic7 Module on the Insert menu. ,or, In Microso"t 1xcel G.= and I.=, point to Macro on the Insert menu, and then clic7 Module. J/ 9?pe the sample macro code into the module sheet: ;/ Sub 2ain() H/ S6eets(S6eet1)/Select K/ A Assign t6e counter an initial ro$ -alue/ G/ x = 1 @/ A ?oop t6roug6 eac6 text box in t6e acti-es6eet/ </ ,or 0ac6 tbox in Acti-eS6eet/&ext3oxes 10/ A Select t6e next ro$ "o$n an" place t6e text t6ere/ 11/ #ange(a > x)/9alue = tbox/&ext 1F/ A !ncrement t6e counter 1J/ x = x L 1 1;/ 7ext tbox 1nd .ub )um s )op$ ? aste un Text Box Prin Laurie $appeport, e2ow (ontributor Parta@are 9weet Parta@are Pin (asete de text social, prin copierea i lipirea lor de la un document la altul. Persoanele care lucreaz# cu programe so"tware de birou s,ar putea g#si c# este util de a organiza in"orma iile 0n casete de text. Sn "unc ie de document, casete de text permite creatorul documentului pentru a aran@a textul i datele 0n sec iuni citite u or. (4nd schimbul de in"orma ii de la aceste casete de text dintre documente Microso"t &""ice, sau 0ntre programe so"tware Microso"t &""ice, creatorul de documente s,ar putea dori pentru a trans"era in"orma iile de copierea 0ntregului caseta de text de la un document la altul. Instrumentul de copiere i lipire "ace acest lucru posibil. 2ave a TuestionO Pet an answer "rom online tech support nowU /lte persoane sunt citind (um sa "aci un (op? V Paste Box (um sa "aci o caset# text 0n Microso"t 6ord Instruc iuni +. o + 8u,te la punctul dumneavoastr# de vedere aspect de imprimare. Lace i clic pe -!iew- din bara de instrumente, i apoi -La?out Print- din meniul drop,down. Sn unele versiuni ale Microso"t &""ice, nu va "i nevoie s# deschide i mai 0nt4i documentul ca un -La?out Print.- o < .t4nga,clic pe oricare dintre "rontierele exterioare ale casetei de text. Puncte mici vor ap#rea 0n col urile casetei de text i 0n mi@locul "rontierelor caseta de text de. o o : Lace i clic dreapta pe oricare dintre punctele. o B Lace i clic pe bara de instrumente i "ace i clic pe -1dit-, apoi -(op?- din meniul drop,down. o G 8eschide i noul document i plasa i cursorul pe punctul 0n care dori i s# introduce i caseta de text copiat. o ; Lace i clic pe -1dit- din bara de instrumente i "ace i clic pe -Paste- din meniul drop,down. (aseta de text se va lipi 0n noul document. $ead more : http://translate.googleusercontent.com/translateWcOdepthK+VhlKroVprevK/search X:LTX:82owX<BtoX<B(op?X<BtheX<B9extX<B6ithinX<BaX<B9extX<BBoxX<Bto X<BaX<B(ellX<BPrintX<BPrintX<B1mailX<B1mailX<;hlX:8roX<;biw X:8>B;X<;bih X:8;+=VrurlKtranslate.google.comVslKenVuKhttp://www.ehow.com/howWIB;GII:Wcop?, paste,text,box.htmlVusgK3L75rh@;vonBB<!bP1en"tgWaeEP?iY5n3 Lectia 10: Introducere la VB built-in functii O func ie este similar cu o procedur normal, dar scopul principal al func iei este de a accepta un anumit input de la utilizator i returneaz o valoare care este trecut pe la programul principal pentru a termina executia. Exist dou tipuri de func ii, func iile built- in (sau func ii interne) i func iile create de programatori. Formatul general al unei func ii este Functionname (argumente) Argumentele sunt valori care sunt transmise la func ia. n aceast lec ie, vom !nv a dou func ii interne de baz "isual foarte de baz, dar utile, adic MsgBox () i InputBox func ii () 10!1 MsgBox () Func ia Obiectivul de #sg$ox este de a produce un mesa% caset de tip pop-up i cere utilizatorului s face i clic pe un buton de comand, !nainte de el & ea poate continua. Acest format este urmtoarea' "ourMsg # MsgBox ($rompt! %aloarea &t"le! titlu) (rimul argument, (rompt, se va afi a mesa%ul !n caseta de mesa%. "aloarea )t*le va determina ce tip de butoane de comand apare pe caseta de mesa%, v rugm s consulta i tabelul +,.+ pentru tipuri de buton de comand afi ate. Argumentul titlu va afi a titlul message board. 'abelul 101: Valori &t"le Valoarea &t"le (umit )onstant Butoanele afi ate , vbO-Onl* $utonul O. + vbO-/ancel O- si /ancel butoanele 0 vbAbort1etr*2gnore Abandona, 1e!ncerca i i 2gnore butoane. 3 vb4es5o/ancel 6a, nu i anula butoane 7 vb4es5o 6a i nu butoane 8 vb1etr*/ancel ncerca i din nou i anula butoane
(utem folosi numele de constant !n loc de numere !ntregi pentru al doilea argument pentru a face programele mai usor de citit. 6e fapt, "$9 va afi eaz automat o list de nume constante de unde pute i selecta una dintre ele. Exemplu' *our#sg : #sg$ox (;Apsa i O. pentru a continua;, +, ;)tartup #enu;) i *our#sg : #sg (;Apsa i O. pentru a continua;. vbO-/ancel, ;)tartup #enu;) sunt acelea i. *our#sg este o variabil care de ine valori, care sunt returnate de func ia #sg$ox (). "alorile sunt determinate de tipul de butoane a fi apasat de ctre utilizatori. Ea trebuie s fie declarat ca 2nteger tip de date !n cadrul procedurii sau !n declara ia general sec iune. 'abelul 10* prezint valorile, corespunztoare a numit-constant i butoane. 'abelul 10*: Valorile +ntoarse i butoane de comand, Valoarea (umit )onstant Button f,cut clic + vbO- $utonul O. 0 vb/ancel Anulare 3 vbAbort $uton Abandona i 7 vb1etr* $uton 1e!ncerca i 8 vb2gnore $uton 2gnora i 9 vb4es 6a buton < vb5o 5u buton -xemplu 10!1 i. 2nterfa a' (ute i trage trei butoane de comand i o etic=et a a cum se arat !n figura +,.+ Figura 101 ii. (rocedura pentru butonul de testare' )ub (rivate >est?/lic- () 6im testmsg /a 2nteger testmsg : #sg$ox (;/lic- pentru a testa;, + ;, mesa%ul de testare;) 6ac testmsg : + Apoi 6ispla*./aption : ;>estarea de succes; Altele 6ispla*./aption : ;>estarea nu; End 6ac End )ub Atunci c@nd un utilizator face clic- pe butonul de test, va aprea imaginea ca cel prezentat !n figura +,.0. /a utilizator, face i clic pe butonul O., mesa%ul ;>estarea de succes; va fi afi at i atunci c@nd el & ea face clic pe butonul /ancel, mesa%ul ;>estarea nu; va fi afi at. Figura 10* (entru a face caseta de mesa% pare mai sofisticat, pute i aduga o pictogram !n afar de mesa%ul. Exist patru tipuri de pictograme disponibile !n "$ a a cum se arat !n >abelul +,.3 'abelul 10. Valoarea (umit )onstant Icon +9 vb/ritical 30 vbAuestion 7B vbExclamation 97 vb2nformation -xemplu 10!* >u trage aceea i interfa ca !n exemplul +,.+, dar modifica codurile dup cum urmeaz' )ub (rivate test0?/lic- () 6im test#sg0 /a 2nteger test#sg0 : #sg$ox (;/lic- pentru a testa;, vb4es5o/ancel C vbExclamation, ;#esa% de testare;) 6ac test#sg0 : 9 Apoi displa*0./aption : ;>estarea de succes; Elseif test#sg0 : < Apoi, displa*0./aption : ;E ti sigurD; Altele displa*0./aption : ;>estarea nu; End 6ac End )ub n acest exemplu, urmtoarea caseta de mesa% va fi afi at' Figura 10. 10!* InputBox () Func ia O func ie 2nput$ox () se va afi a o caset de mesa% !n care utilizatorul poate introduce o valoare sau un mesa% !n form de text. Formatul este m"Message # InputBox ($rompt! titlul! default/text! de po0i ie x! "- po0i ie) m*#essage este un tip de date variant, dar de obicei este declarat ca ir de caractere, care accept intrarea mesa% de ctre utilizatori. Argumentele sunt explicate dup cum urmeaz' ii. (rocedura de butonul O. )ub (rivate O.?/lic- () 6im ca ir de user#sg user#sg : 2nput$ox (;/are este mesa%ulD;, ;#esa% Formularul de !nscriere;, ;Enter messge dumneavoastr aici;, 8,,, <,,) 6ac user#sg EF ;; Atunci, message./aption : user#sg Altele message./aption : ;5ici un mesa%; End 6ac (rompt - mesa%ul afi at !n mod normal ca o !ntrebare. >itlul - >itlul caseta de intrare. default text - textul implicit care apare !n c@mpul de introducere, unde utilizatorii pot folosi ca intrare sau inten ionat sau poate modifica la mesa%ul pe care dori i s introduce i. x-pozi ie i *-pozi ie - pozi ia sau coordonatele caseta de intrare. -xemplu 10!. i. 2nterfa a Figura 101 End )ub Atunci c@nd un utilizator face i clic pe butonul O., va aprea caseta de intrare a a cum se arat !n figura +,.8. 6upa utilizator introdus mesa%ul i face i clic pe O., mesa%ul va fi afi at pe legend, !n cazul !n care el face i clic pe 1evocare, va fi afi at ;5ici un mesa%;. Lesson 10: Introduction to VB Built-in Functions A function is similar to a normal procedure but t=e main purpose of t=e function is to accept a certain input from t=e user and return a value G=ic= is passed on to t=e main program to finis= t=e execution. >=ere are tGo t*pes of functions, t=e built-in functions (or internal functions) and t=e functions created b* t=e programmers. >=e general format of a function is Function(ame (arguments) >=e arguments are values t=at are passed on to t=e function. 2n t=is lesson, Ge are going to learn tGo ver* basic but useful internal functions of "isual basic , ie t=e MsgBox( ) and InputBox ( ) functions. 101 MsgBox ( ) Function >=e ob%ective of #sg$ox is to produce a pop-up message box and prompt t=e user to clic- on a command button before =e &s=e can continues. >=is format is as folloGs' "ourMsg#MsgBox($rompt! &t"le Value! 'itle) >=e first argument, (rompt, Gill displa* t=e message in t=e message box. >=e )t*le "alue Gill determine G=at t*pe of command buttons appear on t=e message box, please refer >able +,.+ for t*pes of command button displa*ed. >=e >itle argument Gill displa* t=e title of t=e message board. 'able 101: &t"le Values &t"le Value (amed )onstant Buttons 2ispla"ed , vbO-Onl* O- button + vbO-/ancel O- and /ancel buttons 0 vbAbort1etr*2gnore Abort, 1etr* and 2gnore buttons. 3 vb4es5o/ancel 4es, 5o and /ancel buttons 7 vb4es5o 4es and 5o buttons 8 vb1etr*/ancel 1etr* and /ancel buttons
He can use named constant in place of integers for t=e second argument to ma-e t=e programs more readable. 2n fact, "$9 Gill automaticall* s=oGs up a list of names constant G=ere *ou can select one of t=em. Example' *our#sg:#sg$ox( ;/lic- O. to (roceed;, +, ;)tartup #enu;) and *our#sg:#sg(;/lic- O. to (roceed;. vbO-/ancel,;)tartup #enu;) are t=e same. *our#sg is a variable t=at =olds values t=at are returned b* t=e #sg$ox ( ) function. >=e values are determined b* t=e t*pe of buttons being clic-ed b* t=e users. 2t =as to be declared as 2nteger data t*pe in t=e procedure or in t=e general declaration section. 'able 10* s=oGs t=e values, t=e corresponding named constant and buttons. 'able 10* : 3eturn Values and )ommand Buttons Value (amed )onstant Button )lic4ed + vbO- O- button 0 vb/ancel /ancel button 3 vbAbort Abort button 7 vb1etr* 1etr* button 8 vb2gnore 2gnore button 9 vb4es 4es button < vb5o 5o button -xample 101 i. >=e 2nterface' 4ou draG t=ree command buttons and a label ii. >=e procedure for t=e test button' (rivate )ub >est?/lic-() as s=oGn in Figure +,.+ Figure 101 6im testmsg As 2nteger testmsg : #sg$ox(;/lic- to test;, +, ;>est message;) 2f testmsg : + >=en 6ispla*./aption : ;>esting )uccessful; Else 6ispla*./aption : ;>esting fail; End 2f End )ub H=en a user clic- on t=e test button, t=e image li-e t=e one s=oGn in Figure +,.0 Gill appear. As t=e user clic- on t=e O. button, t=e message ;>esting successful; Gill be displa*ed and G=en =e&s=e clic-s on t=e /ancel button, t=e message ;>esting fail; Gill be displa*ed. Figure 10* >o ma-e t=e message box loo-s more sop=isticated, *ou can add an icon besides t=e message. >=ere are four t*pes of icons available in "$ as s=oGn in >able +,.3 'able 10. Value (amed )onstant Icon +9 vb/ritical 30 vbAuestion 7B vbExclamation 97 vb2nformation -xample 10* 4ou draG t=e same 2nterface as in example +,.+ but modif* t=e codes as folloGs' (rivate )ub test0?/lic-() 6im test#sg0 As 2nteger test#sg0 : #sg$ox(;/lic- to >est;, vb4es5o/ancel C vbExclamation, ;>est #essage;) 2f test#sg0 : 9 >=en displa*0./aption : ;>esting successful; Else2f test#sg0 : < >=en displa*0./aption : ;Are *ou sureD; Else displa*0./aption : ;>esting fail; End 2f End )ub 2n t=is example, t=e folloGing message box Gill be displa*ed' Figure 10. 10* '5e InputBox( ) Function An 2nput$ox( ) function Gill displa* a message box G=ere t=e user can enter a value or a message in t=e form of text. >=e format is m"Message#InputBox($rompt! 'itle! default/text! x-position! "-position) m*#essage is a variant data t*pe but t*picall* it is declared as string, G=ic= accept t=e message input b* t=e users. >=e arguments are explained as folloGs' (rompt - >=e message displa*ed normall* as a Iuestion as-ed. >itle - >=e title of t=e 2nput $ox. default-text - >=e default text t=at appears in t=e input field G=ere users can use it as =is intended input or =e ma* c=ange to t=e message =e Gis= to -e* in. x-position and *-position - t=e position or t=e coordinate of t=e input box. -xample 10. i. >=e 2nterface Figure 101 ii. >=e procedure for t=e O. button (rivate )ub O.?/lic-() 6im user#sg As )tring user#sg : 2nput$ox(;H=at is *our messageD;, ;#essage Entr* Form;, ;Enter *our messge =ere;, 8,,, <,,) 2f user#sg EF ;; >=en message./aption : user#sg Else message./aption : ;5o #essage; End 2f End )ub H=en a user clic- t=e O. button, t=e input box as s=oGn in Figure +,.8 Gill appear. After user entering t=e message and clic- O., t=e message Gill be displa*ed on t=e caption, if =e clic- /ancel, ;5o message; Gill be displa*ed. E(revious JessonF EE Kome FF E 5ext JessonF Input Box @ crearea Ai inserarea acesteia n cod Posted on +B.+=.<=++ b? 3lexandru 8ionisie in , !B3 with = (omments 3tunci c4nd doriZi s# obZineZi o anumit# in"ormaZie de la utilizator, puteZi "olosi o caset# de tip Input Box. .intaxa este destul de simpl# [i 0ntr,o anumit# m#sur# seam#n# cu cea a Message Box,urilor: !nput3ox(promptM, titleN M, "e1aultN M, xposN M, 5posN M, 6elp1ile, contextN) ,espre sintaxB , prompt , textul ce va "i a"i[at 0n caseta de tip Input Box. .uport# p4n# la 3C46 de caractere )argument obligatoriu*J , title N textul ce apare 0n bara de titlu )argument opZional*J , default N textul ce va "i a"i[at 0n text box,ul de tip Input )argument opZional*J , xpos Ai $pos N se speci"ic# coordonatele de a"i[are pe ecran, at4t pe orizontal# c4t [i pe vertical# )argument opZional*J , 'elpfile Ai context , se speci"ic# locaZia "i[ierului de tip 7el [i din "i[ierul de a@utor. .pre deosebire de Message Box, Input Box ne o"er# 0n mod implicit : butoane care nu pot "i modi"icate/eliminate: -D, )ancel [i 7elp )dac# speci"ic#m un "i[ier pentru argumentul 'elpfile*. An exemplu este urm#torul: Sub 8o"() On 0rror =o&o err A"e(acti-am re"esenarea obiectelor Application/Screen:p"ating = ,alse A"e1inim 8o":ser ca String Aspeci1icam cerinta, un titlu si un text pre"e1init 8o":serO = !nput3ox(!ntro"uceti co"ul "e utili(ator P, 8o" :tili(ator, B) Arulam co"ul "orit Aselectam celula 8F #ange(8F)/Select Ain celula acti-a intro"ucem textul "in !nput3ox Acti-e8ell/9alue = 8o":ser Aacti-am re"esenarea obiectelor Application/Screen:p"ating = &rue 0xit Sub Aproce"ura "e eroare err: 2sg3ox err/Description, -bOQOnl5 L -b!n1ormation, 0roare 0n" Sub 8up# rularea codului, va "i a"i[at input box,ul creat [i ni se va cere s# introducem in"ormaZia de interes. $ead more: http://www.tutorialeo""ice.ro/ms,o""ice/vba,tips/input,box,crearea,si,inserarea, acesteia,in,cod/Dixzz:33\xoIte !tili#area InputBox 1i"elB .cris de 9he!BProgramer . ] ] $eT9est2arness
0ce,t tutorial +*# e6plic modul n care /unc ioneaz Input*o67 Se a/i eaz un prompt ntr-o ca,et de dialog8 a teapt ca utilizatorul , introducere a te6tului ,au /ace i clic pe un uton8 i returneaz un ir care con ine con inutul ca,etei de te6t7
1tilizare9 stringvariable = !nput3ox (prompt M, title] M, implicit] M, xpos] M, ypos] M, helpfile, context])
0rgumentele la /unc ia Input*o6 ,unt de,cri,e mai 4o,9
!rgument Descriere prompt Nece,ar7 )6pre,ie ir a/i at ca me,a4ul din ca,eta de dialog7 3ungimea ma6im de prompte e,te de apro6imativ 1024 de caractere8 n /unc ie de l imea caracterelor utilizate7 titlu (p ional7 )6pre,ie ir a/i at n ara de titlu a ca,etei de dialog7 "ac omite i titlu, numele aplica iei e,te pla,at n ara de titlu7 default (p ional7 )6pre,ie ir a/i at n ca,eta de te6t ca r,pun, implicit dac e,te prevzut nici o alt intrare7 "ac omite i implicit, ca,eta te6t e,te a/i at gol7 xpos i ypos 0mele op ional7 )6pre,ii numerice care ,peci/ic pozi ionarea oicei din ca,eta de pe ecran (n mod implicit8 ca,eta e,te a/i at n centrul ecranului8 care e,te8 de oicei8 de dorit)7 helpfile i context 0mele op ional7 :oate /i /olo,it n cazul n care un /i ier de a4utor a /o,t n/iin at pentru aplicarea7 "ac ,e utilizeaz oricare dintre ace,te argumente8 amii treuie , /ie utilizate7
Observa ii n cazul n care utilizatorul /ace clic pe O# ,au )N;)< pre,e8 /unc ia InputBo$ intoarce tot ceea ce e,te n ca,eta de te6t7 n cazul n care utilizatorul /ace clic pe %evocare& /unc ia returneaz un ir de lungime zero (==)7
n e6emplul dat n ,uiectul anterior8 un Input*o6 a /o,t /olo,it pentru a o ine numele de utilizator7 0minti i-v c o variail ,tring (,trName) a /o,t declarat i /olo,it pentru a ,toca rezultatul /unc iei Input*o69
Dim ca ir "e str7ame str7ame = !nput3ox (!ntro"uce i numele "umnea-oastr:, &est "e intrare)
<e ine i c /unc ia Input*o6 n ace,t e6emplu utilizeaz =Introduce i numele dumneavoa,tr9= ca argument prompt nece,ar8 i =;e,t de intrare=8 ca argument titlu op ional (care a provocat ace,t te6t pentru a /i a/i at n ara de titlu a ca,etei de dialog)7 n cazul n care programul a /o,t primul a alerga8 Input*o6 arata ca acea,ta9
1tilizatorul a intrat apoi numele ,u n zona de te6t a Input*o69
0tunci c>nd utilizatorul /ace clic pe (?8 irul =@arr.= a /o,t depozitat n ,trName variail7 0 avut utilizatorul a /cut clic pe <evocare8 irul de lungime zero (==) ar /i /o,t ,tocate n ,trName7
1rmtorul e6emplu arat cum ,e /olo,e te argumentul implicit.
S pre,upunem c ave i nevoie utilizatorul pentru a introduce un numr de cont8 dar cea mai mare parte a timpului a programului va /i de prelucrare con,iderare =0*2- 123=7 0i putea o/eri irul =0*2-123=8 ca al treilea argument pentru Input*o69 strAcct!D = !nput3ox (8ontul !D:, "e intrare "e testare, A38B1FJ)
n cazul n care programul e,te rulat8 te6tul introdu, ca argument implicit apare pre- umplut i a ,uliniat n zona de introducere a te6tului de Input*o69
1tilizatorul poate accepta c i /ace i clic pe (?8 ,au ,e pot introduce =0*2-123= pentru a intra n tot ce e,te nece,ar i apoi /ace i clic pe (?7
"ac dori i8 con/igura i un alt proiect =,-l ncerca i=8 copia i /olderul n care a i ,alvat ini ial =,-l ncerca i= proiect la un nou do,ar8 de,c5ide i proiectul copiat8 i nlocui i evenimentul cmd;r.ItA2licB cu urmtorul cod9
Sub Pri-ate cm"&r5!t%8lic4 ()
Dim ca ir "e strAcct!D strAcct!D = !nput3ox (8ontul !D:, "e intrare "e testare, A38B1FJ) Print Datele pentru contul "e i"entitateR strAcct!DR 9or 1i procesate/ 0n" Sub
2>nd e6ecuta i proiectului i /ace i clic pe utonul =,-l ncerca i=8 Input*o6 cu intrarea implicit a a cum ,e arat alove vor /i a/i ate7 "ac-l accepte i /ace i clic pe (?8 produc ia ar treui , arate ace,t lucru9
MessageBox 8unction in (isual Basic E ((BE) 8ispla?s a message in a dialog box and wait "or the user to clic7 a button, and returns an integer indicating which button the user clic7ed. 8ollo>ing is an expanded MessageBox S$ntax B MsgBox ( Prompt ,iconsFbuttons % ,title % ) memor$F"aria+le G MsgBox ( prompt , iconsF buttons% ,title% ) rompt B .tring expressions displa?ed as the message in the dialog box. I" prompt consist o" more than one line, ?ou can separate the lines using the "+r)r=f constant. Icons H Buttons B Eumeric expression that is the sum o" values speci"?ing the number and t?pe o" buttons and icon to displa?. Title B .tring expression displa?ed in the title bar o" the dialog box. I" ?ou omit title, the application name is placed in the title bar. Icons )onstant (alue ,escription "+)ritical +; 8ispla? (ritical message icon "+2uestion :< 8ispla? 6arning Huer? icon "+Exclamation BC 8ispla? 6arning message icon "+Information ;B 8ispla? in"ormation icon Buttons )onstant (alue ,escription "+-D-nl$ = 8ispla? &' button onl? "+-D)ancel + 8ispla? &' and (ancel buttons "+/+ort*etr$Ignore < 8ispla? 3bort, $etr? and Ignore buttons "+0es1o)ancel : 8ispla? /es, Eo and (ancel buttons "+0es1o B 8ispla? /es and Eo buttons "+*etr$)ancel G 8ispla? $etr? and (ancel buttons *eturn (alues )onstant (alue ,escription "+-D + &7 Button "+)ancel < (ancel Button "+/+ort : 3bort Button "+*etr$ B $etr? Button "+Ignore G Ignore Button "+0es ; /es Button "+1o I Eo Button 8ollo>ing is an example illustrates t'e use of message +oxes I &pen a new Pro@ect and save the Lorm as messageboxdemo."rm and save the Pro@ect as messageboxdemo.vbp I 8esign the application as shown below. -+Ject ropert$ Setting 8orm (aption Eame MessageBox8emo "rmMessageBox8emo =a+el (aption Eame lblEame Eame TextBox Eame 9ext txtEame ) empt? * =istBox Eame lstEame )ommandButton (aption Eame 3dd cmd3dd )ommandButton (aption Eame 8elete cmd8elete )ommandButton (aption Eame 1xit cmd1xit Lollowing code is entered in the txtEameW(hange ) * event Private .ub txtEameW(hange)* I" Len)txtEame.9ext* ^ = 9hen cmd3dd.1nabled K 9rue 1nd I" 1nd .ub Lollowing code has to be entered in the cmd3ddW(lic7 ) * event Private .ub cmd3ddW(lic7)* answer K MsgBox)-8o ?ou want to add this name to the list boxO-, vb1xclamation F vb/esEo, -3dd (on"irm-* I" answer K vb/es 9hen lstEame.3ddItem txtEame.9ext txtEame.9ext K -- txtEame..etLocus cmd3dd.1nabled K Lalse 1nd I" 1nd .ub Lollowing code is entered in the cmd8eleteW(lic7 ) * event Private .ub cmd8eleteW(lic7)* 8im remove 3s Integer remove K lstEame.ListIndex I" remove _ = 9hen MsgBox -Eo names is selected-, vbIn"ormation, -1rror- 1lse answer K MsgBox)-3re ?ou sure ?ou want to delete - V vb(rL" V -the selected nameO-,W vb(ritical F vb/esEo, -6arning-* I" answer K vb/es 9hen I" remove ^K = 9hen lstEame.$emoveItem remove txtEame..etLocus MsgBox -.elected name was deleted-, vbIn"ormation, -8elete (on"irm- 1nd I" 1nd I" 1nd I" 1nd .ub Lollowing code is entered in the cmd1xitW(lic7 ) * event Private .ub cmd1xitW(lic7)* answer K MsgBox)-8o ?ou want to TuitO-, vb1xclamation F vb/esEo, -(on"irm-* I" answer K vb/es 9hen 1nd 1lse MsgBox -3ction canceled-, vbIn"ormation, -(on"irm- 1nd I" 1nd .ub .ave and run the application. /ou can notice the di""erent t?pe o" message box t?pes are used to per"orm an action ( ,o>nload t'e source code ) MessageBox 8unc ia n (isual Basic E ((BE) 3"i eaz# un mesa@ 0ntr,o caset# de dialog i a tepta i pentru ca utilizatorul s# "ace i clic pe un buton, i returneaz# un 0ntreg care indic# buton care utilizatorul a "#cut clic. ;n urma este un MessageBox extins SintaxaB MsgBox (rompt , icoane butoane F% , titlu&) memor$F"aria+le G MsgBox (prompte , icoane butoane F% , titlu&) romptB expresii .tring a"i at ca mesa@ul din caseta de dialog. Sn cazul 0n care constau prompt# a mai mult de o linie, se poate separa liniile utiliz4nd constanta "+r)r=fK Icoane H ButoaneB expresie numeric# care este suma valorilor care speci"ic# num#rul i tipul de butoane i pictogram# pentru a a"i a. TitluB 1xpresie ir a"i at 0n bara de titlu a casetei de dialog. 8ac# omite i titlu, numele aplica iei este plasat 0n bara de titlu. Icoane )onstant (aloarea ,escriere "+)ritical +; 3"i eaz# pictograma mesa@ critice "+2uestion :< 3"i are pictogram# de interogare de avertizare "+Exclamation BC Icon mesa@ de avertizare de a"i are "+Information ;B Icon in"orma ii de a"i are Butoane )onstant (aloarea ,escriere "+-D-nl$ = 3"i eaz# doar butonul &' "+-D)ancel + 3"i area &' i (ancel butoanele "+/+ort*etr$Ignore < 3"i area 3bort, $etr? i Ignore butoane "+0es1o)ancel : 3"i area 8a, Eu i anula butoane "+0es1o B 3"i area da i nu butoane "+*etr$)ancel G 3"i area $etr? i (ancel butoanele (alorile returnate )onstant (aloarea ,escriere "+-D + Butonul &' "+)ancel < Butonul 3nulare "+/+ort : 3bandona i Button "+*etr$ B Sncerca i din nou Button "+Ignore G Ignora i Button "+0es ; 8a Button "+1o I Eu Button ;n urma este un exemplu ilustrea# utili#area de casete de mesaJ I 8eschide un nou proiect i de a salva "ormularul de messageboxdemo."rm i salva proiectul ca messageboxdemo.vbp I 8esign aplicarea a a cum se arat# mai @os. -+iect roprietate Setarea 8ormular (aption Eume MessageBox8emo "rmMessageBox8emo =a+el (aption Eume lblEame Eume TextBox Eume 9ext txtEame )Pol* =istBox Eume lstEame )ommandButton (aption Eume 3dauga cmd3dd )ommandButton (aption Eume terge i cmd8elete )ommandButton (aption Eume 1xit cmd1xit 8up# cod este 0nscris 0n txtEameW(hange )* eveniment .ub Private txtEameW(hange )* 8ac# Len )txtEame.9ext*^ = atunci cmd3dd.1nabled K 9rue 1nd 8ac# 1nd .ub 8up# cod trebuie s# "ie introduse 0n cmd3ddW(lic7 )* eveniment .ub Private cmd3ddW(lic7 )* answer K MsgBox )-Eu vrei sa adaugi acest nume pentru caseta list#O-, vb1xclamation F vb/esEo, -3d#uga i (on"irm-* 8aca raspunsul K vb/es 3poi lstEame.3ddItem txtEame.9ext txtEame.9ext K -- txtEame..etLocus cmd3dd.1nabled K Lalse 1nd 8ac# 1nd .ub 8up# cod este 0nscris 0n cmd8eleteW(lic7 )* eveniment .ub Private cmd8eleteW(lic7 )* 8im elimina (a Integer elimina K lstEame.ListIndex 8ac# elimina i _= atunci MsgBox -nu este selectat un nume-, vbIn"ormation, -1roare- 3ltele answer K MsgBox )-.unte i sigur c# dori i s# terge i- V vb(rL" si -numele selectatO-, W vb(ritical F vb/esEo, -3vertisment-* 8aca raspunsul K vb/es 3poi 8ac# scoate i^ K = 3poi, lstEame.$emoveItem remove txtEame..etLocus MsgBox -numele selectat a "ost ters-, vbIn"ormation, -8elete (on"irmare- 1nd 8ac# 1nd 8ac# 1nd 8ac# 1nd .ub 8up# cod este 0nscris 0n cmd1xitW(lic7 )* eveniment .ub Private cmd1xitW(lic7 )* answer K MsgBox )-!rei s# renun iO-, vb1xclamation F vb/esEo, -(on"irm-* 8aca raspunsul K vb/es 3poi ."4r it 3ltele MsgBox -3c iunea anulat-, vbIn"ormation, -(on"irm- 1nd 8ac# 1nd .ub .alva i i rula aplica ia. Pute i observa di"eritele tipuri de tipuri de cutie de mesa@e sunt "olosite pentru a e"ectua o ac iune (,escrca codul surs) !sing TextBox )ontrol In (isual Basic E 9extBox controls o""er a natural wa? "or users to enter a value in ?our program. Lor this reason, the? tend to be the most "reTuentl? used controls in the ma@orit? o" 6indows applications. 9extBox controls, which have a great man? properties and events, are also among the most complex intrinsic controls. In this section, I guide ?ou through the most use"ul properties o" 9extBox controls and show how to solve some o" the problems that ?ou`re li7el? to encounter. Setting properties to a TextBox 9ext can be entered into the text box b? assigning the necessar? string to the text propert? o" the control I" the user needs to displa? multiple lines o" text in a 9extBox, set the MultiLine propert? to 9rue 9o customize the scroll bar combination on a 9extBox, set the .crollBars propert?. .croll bars will alwa?s appear on the 9extBox when it`s MultiLine propert? is set to 9rue and its .crollBars propert? is set to an?thing except Eone)=* I" ?ou set the MultilIne propert? to 9rue, ?ou can set the alignment using the 3lignment propert?. 9he test is le"t,@usti"ied b? de"ault. I" the MultiLine propert? is et to Lalse, then setting the 3lignment propert? has no e""ect. *un:Time roperties of a TextBox control 9he 9ext propert? is the one ?ou`ll re"erence most o"ten in code, and convenientl? it`s the de"ault propert? "or the 9extBox control. 9hree other "reTuentl? used properties are these: T'e SelStart propert$ sets or returns the position o" the blin7ing caret )the insertion point where the text ?ou t?pe appears*. Eote that the blin7ing cursor inside 9extBox and other controls is named caret, to distinguish it "rom the cursor )which is implicitl? the mouse cursor*. 6hen the caret is at the beginning o" the contents o" the 9extBox control, .el.tart returns =J when it`s at the end o" the string t?ped b? the user, .el.tart returns the value Len)9ext*. /ou can modi"? the .el.tart propert? to programmaticall? move the caret. T'e SelLengt propert$ returns the number o" characters in the portion o" text that has been highlighted b? the user, or it returns = i" there`s no highlighted text. /ou can assign a nonzero value to this propert? to programmaticall? select text "rom code. Interestingl?, ?ou can assign to this propert? a value larger than the current text`s length without raising a run,time error. T'e SelText propert$ sets or returns the portion o" the text that`s currentl? selected, or it returns an empt? string i" no text is highlighted. Ase it to directl? retrieve the highlighted text without having to Tuer? 9ext, .el.tart, and .elLength properties. 6hat`s even more interesting is that ?ou can assign a new value to this propert?, thus replacing the current selection with ?our own. I" no text is currentl? selected, ?our string is simpl? inserted at the current caret position. 6hen ?ou want to append text to a 9extBox control, ?ou should use the "ollowing code )instead o" using the concatenation operator* to reduce "lic7ering and improve per"ormance: 9ext+..el.tart K Len)9ext+.9ext* 9ext+..el9ext K .tring9oBe3dded &ne o" the t?pical operations ?ou could "ind ?oursel" per"orming with these properties is selecting the entire contents o" a 9extBox control. /ou o"ten do it when the caret enters the "ield so that the user can Tuic7l? override the existing value with a new one, or start editing it b? pressing an? arrow 7e?: Private .ub 9ext+WPotLocus)* 9ext+..el.tart K = ` 3 ver? high value alwa?s does the tric7. 9ext+..elLength K >>>> 1nd .ub 3lwa?s set the .el.tart propert? "irst and then the .elLength or .el9ext properties. 6hen ?ou assign a new value to the .el.tart propert?, the other two are automaticall? reset to = and an empt? string respectivel?, thus overriding ?our previous settings. 9he selected text can be copied to the (lipboard b? using .el9ext: (lipboard..el9ext text, "ormat% In the above s?ntax, text is the text that has to be placed into the (lipboard, and "ormat has three possible values. +. !b(LLin7 , conversation in"ormation <. !b(L$9L , $ich 9ext Lormat :. !b(L9ext , 9ext 6e can get text "rom the clipboard using the Pet9ext)* "unction this wa?: (lipboard.Pet9ext )"ormat%* 9he "ollowing Ligure summarizes the common 9extBox control`s properties and methods. ropert$L Met'od ,escription Propertie! Ena+led speci"ies whether user can interact with this control or not Index .peci"ies the control arra? index =ocDed I" this control is set to 9rue user can use it else i" this control is set to "alse the control cannot be used Max=engt' .peci"ies the maximum number o" characters to be input. 8e"ault value is set to = that means user can input an? number o" characters Mouseointer Asing this we can set the shape o" the mouse pointer when over a 9extBox Multiline B? setting this propert? to 9rue user can have more than one line in the 9extBox ass>ord)'ar 9his is to speci"? mas7 character to be displa?ed in the 9extBox ScrollBars 9his to set either the vertical scrollbars or horizontal scrollbars to ma7e appear in the 9extBox. Aser can also set it to both vertical and horizontal. 9his propert? is used with the Multiline propert?. Text .peci"ies the text to be displa?ed in the 9extBox at runtime ToolTipIndex 9his is used to displa? what text is displa?ed or in the control (isi+le B? setting this user can ma7e the 9extbox control visible or invisible at runtime "etod Set8ocus 9rans"ers "ocus to the 9extBox E"ent procedures )'ange 3ction happens when the 9extBox changes )licD 3ction happens when the 9extBox is clic7ed Mot8ocus 3ction happens when the 9extBox receives the active "ocus =ost8ocus 3ction happens when the 9extBox loses it "ocus .e$,o>n (alled when a 7e? is pressed while the 9extBox has the "ocus .e$!p (alled when a 7e? is released while the 9extBox has the "ocus More on (BE TextBox )ontrols 9rapping 'e?board 3ctivit? !alidation $outines "or Eumbers 9he (auses!alidation Propert? and the !alidate 1vent 3uto,9abbing Lields and Lormatting 9ext Multiline 9extBox (ontrols See /lso 9extBox (ontrol in !isual Basic ; (ommandButton and &ptionButton (ontrols in !isual Basic ; (hec7Box control in !isual Basic ; Label and Lrame (ontrols in !isual Basic ; PictureBox and Image (ontrols in !isual Basic ; 9he 9imer, Line, .hape and &L1 (ontrols in !isual Basic ; 6or7ing with Menus in !isual Basic ; .crollBar (ontrol in !isual Basic ; 8riveListBox, 8irListBox, and LileListBox (ontrols in !isual Basic ; 8olosind TextBox de control n (isual Basic E (ontroale 9extBox o"era un mod natural pentru ca utilizatorii s# introduce i o valoare 0n program. 8in acest motiv, ele tind s# "ie cele mai utilizate 0n ma@oritatea aplica iilor 6indows. (ontroale 9extBox, care au un num#r mare de propriet# i i evenimente, sunt, de asemenea, printre cele mai complexe de control intrinseci. Sn aceast# sec iune, v# ghida prin propriet# ile cele mai utile de control 9extBox i arat# cum s# rezolve unele dintre problemele pe care este "oarte probabil sa 0nt4lni. Setarea propriet ilor pentru o caset text 9extul poate "i introdus# 0n caseta de text prin atribuirea irul necesar pentru proprietatea de text a controlului Sn cazul 0n care utilizatorul are nevoie pentru a a"i a mai multe linii de text 0ntr,o caset# text, seta i proprietatea Multiline la 9rue Pentru a personaliza combina ia bara de de"ilare pe o caset# text, seta i proprietatea barele de derulare. Barele de de"ilare va ap#rea 0ntotdeauna pe 9extBox atunci c4nd este proprietate multilinie este setat# la 3dev#rat i proprietatea de derulare este setat la nimic 0n a"ar# de Eone )=* 8ac# seta i proprietatea multilinie la 9rue, pute i seta alinierea "olosind proprietatea de aliniere. 9estul este l#sat,@usti"icat# 0n mod implicit. Sn cazul 0n care proprietatea Multilinie este et la Lalse, atunci setarea propriet# ii 3liniere are nici un e"ect. *un:Time ropriet ile unui control caset text Proprietatea text este cea pe care o vei "ace re"erire cel mai adesea 0n cod, i convenabil este proprietatea implicit pentru controlul 9extBox. 3lte trei propriet# i utilizate "recvent sunt acestea: Seturile de proprietate SelStart sau returneaz# pozi ia cursorului intermitent )punctul de inserare 0n care apare textul pe care 0l tasta i*. $e ine i c# cursorul intermitent 0n interiorul 9extBox i alte controale este numit cursor, pentru a se distinge de la cursorul )care este implicit cursorul mouse,ului*. (4nd cursorul este la 0nceputul con inutului de control 9extBox, .el.tart returneaz# =J atunci c4nd este la s"4r itul irului tastat de utilizator, .el.tart returneaz# valoarea Len )9ext*. 3ve i posibilitatea s# modi"ica i proprietatea .el.tart pentru a muta cursorul programatic. roprietatea SelLengt returneaz# num#rul de caractere 0n partea de text care a "ost eviden iat# de c#tre utilizator, sau se returneaz# = dac# nu exist# nici un text eviden iat. 3ve i posibilitatea s# atribui i o valoare di"erit# de zero pentru aceast# proprietate pentru a selecta programatic textul din cod. Interesant, pute i aloca pentru aceast# proprietate o valoare mai mare dec4t lungimea textului curent, "#r# a ridica o eroare de run,time. Seturile de proprietate SelText sau 0ntoarce por iunea de text care este selectat 0n prezent, sau se 0ntoarce un ir gol dac# nu textul este eviden iat. Lolositi,l pentru a prelua direct textul eviden iat, "#r# a interoga 9ext, .el.tart, i propriet# i .elLength. (e e chiar mai interesant este c# pute i atribui o nou# valoare pentru aceast# proprietate, 0nlocuind ast"el selec ia curent# cu propriul t#u. Sn cazul 0n care nici un text este selectat#, string,ul este pur i simplu introdus la pozi ia curent# caret. (4nd dori i s# ad#uga i text la un control caset# text, trebuie s# utiliza i codul de mai @os )0n loc de a "olosi operatorul de concatenare* pentru a reduce p4lp4irea i 0mbun#t# i per"orman a: 9ext+..el.tart K Len )9ext+.9ext* 9ext+..el9ext K .tring9oBe3dded Ana dintre opera iunile tipice te,ai putea g#si per"ormante cu aceste propriet# i este selectarea 0ntregul con inut al unui control caset# text. 3i de multe ori o "ac atunci c4nd cursorul intr# 0n domeniu, ast"el 0nc4t utilizatorul poate trece rapid valoarea existent# cu una nou#, sau de a 0ncepe editarea ei ap#s4nd orice tast# s#geat#: .ub Private 9ext+WPotLocus )* 9ext+..el.tart K = -& valoare "oarte mare nu 0ntotdeauna truc. 9ext+..elLength K >>>> 1nd .ub .eta i 0ntotdeauna proprietatea .el.tart 0nt4i i apoi .elLength sau .el9ext propriet# ile. (4nd atribui i o nou# valoare a propriet# ii .el.tart, celelalte dou# sunt resetate automat la = i un ir gol, respectiv, imperative, ast"el set#rile anterioare. 9extul selectat poate "i copiat 0n (lipboard "olosind .el9ext: 9extul (lipboard..el9ext, "ormat% Sn sintaxa de mai sus, textul este textul care trebuie s# "ie plasat 0n (lipboard, i "ormat are trei valori posibile. + !b(LLin7 , in"orma ii conversa ie < !b(L$9L , $ich 9ext Lormat : !b(L9ext , 9ext Putem ob ine textul din clipboard "olosind "unc ia nls )* ast"el: (lipboard.Pet9ext )"ormat%* Ligura de mai @os rezum# propriet# i i metode comune de control 9extBox lui. roprietatea L Metoda ,escriere Propriet# i /cti"at speci"ic# dac# utilizatorul poate interac iona cu acest control sau nu Index .peci"ic# indicele matrice de control Blocat 8ac# acest control este setat la 9rue utilizator poate "olosi altceva dac# acest control este setat la "als controlul nu poate "i utilizat Maxlengt' .peci"ic# num#rul maxim de caractere pentru a "i introduse. !aloarea implicit# este setat# la = 0nseamn# c# utilizatorul poate introduce orice num#r de caractere ointerul Lolosind acest putem seta "orma de cursorul mouse,ului atunci c4nd 0ntr,o caset# text Multiline Prin setarea aceast# proprietate la 9rue utilizator poate avea mai mult de o linie 0n caseta de text ass>ord)'ar 3cest lucru este de a speci"ica masca de caracter pentru a "i a"i ate 0n caseta de text Barele de derulare 3cest lucru a seta "ie barele de derulare verticale sau orizontale barele de derulare pentru a "ace s# apar# 0n caseta de text. Atilizatorul poate de asemenea seta at4t pe vertical# i orizontal#. 3ceast# proprietate este "olosit# cu proprietatea Multiline. Text .peci"ic# textul s# "ie a"i at 0n caseta de text 0n timpul rul#rii ToolTipIndex 3cesta este "olosit pentru a a"i a ceea ce textul este a"i at sau 0n controlul (i#i+il Prin setarea acestui utilizator poate "ace controlul caseta vizibil sau invizibil 0n timpul rul#rii "etoda Setfocus 9rans"erurile se concentreze la 9extBox rocedurile de e"enimente Sc'im+ 3c iunea se 0nt4mpl# atunci c4nd se schimb# 9extBox 8ace i clic pe 3c iunea se 0nt4mpl# atunci c4nd se "ace clic pe 9extBox Mot8ocus 3c iunea se 0nt4mpl# atunci c4nd 9extBox prime te "ocalizarea activ# =ost8ocus 3c iunea se 0nt4mpl# atunci c4nd 9extBox se pierde "ocus .e$,o>n Eumit atunci c4nd o tast# este ap#sat# 0n timp ce 9extBox are "ocalizarea .e$up Eumit atunci c4nd o tast# este eliberat# 0n timp ce 9extBox are "ocalizarea (BE )ommandButton and -ptionButton )ontrols : (isual Basic E 6hen compared to 9extBox controls, these controls are reall? simple. Eot onl? do the? expose relativel? "ew properties, the? also support a limited number o" events, and ?ou don`t usuall? write much code to manage them. )ommandButton )ontrols in (BE Asing (ommandButton controls is trivial. In most cases, ?ou @ust draw the control on the "orm`s sur"ace, set its (aption propert? to a suitable string )adding an V character to associate a hot 7e? with the control i" ?ou so choose*, and ?ou`re "inished, at least with user,inter"ace issues. 9o ma7e the button "unctional, ?ou write code in its (lic7 event procedure, as in this "ragment: Private .ub (ommand+W(lic7)* ` .ave data, then unload the current "orm. (all .ave8ata9o8is7 Anload Me 1nd .ub /ou can use two other properties at design time to modi"? the behavior o" a (ommandButton control. /ou can set the 8e"ault propert? to 9rue i" it`s the de"ault push button "or the "orm )the button that receives a clic7 when the user presses the 1nter 7e?Musuall? the &' or .ave button*. .imilarl?, ?ou can set the (ancel propert? to 9rue i" ?ou want to associate the button with the 1scape 7e?. 9he onl? relevant (ommandButton`s run,time propert? is !alue, which sets or returns the state o" the control )9rue i" pressed, Lalse otherwise*. !alue is also the de"ault propert? "or this t?pe o" control. In most cases, ?ou don`t need to Tuer? this propert? because i" ?ou`re inside a button`s (lic7 event ?ou can be sure that the button is being activated. 9he !alue propert? is use"ul onl? "or programmaticall? clic7ing a button: 9his "ires the button`s (lic7 event. (ommand+.!alue K 9rue 9he (ommandButton control supports the usual set o" 7e?board and mouse events )'e?8own, 'e?Press, 'e?Ap, Mouse8own, MouseMove, MouseAp, but not the 8bl(lic7 event* and also the PotLocus and LostLocus events, but ?ou`ll rarel? have to write code in the corresponding event procedures. roperties of a )ommandButton control 9o displa? text on a (ommandButton control, set its Caption propert?. 3n event can be activated b? clic7ing on the (ommandButton. 9o set the bac7ground colour o" the (ommandButton, select a colour in the Bac7(olor propert?. 9o set the text colour set the Lorecolor propert?. Lont "or the (ommandButton control can be selected using the Lont propert?. 9o enable or disable the buttons set the 1nabled propert? to 9rue or Lalse 9o ma7e visible or invisible the buttons at run time, set the !isible propert? to 9rue or Lalse. 9ooltips can be added to a button b? setting a text to the 9ooltip propert? o" the (ommandButton. 3 button clic7 event is handled whenever a command button is clic7ed. 9o add a clic7 event handler, double clic7 the button at design time, which adds a subroutine li7e the one given below. Private .ub (ommand+W(lic7) * .................. 1nd .ub -ptionButton )ontrols in (BE &ptionButton controls are also 7nown as radio buttons because o" their shape. /ou alwa?s use &ptionButton controls in a group o" two or more because their purpose is to o""er a number o" mutuall? exclusive choices. 3n?time ?ou clic7 on a button in the group, it switches to a selected state and all the other controls in the group become unselected. Preliminar? operations "or an &ptionButton control are similar to those alread? described "or (hec7Box controls. /ou set an &ptionButton control`s (aption propert? to a meaning"ul string, and i" ?ou want ?ou can change its 3lignment propert? to ma7e the control right aligned. I" the control is the one in its group that`s in the selected state, ?ou also set its !aluepropert? to 9rue. )9he &ptionButton`s !alue propert? is a Boolean value because onl? two states are possible.* !alue is the de"ault propert? "or this control. 3t run time, ?ou t?picall? Tuer? the control`s !alue propert? to learn which button in its group has been selected. Let`s sa? ?ou have three &ptionButton controls, named opt6ee7l?, optMonthl?, and opt/earl?. /ou can test which one has been selected b? the user as "ollows: I" opt6ee7l?.!alue 9hen ` Aser pre"ers wee7l? "reTuenc?. 1lseI" optMonthl?.!alue 9hen ` Aser pre"ers monthl? "reTuenc?. 1lseI" opt/earl?.!alue 9hen ` Aser pre"ers ?earl? "reTuenc?. 1nd I" .trictl? spea7ing, ?ou can avoid the test "or the last &ptionButton control in its group because all choices are supposed to be mutuall? exclusive. But the approach I @ust showed ?ou increases the code`s readabilit?. 3 group o" &ptionButton controls is o"ten hosted in a Lrame control. 9his is necessar? when there are other groups o" &ptionButton controls on the "orm. 3s "ar as !isual Basic is concerned, all the &ptionButton controls on a "orm`s sur"ace belong to the same group o" mutuall? exclusive selections, even i" the controls are placed at the opposite corners o" the window. 9he onl? wa? to tell !isual Basic which controls belong to which group is b? gathering them inside a Lrame control. 3ctuall?, ?ou can group ?our controls within an? control that can wor7 as a containerMPictureBox, "or exampleMbut Lrame controls are o"ten the most reasonable choice. Example &pen a new .tandard 1\1 pro@ect and the save the Lorm as &ption."rm and save the pro@ect as &ption.vbp. 8esign the Lorm as per the "ollowing speci"ications table. -+Ject ropert$ Settings =a+el (aption Eame 1nter a Eumber Label+ TextBox 9ext Eame )empt?* 9ext+ )ommandButton (aption Eame V(lose (ommand+ -ptionButton (aption Eame V&ctal opt&ct -ptionButton (aption Eame V2exadecimal opt2ex -ptionButton (aption Eame V8ecimal opt8ec 9he application responds to the "ollowing events 9he change event o" the 9extBox reads the value and stores it in a "orm,level numeric variable. 9he clic7 event o" opt&ct button returns curretval in octal. 9he clic7 event o" the opt2ex button curerntval in hexadecimal 9he clic7 event o" the opt8ec button returns the decimal eTuivalent o" the value held currentval. 9he "ollowing code is entered in the general declarations section o" the Lorm. 8im currentval as variant 9he variable is initialized to = b? de"ault. 9he change event procedure chec7s to ascertain the number s?stem )&ctal, 2exadecimal* that is in e""ect and then reads in the number. Private .ub 9ext+W(hange)* I" opt&ct.!alue K 9rue 9hen currentval K !al )-V&- V L9rim )9ext+.9ext* V -V-* 1lsei" opt8ec.value K 9rue 9hen currentval K !al )L9rim )9ext+.9ext* V -V-* 1lse currentval K !al )-V2- V L9rim )9ext+.9ext* V -V-* 1nd i" 1nd .ub 9he !al "unction is used to translate string to a number and can recognize &ctal and 2exadecimal strings. 9he L9rim "unction trims the leading blan7s in the text. 9he "ollowing code is entered in the clic7 events o" the &ptionButton controls. Private .ub opt&ctW(lic7)* 9ext+.9ext K &ct)currentval* 1nd .ub Private .ub opt2exW(lic7)* 9ext+.9ext K 2ex)currentval* 1nd .ub Private .ub opt8ecW(lic7)* 9ext+.9ext K Lormat)currentval* 1nd .ub 9he "ollwoing code is entered in the clic7 event o" teh (lose button. Private .ub cmd(loseW(lic7)* Anlod Me 1nd .ub 9he 3pplication is run b? pressing LG or clic7ing on the $un icon in the tool bar. B? pressing the 1xit button the program is terminated. See /lso (BE )ommandButton i -ptionButton )ontrols : (isual Basic E Sn compara ie cu controalele 9extBox, aceste controale sunt "oarte simplu. Eu numai c# expune relativ pu ine propriet# i, ei spri@in#, de asemenea, un num#r limitat de evenimente, iar tu de obicei nu scrie mult cod pentru a le gestiona. )ommandButton )ontroale n (BE Atilizarea comenzilor (ommandButton este trivial. Sn cele mai multe cazuri, va atrage doar controlul pe supra"a # a "ormularului, seta i proprietatea (aption a unui ir adecvat )ad#ugarea unui caracter si de a se asocia o cheie "ierbinte cu controlul, dac# doresc acest lucru*, i a i terminat, cel pu in cu probleme de inter"a # de utilizator. Pentru a "ace butonul "unc ional, tu scrie cod 0n procedura sa Lace i clic eveniment, la "el ca 0n acest "ragment: .ub Private (ommand+W(lic7 )* -.alva i datele, apoi s# descarce "ormularul de curent. (all .ave8ata9o8is7 8esc#rca i Me 1nd .ub Pute i "olosi alte dou# propriet# i 0n timpul de proiectare a modi"ica comportamentul unui control (ommandButton. Pute i seta proprietatea implicit la 9rue dac# e buton implicit pentru "ormularul )butonul care prime te un clic atunci c4nd utilizatorul apas# tasta 1nter,de obicei butonul &' sau .ave*. Sn mod similar, pute i seta proprietate la 9rue 3nulare dac# dori i s# se asocieze butonul cu tasta 1scape. Proprietate run,time doar (ommandButton relevant este valoarea, care stabile te sau se 0ntoarce la starea de control )3dev#rat dac# este ap#sat, L3L.1 0n caz contrar*. !aloarea este, de asemenea, proprietatea implicit# pentru acest tip de control. Sn cele mai multe cazuri, nu ave i nevoie pentru a interoga aceast# proprietate pentru c# dac# e ti 0n interiorul unui buton (lic7 eveniment pute i "i siguri c# butonul este activat. Proprietatea !aloarea este util doar pentru clic7 programatic un buton: 3cest lucru declan eaz# butonul (lic7 eveniment. (ommand+.!alue K 9rue (ontrolul (ommandButton sus ine setul obi nuit de tastatur# i mouse,ul de evenimente )'e?8own, ap#sare de tast#, 'e?Ap, Mouse8own, mousemove, MouseAp, dar nu evenimentul 8bl(lic7* i, de asemenea, evenimentele PotLocus i LostLocus, dar va trebui "oarte rar de a scrie cod 0n Procedurile eveniment corespunz#tor. ropriet ile unui control )ommandButton Pentru a a"i a un text pe o comand# (ommandButton, seta i proprietatea Caption. An eveniment poate "i activat "#c4nd clic pe (ommandButton. Pentru a seta culoarea de "undal a (ommandButton, selecta i o culoare 0n proprietatea Bac7(olor. Pentru a seta culoarea textului seta i proprietatea "orecolor. Lont pentru controlul (ommandButton pot "i selectate "olosind proprietatea Lont. Pentru a activa sau dezactiva butoanele seta i proprietatea 1nabled la 3dev#rat sau "als Pentru a "ace vizibile sau invizibile butoanele de la momentul execu iei, seta i proprietatea !isible la 9rue sau Lalse. Ponturile pot "i ad#ugate la un buton prin stabilirea unui text la proprietatea 9ooltip a (ommandButton. An eveniment "ace i clic pe butonul este manipulat ori de c4te ori un buton de comand# este ap#sat. Pentru a ad#uga un handler eveniment clic7, dublu clic7 pe butonul de la timpul de proiectare, care adaug# o subrutin# ca cea de mai @os. .ub Private (ommand+W(lic7 )* .................. 1nd .ub -ptionButton )ontroale n (BE (ontroalele &ptionButton sunt cunoscute ca butoane radio, din cauza "ormei lor. Atiliza i 0ntotdeauna &ptionButton controale 0ntr,un grup de dou# sau mai multe pentru c# scopul lor este de a o"eri o serie de op iuni care se exclud reciproc. 8e "iecare dat# c4nd "ace i clic pe un buton din grup, se trece la o stare selectat i toate celelalte controale din grupul devin neselectate. &pera iunile preliminare pentru un control &ptionButton sunt similare cu cele de@a descrise pentru controale caset# de selectare. .eta i (aption proprietate un control &ptionButton la un ir semni"icativ, iar dac# dori i, pute i schimba proprietatea 3liniere pentru a "ace controlul aliniat la dreapta. Sn cazul 0n care controlul este cea 0n grupul s#u, care este 0n starea selectat, seta i, de asemenea, !aluepropert? de la 9rue. )Proprietate !aloarea &ptionButton este o valoare Boolean pentru c# numai dou# state sunt posibile.* !aloarea este proprietatea implicit# pentru acest control. La momentul execu iei, interoga i de obicei, valoarea propriet# ii de control pentru a a"la care buton 0n grupul s#u a "ost selectat. .# presupunem c# ave i trei controale &ptionButton, numit opt6ee7l?, optMonthl?, i opt/earl?. Pute i testa care unul a "ost selectat de c#tre utilizator, dup# cum urmeaz#: 8ac# opt6ee7l?.!alue 3poi, -Atilizator pre"er# "recven # s#pt#m4nal#. 1lsei" optMonthl?.!alue 3poi, -Atilizator pre"er# "recven # lunar#. 1lsei" opt/earl?.!alue 3poi, -Atilizator pre"er# "recven # anual#. 1nd 8ac# .trict vorbind, pute i evita test pentru ultimului control &ptionButton 0n grupul s#u pentru c# toate alegerile ar trebui s# "ie reciproc exclusive. 8ar abordarea tocmai i,am ar#tat cre te lizibilitatea codului de. An grup de control &ptionButton este adesea g#zduit 0ntr,un control Lrame. 3cest lucru este necesar atunci c4nd exist# alte grupuri de controale &ptionButton de pe "ormular. Sn ceea ce prive te !isual Basic, toate controalele &ptionButton pe supra"a a unui "ormular apar in aceluia i grup de selec ii exclusive reciproc, chiar dac# controalele sunt plasate la col uri opuse ale "erestrei. .ingura modalitate de a spune !isual Basic, care controleaz# apar in, care grup este de colectarea lor 0ntr,un cadru de control. 8e "apt, pute i grup de control dvs. 0n orice control care poate lucra ca un container,PictureBox, pentru controale exemplu, dar Lrame sunt de multe ori alegerea cea mai rezonabil#. Exemplu 8eschide un nou proiect .tandard 1\1 i salva "ormularul de &ption."rm i salva proiectul ca &ption.vbp. Proiectarea Lormularul ca pe urm#torul tabel caietul de sarcini. -+iect roprietate Setri =a+el (aption Eume Introduce i un num#r de Label+ TextBox 9ext Eume )Pol* 9ext+ )ommandButton (aption Eume V (lose (ommand+ -ptionButton (aption Eume V &ctal opt&ct -ptionButton (aption Eume V 2exazecimal opt2ex -ptionButton (aption Eume V Yecimal opt8ec 3plica ia r#spunde la urm#toarele evenimente 1venimentul schimbare a 9extBox cite te valoarea i o stocheaz# 0ntr,o variabil# numeric# la nivel de "ormular. 1venimentul clic de opt&ct 0ntoarce buton curretval 0n octal. 1venimentul clic de buton curerntval opt2ex 0n hexazecimal 1venimentul clic pe butonul opt8ec 0ntoarce echivalentul zecimal al valorii avut loc currentval. Arm#torul cod este introdus 0n partea general# declara ii a "ormularului. 8im currentval ca variant# !ariabila este ini ializat la = 0n mod implicit. Procedura eveniment schimbare controale pentru a stabili sistemul de num#r )octal, hexazecimal*, care este 0n vigoare i apoi cite te 0n num#rul. .ub Private 9ext+W(hange )* 8ac# opt&ct.!alue K true 3poi, currentval K !al )-V &- V L9$IM )9ext+.9ext* V -V-* 1lsei" opt8ec.value K true 3poi, currentval K !al )L9$IM )9ext+.9ext* V -V-* 3ltele currentval K !al )-V 2- i L9$IM )9ext+.9ext* V -V-* Linal, dac# 1nd .ub Lunc ia !al este "olosit pentru a traduce ir la un num#r i poate recunoa te octale i hexazecimale siruri de caractere. Lunc ia L9$IM ornamente de conducere spa iile libere din text. Arm#torul cod este introdus 0n evenimentele apasare a controalelor &ptionButton. .ub Private opt&ctW(lic7 )* 9ext+.9ext K octombrie )currentval* 1nd .ub .ub Private opt2exW(lic7 )* 9ext+.9ext K 2ex )currentval* 1nd .ub .ub Private opt8ecW(lic7 )* 9ext+.9ext K Lormat )currentval* 1nd .ub (odul "ollwoing este 0nscris 0n caz clic de teh buton (lose. .ub Private cmd(loseW(lic7 )* Anlod Me 1nd .ub (ererea este condus prin ap#sarea LG sau "ace i clic pe pictograma $un din bara de instrumente. Prin ap#sarea butonului Ie ire la "inalizarea programului. 8olosind =istBox )om+oBox i controale n (isual Basic E (ontroalele ListBox (omboBox i s# prezinte un set de op iuni care sunt a"i ate vertical 0ntr,o coloan#. Sn cazul 0n care num#rul de articole s# dep# easc# valoarea care se a"i eaz#, barele de de"ilare va ap#rea 0n mod automat pe controlul. 3ceste bare de de"ilare pot "i derulate 0n sus i 0n @os sau la st4nga la dreapta prin lista. Arm#toarele "ig enumer# c4teva dintre propriet# ile comune )om+oBox i metodele. roprietatea L Metoda ,escriere ropriet i /cti"at Prin setarea aceast# proprietate la 3dev#rat sau "als utilizatorul poate decide dac# utilizatorul poate interac iona cu acest control sau nu Index .peci"ic# indicele matrice de control =ista .tring matrice. (ontine siruri de caractere a"i ate 0n lista vertical#. Sncep4nd cu index de matrice este =. =ist)ount Integer. (on ine num#rul de drop,down elemente de list# =istIndex Integer. (on ine indexul elementului (omboBox selectat. Sn cazul 0n care un element nu este selectat, ListIndex este ,+ Blocat Boolean. .peci"ic# dac# utilizatorul poate introduce sau nu 0n (omboBox ointerul Integer. .peci"ic# "orma de cursorul mouse,ului atunci c4nd 0n zona de (omboBox Index1ou Integer. Index de ultimul element ad#ugat la (omboBox. Sn cazul 0n care combobox nu con ine nici un produs, IndexEou este ,+ Sortate Boolean. .peci"ic# dac# un produs (omboBox sunt sortate sau nu. Stil Integer. .peci"ic# stilul de aspectul (omboBox de Ta+Stop Boolean. .peci"ic# dac# (omboBox prime te "ocalizarea sau nu. Text .tring. .peci"ic# elementul selectat din (omboBox ToolTipIndex .tring. .peci"ic# ce textul este a"i at ca instrument s"at (omboBox de (i#i+il Boolean. .peci"ic# dac# (omboBox este vizibil sau nu la momentul execu iei Metode /ddItem 3d#uga i un element 0n caseta combo )lear 1limin# toate articolele de la (omboBox *emo"eItem .e elimin# elementul speci"icat din (omboBox Setfocus 9rans"erurile se concentreze pentru a (omboBox roceduri e"enimente Sc'im+ (hemat c4nd textul 0n (omboBox este schimbat ,rop,o>n Eumit atunci c4nd este a"i at# lista drop,down (omboBox Mot8ocus Eumit c4nd (omboBox prime te "ocalizarea =ost8ocus Eumit c4nd (omboBox se pierde "ocus /dugarea produs pentru o list 1ste posibil pentru a popula lista de la design,time sau timp de "unc ionare Timp ,esignB Pentru a ad#uga elemente la o list# de la timpul de proiectare, "ace i clic pe lista de proprietate 0n caseta de proprietate i apoi se adaug# elemente. 3p#sa i (9$L F 1E91$ dup# ad#ugarea "iec#rui element a a cum se arat# mai @os. *un TimeB Metoda 3ddItem este utilizat pentru a ad#uga elemente 0ntr,o list# 0n timpul rul#rii. Metoda 3ddItem utilizeaz# urm#toarea sintax#. &b@ect.3ddItemitem, Index 3rgumentul element este un ir de caractere care reprezint# textul pentru a ad#uga la lista de 3rgumentul index este un num#r 0ntreg care indic# 0n cazul 0n care 0n lista pentru a ad#uga elementul nou. Eu da indicele nu este o problem#, pentru c# 0n mod implicit indicele este alocat. Sn urma este un exemplu de a ad#uga element 0ntr,o caset# combo. (odul este scris 0n cazul 0n LormWLoad Private .ub LormWLoad )* (ombo+.3ddItem + (ombo+.3ddItem < (ombo+.3ddItem : (ombo+.3ddItem B (ombo+.3ddItem G (ombo+.3ddItem ; 1nd .ub Scoaterea /rticole dintr:o list Metoda $emoveItem este utilizat pentru a elimina un element dintr,o list#. .intaxa pentru acest lucru este dat de mai @os. Index &b@ect.$emoveItem Armatorul cod veri"ic# dac# un element este selectat 0n list# i apoi elimin# elementul selectat din lista. .ub Private cmd$emoveW(lic7 )* 8ac# List+.ListIndex^ ,+ 3poi, List+.$emoveItem List+. ListIndex 1nd 8ac# 1nd .ub Sortarea listei Proprietatea .ortate este setat# la 3dev#rat, pentru a permite o list# s# apar# 0n ordine al"anumeric# i "alse pentru a a"i a elementele din list# 0n ordinea care sunt ad#ugate la lista. !tili#area com+o+ox An (omboBox combin# caracteristicile unui caset# text i un ListBox. 3cest lucru permite utilizatorului s# selecteze, "ie prin tastarea de text 0n caseta combo sau prin selectarea unui element din list#. 1xist# trei tipuri de stiluri (omboBox care sunt reprezentate dup# cum se arat# mai @os. (ombo vertical (ombo .imple List# vertical# !ertical# (ombo )stil =* (ombo .imple )stil +* Lista vertical# )stil <* (utia (ombo simplu a"i eaz# o zon# de editare cu o caset# list# acordat 0ntotdeauna vizibile imediat sub zona de editare. & caset# combo simplu a"i eaz# con inutul lista sa tot timpul. Atilizatorul poate selecta un element din list# sau tasta i un element 0n por iunea caseta de editare a casetei combo. & bar# de de"ilare se a"i eaz# l4ng# lista, dac# exist# prea multe elemente pentru a "i a"i ate 0n zona de caseta list#. Lista de valori (ombo apare pentru prima dat# ca doar o zon# de editare cu un buton s#geat# 0n @os, la dreapta. Por iunea Lista r#m4ne ascuns p4n# c4nd utilizatorul "ace clic pe butonul s#geat# 0n @os s# scad# 0n @os por iunea list#. Atilizatorul poate selecta o valoare din list# sau introduce i o valoare 0n zona de editare. 8ropdown caseta list# combo,se caseta combo 0ntr,o caset# list# vertical#. La momentul execu iei, controlul pare ca meniul derulant (ombo. Atilizatorul poate "ace i clic pe s#geata 0n @os pentru a vedea lista. 8i"eren a dintre 8ropdown (ombo si lista expandabila (ombo este c# zona de editare din list# (ombo este dezactivat. Atilizatorul poate selecta doar un element i nu poate introduce nimic 0n zona de editare. &ricum acest domeniu a"i eaz# elementul selectat. Exemplu 3cest exemplu este de a ad#uga, elimina, (lear lista de articole i aproape de "inal aplica ia. 8eschide un nou proiect .tandard 1\1 este deschis un nume Lormularul ca Listbox."rm i salva proiectul ca Listbox.vbp Proiectarea cererea a a cum se arat# mai @os. -+iect roprietate Setri 8ormular (aption Eume ListBox "rmListBox TextBox 9ext Eume )Pol* txtEame =a+el (aption Eume Introduce i un nume lblEame =istBox Eume lstEame =a+el (aption Eume .uma 0nscris# lbl3mount =a+el (aption Eume .til de "rontier# )Pol* lbl8ispla? + pat "ix )ommandButton (aption Eume 3dauga cmd3dd )ommandButton (aption Eume 1liminare cmd$emove )ommandButton (aption Eume (lear cmd(lear )ommandButton (aption Eume 1xit cmd1xit Arm#toarele proceduri eveniment sunt introduse pentru controalele 9extBox i (ommandButton. .ub Private txtEameW(hange )* Sn cazul 0n care )Len )txtEame.9ext*^ =*, atunci -3ctivarea butonul 3dd -Sn cazul 0n care cel pu in un caracter -1ste 0nscris cmd3dd.1nabled K 9rue 1nd 8ac# 1nd .ub .ub Private cmd3ddW(lic7 )* lstEame.3ddItem txtEame.9ext -3d#uga i introduse persona@ele la list# txtEame.9ext K -- - tergerea caseta de text txtEame..etLocus -Ia "ocalizarea 0napoi la -(aset# de text lbl8ispla?.(aption K lstEame.List(ount `3"i eaz# num#rul de elemente din lista cmd3dd.1nabled K Lalse `8ezactivarea butonul 3dd 1nd .ub 1venimentul clic pe butonul 3dd adaug# textul pentru caseta list# care a "ost introdus 0n caseta de text. 3poi, caseta text este ters, iar accentul este luat 0n caseta de text. Eum#rul de valorile introduse vor cre te 0n "unc ie de num#rul de articole ad#ugate la listbox. .ub Private cmd(learW(lic7 )* lstEame.(lear lbl8ispla?.(aption K lstEame.List(ount 1nd .ub .ub Private cmd1xitW(lic7 )* 8esc#rca i Me 1nd .ub .ub Private cmd$emoveW(lic7 )* 8im elimina (a Integer elimina K lstEame.ListIndex -Eo iuni de baz# indicele 8ac# remove^ K = 3poi, -asigura i,v# c# un element este selectat -Sn caseta list# lstEame.$emoveItem elimina -.coate i element din caseta list# lbl8ispla?.(aption K lstEame.List(ount `a"i a num#rul de articole -Sn listbox 1nd 8ac# 1nd .ub .coate i buton elimin# elementul selectat din lista de 0ndat# ce a i ap#sat butonul $emove. Eum#rul de articole este sc#zut 0n listbox, iar valoarea este a"i at# pe etichet#. (odul pentru butonul de clar terge listbox c4nd este ap#sat. i num#rul de elemente prezentate 0n eticheta devine =. ) descrca codul surs * !sing =istBox and )om+oBox )ontrols In (isual Basic E ListBox and (omboBox controls present a set o" choices that are displa?ed verticall? in a column. I" the number o" items exceed the value that be displa?ed, scroll bars will automaticall? appear on the control. 9hese scroll bars can be scrolled up and down or le"t to right through the list. 9he "ollowing Lig lists some o" the common )om+oBox properties and methods. ropert$LMet'od ,escription roperties Ena+led B? setting this propert? to 9rue or Lalse user can decide whether user can interact with this control or not Index .peci"ies the (ontrol arra? index =ist .tring arra?. (ontains the strings displa?ed in the drop,down list. .tarting arra? index is =. =ist)ount Integer. (ontains the number o" drop,down list items =istIndex Integer. (ontains the index o" the selected (omboBox item. I" an item is not selected, ListIndex is ,+ =ocDed Boolean. .peci"ies whether user can t?pe or not in the (omboBox Mouseointer Integer. .peci"ies the shape o" the mouse pointer when over the area o" the (omboBox 1e>Index Integer. Index o" the last item added to the (omboBox. I" the (omboBox does not contain an? items , EewIndex is ,+ Sorted Boolean. .peci"ies whether the (omboBox`s items are sorted or not. St$le Integer. .peci"ies the st?le o" the (omboBox`s appearance Ta+Stop Boolean. .peci"ies whether (omboBox receives the "ocus or not. Text .tring. .peci"ies the selected item in the (omboBox ToolTipIndex .tring. .peci"ies what text is displa?ed as the (omboBox`s tool tip (isi+le Boolean. .peci"ies whether (omboBox is visible or not at run time Met'ods /ddItem 3dd an item to the (omboBox )lear $emoves all items "rom the (omboBox *emo"eItem $emoves the speci"ied item "rom the (omboBox Set8ocus 9rans"ers "ocus to the (omboBox E"ent rocedures )'ange (alled when text in (omboBox is changed ,rop,o>n (alled when the (omboBox drop,down list is displa?ed Mot8ocus (alled when (omboBox receives the "ocus =ost8ocus (alled when (omboBox loses it "ocus /dding items to a =ist It is possible to populate the list at design time or run time ,esign Time : 9o add items to a list at design time, clic7 on List propert? in the propert? box and then add the items. Press (9$LF1E91$ a"ter adding each item as shown below. *un Time B 9he 3ddItem method is used to add items to a list at run time. 9he 3ddItem method uses the "ollowing s?ntax. &b@ect.3ddItemitem, Index 9he item argument is a string that represents the text to add to the list 9he index argument is an integer that indicates where in the list to add the new item. Eot giving the index is not a problem, because b? de"ault the index is assigned. Lollowing is an example to add item to a combo box. 9he code is t?ped in the LormWLoad event Private .ub LormWLoad)* (ombo+.3ddItem + (ombo+.3ddItem < (ombo+.3ddItem : (ombo+.3ddItem B (ombo+.3ddItem G (ombo+.3ddItem ; 1nd .ub *emo"ing Items from a =ist 9he $emoveItem method is used to remove an item "rom a list. 9he s?ntax "or this is given below. &b@ect.$emoveItem index 9he "ollowing code veri"ies that an item is selected in the list and then removes the selected item "rom the list. Private .ub cmd$emoveW(lic7)* I" List+.ListIndex ^ ,+ 9hen List+.$emoveItem List+. ListIndex 1nd I" 1nd .ub Sorting t'e =ist 9he .orted propert? is set to 9rue to enable a list to appear in alphanumeric order and Lalse to displa? the list items in the order which the? are added to the list. !sing t'e )om+oBox 3 (omboBox combines the "eatures o" a 9extBox and a ListBox. 9his enables the user to select either b? t?ping text into the (omboBox or b? selecting an item "rom the list. 9here are three t?pes o" (omboBox st?les that are represented as shown below. 8ropdown combo .imple combo 8ropdown list 8ropdown (ombo )st?le =* .imple (ombo )st?le +* 8ropdown List )st?le <* 9he .imple (ombo box displa?s an edit area with an attached list box alwa?s visible immediatel? below the edit area. 3 simple combo box displa?s the contents o" its list all the time. 9he user can select an item "rom the list or t?pe an item in the edit box portion o" the combo box. 3 scroll bar is displa?ed beside the list i" there are too man? items to be displa?ed in the list box area. 9he 8ropdown (ombo box "irst appears as onl? an edit area with a down arrow button at the right. 9he list portion sta?s hidden until the user clic7s the down,arrow button to drop down the list portion. 9he user can either select a value "rom the list or t?pe a value in the edit area. 9he 8ropdown list combo box turns the combo box into a 8ropdown list box. 3t run time , the control loo7s li7e the 8ropdown combo box. 9he user could clic7 the down arrow to view the list. 9he di""erence between 8ropdown combo V 8ropdown list combo is that the edit area in the 8ropdown list combo is disabled. 9he user can onl? select an item and cannot t?pe an?thing in the edit area. 3n?wa? this area displa?s the selected item. Example 9his example is to 3dd , $emove, (lear the list o" items and "inall? close the application. &pen a new .tandard 1\1 pro@ect is opened an named the Lorm as Listbox."rm and save the pro@ect as Listbox.vbp 8esign the application as shown below. -+Ject ropert$ Settings 8orm (aption Eame ListBox "rmListBox TextBox 9ext Eame )empt?* txtEame =a+el (aption Eame 1nter a name lblEame =istBox Eame lstEame =a+el (aption Eame 3mount 1ntered lbl3mount =a+el (aption Eame Border .t?le )empt?* lbl8ispla? + Lixed .ingle )ommandButton (aption Eame 3dd cmd3dd )ommandButton (aption Eame $emove cmd$emove )ommandButton (aption Eame (lear cmd(lear )ommandButton (aption Eame 1xit cmd1xit 9he "ollowing event procedures are entered "or the 9extBox and (ommandButton controls. Private .ub txtEameW(hange)* I" )Len)txtEame.9ext* ^ =* 9hen `1nabling the 3dd button `i" atleast one character `is entered cmd3dd.1nabled K 9rue 1nd I" 1nd .ub Private .ub cmd3ddW(lic7)* lstEame.3ddItem txtEame.9ext `3dd the entered the characters to the list box txtEame.9ext K -- `(learing the text box txtEame..etLocus `Pet the "ocus bac7 to the `text box lbl8ispla?.(aption K lstEame.List(ount `8ispla? the number o" items in the list box cmd3dd.1nabled K Lalse ` 8isabling the 3dd button 1nd .ub 9he clic7 event o" the 3dd button adds the text to the list box that was t?ped in the 9ext box. 9hen the text box is cleared and the "ocus is got to the text box. 9he number o" entered values will is increased according to the number o" items added to the listbox. Private .ub cmd(learW(lic7)* lstEame.(lear lbl8ispla?.(aption K lstEame.List(ount 1nd .ub Private .ub cmd1xitW(lic7)* Anload Me 1nd .ub Private .ub cmd$emoveW(lic7)* 8im remove 3s Integer remove K lstEame.ListIndex `Petting the index I" remove ^K = 9hen `ma7e sure an item is selected `in the list box lstEame.$emoveItem remove `$emove item "rom the list box lbl8ispla?.(aption K lstEame.List(ount `8ispla? the number o" items `in the listbox 1nd I" 1nd .ub $emove button removes the selected item "rom the list as soon as ?ou pressed the $emove button. 9he number o" items is decreased in the listbox and the value is displa?ed in the label. 9he code "or the clear button clears the listbox when ?ou press it. 3nd the number o" items shown in the label becomes =. ) ,o>nload t'e source code * InputBox 8unc ia n (isual Basic E ((BE) 3"i eaz# un prompt 0ntr,o caset# de dialog, a teapt# ca utilizatorul s# introducere a textului sau "ace i clic pe un buton, i returneaz# un .tring care con ine con inutul casetei de text. ;n urma este un InputBox extins SintaxaB memor?Wvariable K InputBox )prompt# , title% , implicit%* memor?Wvariable este un tip de date variant#, dar de obicei este declarat ca ir de caractere, care accept# intrarea mesa@ de c#tre utilizatori. 3rgumentele sunt explicate dup# cum urmeaz#: rompt , expresie .tring a"i at ca mesa@ul din caseta de dialog. 8ac# prompt# este "ormat din mai mult de o linie, se poate separa liniile utiliz4nd constanta vb(rL" 1xpresie .tring a"i at 0n bara de titlu a casetei de dialog , titluK 8ac# omite i titlul, numele aplica iei este a"i at 0n bara de titlu default text , textul implicit care apare 0n c4mpul de introducere, unde utilizatorii pot "olosi ca intrare sau inten ionat sau poate modi"ica la mesa@ul pe care dori i s# introduce i. x:po#i ie i $:po#i ie , pozi ia sau coordonatele caseta de intrare. Arm#torul exemplu demonstreaz# utilizarea "unc iei InputBox a 8eschiderea unui nou proiect i de a salva "ormularul de InputBox."rm i salva proiectul ca InputBox.vbp a 8esign aplicarea a a cum se arat# mai @os. -+iect roprietate Setarea 8ormular (aption Eume 9est InputBox "rmInputBox =a+el (aption Eume 3 i introdus lbl+ =a+el (aption Eume Border.t?le )Pol* lbl< +,"ix .ingle )ommandButton (aption Eume &' cmd&' 8up# cod este 0nscris 0n cmd-.F)licD () eveniment .ub Private cmdo7W(lic7 )* 3ns 8im ca ir ans K InputBox )-Introduce i ceva pentru a "i a"i ate 0n eticheta-, -testare-, =* Sn cazul 0n care 3E. K -- 3tunci, lbl<.(aption K -Eici un mesa@- 3ltele lbl<.(aption K ans 1nd 8ac# 1nd .ub .alva i i rula aplica ia. 8e 0ndat# ce "ace i clic pe butonul &', ve i primi urm#torul InputBox 3ici am intrat 0n -2ello 6orld- 0n c4mpul de text. 8e 0ndat# ce "ace i clic pe &' de ie ire este prezentat# a a cum se arat# mai @os (,escrca codul surs) InputBox 8unction in (isual Basic E ((BE) 8ispla?s a prompt in a dialog box, waits "or the user to input text or clic7 a button, and returns a .tring containing the contents o" the text box. 8ollo>ing is an expanded InputBox S$ntax B memor?Wvariable K InputBox )prompt,title%,de"ault%* memor?Wvariable is a variant data t?pe but t?picall? it is declared as string, which accept the message input b? the users. 9he arguments are explained as "ollows: rompt , .tring expression displa?ed as the message in the dialog box. I" prompt consists o" more than one line, ?ou can separate the lines using the vb(rL" constant Title , .tring expression displa?ed in the title bar o" the dialog box. I" ?ou omit the title, the application name is displa?ed in the title bar default:text , 9he de"ault text that appears in the input "ield where users can use it as his intended input or he ma? change to the message he wish to 7e? in. x:position and $:position , the position or the coordinate o" the input box. Lollowing example demonstrates the use o" InputBox "unction a &pen a new pro@ect and save the Lorm as InputBox."rm and save the Pro@ect as InputBox.vbp a 8esign the application as shown below. -+Ject ropert$ Setting 8orm (aption Eame InputBox test "rmInputBox =a+el (aption Eame /ou entered lbl+ =a+el (aption Eame Border.t?le ) empt?* lbl< +,Lixed .ingle )ommandButton (aption Eame &' cmd&' Lollowing code is entered in cmd-.F)licD ( ) event Private .ub cmdo7W(lic7)* 8im ans 3s .tring ans K InputBox)-1nter something to be displa?ed in the label-, -9esting-, =* I" ans K -- 9hen lbl<.(aption K -Eo message- 1lse lbl<.(aption K ans 1nd I" 1nd .ub .ave and run the application. 3s soon as ?ou clic7 the &' button ?ou will get the "ollowing InputBox 2ere I have entered -2ello 6orld- in text "ield. 3s soon as ?ou clic7 &' the output is shown as shown below ( ,o>nload t'e source code ) *elated Topics MessageBox "unction in !isual Basic ; 8ate and 9ime Lunctions MessageBox 8unc ia n (isual Basic E ((BE) 3"i eaz# un mesa@ 0ntr,o caset# de dialog i a tepta i pentru ca utilizatorul s# "ace i clic pe un buton, i returneaz# un 0ntreg care indic# buton care utilizatorul a "#cut clic. ;n urma este un MessageBox extins SintaxaB MsgBox (rompt , icoane butoane F% , titlu&) memor$F"aria+le G MsgBox (prompte , icoane butoane F% , titlu&) romptB expresii .tring a"i at ca mesa@ul din caseta de dialog. Sn cazul 0n care constau prompt# a mai mult de o linie, se poate separa liniile utiliz4nd constanta "+r)r=fK Icoane H ButoaneB expresie numeric# care este suma valorilor care speci"ic# num#rul i tipul de butoane i pictogram# pentru a a"i a. TitluB 1xpresie ir a"i at 0n bara de titlu a casetei de dialog. 8ac# omite i titlu, numele aplica iei este plasat 0n bara de titlu. Icoane )onstant (aloarea ,escriere "+)ritical +; 3"i eaz# pictograma mesa@ critice "+2uestion :< 3"i are pictogram# de interogare de avertizare "+Exclamation BC Icon mesa@ de avertizare de a"i are "+Information ;B Icon in"orma ii de a"i are Butoane )onstant (aloarea ,escriere "+-D-nl$ = 3"i eaz# doar butonul &' "+-D)ancel + 3"i area &' i (ancel butoanele "+/+ort*etr$Ignore < 3"i area 3bort, $etr? i Ignore butoane "+0es1o)ancel : 3"i area 8a, Eu i anula butoane "+0es1o B 3"i area da i nu butoane "+*etr$)ancel G 3"i area $etr? i (ancel butoanele (alorile returnate )onstant (aloarea ,escriere "+-D + Butonul &' "+)ancel < Butonul 3nulare "+/+ort : 3bandona i Button "+*etr$ B Sncerca i din nou Button "+Ignore G Ignora i Button "+0es ; 8a Button "+1o I Eu Button ;n urma este un exemplu ilustrea# utili#area de casete de mesaJ I 8eschide un nou proiect i de a salva "ormularul de messageboxdemo."rm i salva proiectul ca messageboxdemo.vbp I 8esign aplicarea a a cum se arat# mai @os. -+iect roprietate Setarea 8ormular (aption Eume MessageBox8emo "rmMessageBox8emo =a+el (aption Eume lblEame Eume TextBox Eume 9ext txtEame )Pol* =istBox Eume lstEame )ommandButton (aption Eume 3dauga cmd3dd )ommandButton (aption Eume terge i cmd8elete )ommandButton (aption Eume 1xit cmd1xit 8up# cod este 0nscris 0n txtEameW(hange )* eveniment .ub Private txtEameW(hange )* 8ac# Len )txtEame.9ext*^ = atunci cmd3dd.1nabled K 9rue 1nd 8ac# 1nd .ub 8up# cod trebuie s# "ie introduse 0n cmd3ddW(lic7 )* eveniment .ub Private cmd3ddW(lic7 )* answer K MsgBox )-Eu vrei sa adaugi acest nume pentru caseta list#O-, vb1xclamation F vb/esEo, -3d#uga i (on"irm-* 8aca raspunsul K vb/es 3poi lstEame.3ddItem txtEame.9ext txtEame.9ext K -- txtEame..etLocus cmd3dd.1nabled K Lalse 1nd 8ac# 1nd .ub 8up# cod este 0nscris 0n cmd8eleteW(lic7 )* eveniment .ub Private cmd8eleteW(lic7 )* 8im elimina (a Integer elimina K lstEame.ListIndex 8ac# elimina i _= atunci MsgBox -nu este selectat un nume-, vbIn"ormation, -1roare- 3ltele answer K MsgBox )-.unte i sigur c# dori i s# terge i- V vb(rL" si -numele selectatO-, W vb(ritical F vb/esEo, -3vertisment-* 8aca raspunsul K vb/es 3poi 8ac# scoate i^ K = 3poi, lstEame.$emoveItem remove txtEame..etLocus MsgBox -numele selectat a "ost ters-, vbIn"ormation, -8elete (on"irmare- 1nd 8ac# 1nd 8ac# 1nd 8ac# 1nd .ub 8up# cod este 0nscris 0n cmd1xitW(lic7 )* eveniment .ub Private cmd1xitW(lic7 )* answer K MsgBox )-!rei s# renun iO-, vb1xclamation F vb/esEo, -(on"irm-* 8aca raspunsul K vb/es 3poi ."4r it 3ltele MsgBox -3c iunea anulat-, vbIn"ormation, -(on"irm- 1nd 8ac# 1nd .ub .alva i i rula aplica ia. Pute i observa di"eritele tipuri de tipuri de cutie de mesa@e sunt "olosite pentru a e"ectua o ac iune (,escrca codul surs) MessageBox 8unction in (isual Basic E ((BE) 8ispla?s a message in a dialog box and wait "or the user to clic7 a button, and returns an integer indicating which button the user clic7ed. 8ollo>ing is an expanded MessageBox S$ntax B MsgBox ( Prompt ,iconsFbuttons % ,title % ) memor$F"aria+le G MsgBox ( prompt , iconsF buttons% ,title% ) rompt B .tring expressions displa?ed as the message in the dialog box. I" prompt consist o" more than one line, ?ou can separate the lines using the "+r)r=f constant. Icons H Buttons B Eumeric expression that is the sum o" values speci"?ing the number and t?pe o" buttons and icon to displa?. Title B .tring expression displa?ed in the title bar o" the dialog box. I" ?ou omit title, the application name is placed in the title bar. Icons )onstant (alue ,escription "+)ritical +; 8ispla? (ritical message icon "+2uestion :< 8ispla? 6arning Huer? icon "+Exclamation BC 8ispla? 6arning message icon "+Information ;B 8ispla? in"ormation icon Buttons )onstant (alue ,escription "+-D-nl$ = 8ispla? &' button onl? "+-D)ancel + 8ispla? &' and (ancel buttons "+/+ort*etr$Ignore < 8ispla? 3bort, $etr? and Ignore buttons "+0es1o)ancel : 8ispla? /es, Eo and (ancel buttons "+0es1o B 8ispla? /es and Eo buttons "+*etr$)ancel G 8ispla? $etr? and (ancel buttons *eturn (alues )onstant (alue ,escription "+-D + &7 Button "+)ancel < (ancel Button "+/+ort : 3bort Button "+*etr$ B $etr? Button "+Ignore G Ignore Button "+0es ; /es Button "+1o I Eo Button 8ollo>ing is an example illustrates t'e use of message +oxes I &pen a new Pro@ect and save the Lorm as messageboxdemo."rm and save the Pro@ect as messageboxdemo.vbp I 8esign the application as shown below. -+Ject ropert$ Setting 8orm (aption Eame MessageBox8emo "rmMessageBox8emo =a+el (aption Eame lblEame Eame TextBox Eame 9ext txtEame ) empt? * =istBox Eame lstEame )ommandButton (aption Eame 3dd cmd3dd )ommandButton (aption Eame 8elete cmd8elete )ommandButton (aption Eame 1xit cmd1xit Lollowing code is entered in the txtEameW(hange ) * event Private .ub txtEameW(hange)* I" Len)txtEame.9ext* ^ = 9hen cmd3dd.1nabled K 9rue 1nd I" 1nd .ub Lollowing code has to be entered in the cmd3ddW(lic7 ) * event Private .ub cmd3ddW(lic7)* answer K MsgBox)-8o ?ou want to add this name to the list boxO-, vb1xclamation F vb/esEo, -3dd (on"irm-* I" answer K vb/es 9hen lstEame.3ddItem txtEame.9ext txtEame.9ext K -- txtEame..etLocus cmd3dd.1nabled K Lalse 1nd I" 1nd .ub Lollowing code is entered in the cmd8eleteW(lic7 ) * event Private .ub cmd8eleteW(lic7)* 8im remove 3s Integer remove K lstEame.ListIndex I" remove _ = 9hen MsgBox -Eo names is selected-, vbIn"ormation, -1rror- 1lse answer K MsgBox)-3re ?ou sure ?ou want to delete - V vb(rL" V -the selected nameO-,W vb(ritical F vb/esEo, -6arning-* I" answer K vb/es 9hen I" remove ^K = 9hen lstEame.$emoveItem remove txtEame..etLocus MsgBox -.elected name was deleted-, vbIn"ormation, -8elete (on"irm- 1nd I" 1nd I" 1nd I" 1nd .ub Lollowing code is entered in the cmd1xitW(lic7 ) * event Private .ub cmd1xitW(lic7)* answer K MsgBox)-8o ?ou want to TuitO-, vb1xclamation F vb/esEo, -(on"irm-* I" answer K vb/es 9hen 1nd 1lse MsgBox -3ction canceled-, vbIn"ormation, -(on"irm- 1nd I" 1nd .ub .ave and run the application. /ou can notice the di""erent t?pe o" message box t?pes are used to per"orm an action ( ,o>nload t'e source code ) =ucrul cu forme n (isual Basic E /spect de formulare Principala caracteristica a unui "ormular este bara de titlu pe care este a"i at legend# a "ormularului. La cap#tul din st4nga al barei de titlu este icoana meniului de comand#. 8ac# "ace i clic pe aceast# pictogram# se deschide Meniul de comand#. Maximiza i, Minimizarea i (lose butoane pot "i g#site pe partea dreapt# a "ormularului. L#c4nd clic pe aceste butoane 0ndepline te "unc ia asociat#. Ligura de mai @os ilustreaz# aspectul unui "ormular Meniul de control con ine urm#toarele comenzi: *estaurareB $estaureaz# un "ormular maximizat# la dimensiunea a "ost 0nainte de a "i maximizatJ disponibil# numai dac# "ormularul a "ost maximizat. MutareB Permite utilizatorului se mi c# Lormularul 0n @urul cu mouse,ul ,imensiuneB permite utilizatorului redimensioneaz# de control cu mouse,ul Minimi#areaB Minimizeaz# Lormularul Maximi#areaB Maximizeaz# Lormularul )loseB Snchide "ormularul Setarea 8ormularul Start:!p & aplica ie tipic# are mai mult de un singur "ormular. (4nd o aplica ie ruleaz# Lormularul principal este 0nc#rcat. Prin setarea propriet# ilor de proiect le poate controla ce "ormular trebuie a"i ate 0n start,up a cererii. Ligura de mai @os ilustreaz# "ereastra de proprietati de proiect. Sn mod implicit, !isual Basic sugereaz# i numele de prima "orm# a creat, atunci c4nd a 0nceput proiectul. ;ncrcare i descrcare formulare Sn scopul de a 0nc#rca i desc#rca "ormularele, 0nc#rcarea i desc#rcarea declara ii sunt "olosite. 8eclara ia de 0nc#rcare are urmatoarea sintaxa: Snc#rca i LormEame Iar declara ia Anload are urmatoarea sintaxa: 8esc#rca i LormEame !ariabila LormEame este numele "ormularului care urmeaz# s# "ie 0nc#rcate sau desc#rcate. .pre deosebire de 3"i are metoda care 0i pas# at4t de 0nc#rcare i a"i area "ormei, declara ia de sarcin# nu arat# "ormularul. 9rebuie s# suna i 3rat# metoda Lormularul de a a"i a pe des7top. /fi area i ascunderea 8ormulare 3rat# metod# este "olosit# pentru a a"i a un "ormular. Sn cazul 0n care "ormularul este 0nc#rcat, dar invizibil, .how metoda este "olosita pentru a aduce "ormularul de pe 9op orice alt# "ereastr#. Sn cazul 0n care "ormularul nu este 0nc#rcat#, spectacolul sarcinile metoda i apoi se a"i eaz#. .intaxa de spectacol metoda de Lormularului Mod de LormEame..how !ariabila LormEame este numele formularului, precum i modul de argument op ional determin# dac# "ormularul va "i modal sau nu. 3cesta poate avea una din sintaxa: I =,"#r# moduri )implicit* a +,Modal Lormularele "#r# moduri sunt "ormele normale. Lorme "#r# moduri interac ioneaz# cu utilizatorul i utilizatorul permis pentru a comuta la orice alt# "orm# de aplicare. Sn cazul 0n care nu se speci"ic# argumentul mod op ional, implicit modul este setat la "#r# moduri. Lormularele modale preia controlul total al cererii 0n cazul 0n care utilizatorul nu poate trece la orice alte "orme 0n aplicarea excep ia cazului 0n care "ormularul este 0nchis. An "ormular modal, ast"el, trebuie s# aib# un buton trage sau a unor mi@loace pentru a 0nchide "ormularul cu scopul de a reveni la "orma 0n care a "ost 0nc#rcat "ormularul de Modal. /scunderea 8ormulare 3scunde Metoda este "olosit# pentru a ascunde un "ormular. Arm#toarele este sintaxa 3scunde metoda. LormEame.2ide Pentru a ascunde un "ormular de la 0n propriul s#u cod, codul de mai @os poate "i utilizat. Me.2ide 9rebuie s# 0n elege i c# "ormele care sunt ascunse nu sunt desc#rcateJ ei r#m4ne 0n memorie i pot "i a"i ate instantaneu cu spectacolul metoda. (4nd un "ormular este ascuns, pute i accesa 0n continuare propriet# ile i codul acestuia. 8e exemplu, pute i modi"ica set#rile propriet# ilor sale de control sau sunati la orice "unc ii publice sub "orm#. Arm#torul este un exemplu ilustreaz# 3rat# metoda i declara ia Mode a 8eschide un nou proiect i de a salva proiectul Proiectarea cererea de mai @os -+iect roprietate Setarea 8ormular (aption Eume Lorm+ "rm+ 8ormular (aption Eume Lorm< "rm< 8ormular (aption Eume Lorm: "rm: =a+el (aption Eume Lace i clic pe un buton pentru a a"i a un "ormular Label+ (odul de mai @os este scris 0n Lace i clic cazul butoanele de comand# $ula i aplica ia. 8ac# "ace i clic pe butoanele va a"i a Lormulare respectiv. 8ar pute i vedea c# 0n cmd<W(lic7 )* 1venimentul suplimentar a "ost ad#ugat argument !bModal. Puteti vedea di"eren a dup# ce a a"i a "ormele, "#c4nd clic pe butoanele de comand#. Pute i observa c# nu pute i trece la orice alte "orme de aplicare, cu excep ia cazului 0n care 0nchide i Lorm:. (descrca codul surs) /flarea diferen a dintre !nload i /scunde metod Pentru a ti 0n ce const# di"eren a dintre Anload i ascunde metode, vom "ace un exemplu. 8eschide un nou proiect i de a salva proiectul. 8esena i dou# butoane cu privire la "orma i numele celor a a cum se arat# mai sus. Sn cazul 0n care "ace i clic pe butonul 2ide 8up# cod este 0nscris. Me.2ide Sn cazul clic pe butonul Anload urm#torul cod este 0nscris. 8esc#rca i Me .alva i proiectul i rula aplica ia. 8up# ce "ace i clic pe 2ide buton pute i s# re ine i c# Lormularul este invizibil, dar cererea este 0nc# 0n des"# urare. 8ar atunci c4nd "ace i clic pe butonul Anload se poate vedea c# aplica ia este 0nchis#. 9orDing >it' 8orms in (isual Basic E T'e /ppearance of 8orms 9he main characteristic o" a Lorm is the title bar on which the Lorm`s caption is displa?ed. &n the le"t end o" the title bar is the (ontrol Menu icon. (lic7ing this icon opens the (ontrol Menu. Maximize, Minimize and (lose buttons can be "ound on the right side o" the Lorm. (lic7ing on these buttons per"orms the associated "unction. 9he "ollowing "igure illustrates the appearance o" a Lorm 9he control menu contains the "ollowing commands : *estore : $estores a maximized Lorm to the size it was be"ore it was maximizedJ available onl? i" the Lorm has been maximized. Mo"e : Lets the user moves the Lorm around with the mouse Si#e : Lets the user resizes the control with the mouse Minimi#e : Minimizes the Lorm Maximi#e : Maximizes the Lorm )lose : (loses the Lorm Setting t'e Start:!p 8orm 3 t?pical application has more than a single Lorm. 6hen an application runs the main Lorm is loaded. B? setting the Pro@ect properties ?ou can control which Lorm is to be displa?ed in the .tart,Ap o" the application. Lollowing "igure illustrates the Pro@ect propert? window. B? de"ault, !isual Basic suggests the name o" the "irst Lorm created when the pro@ect started. =oading and !nloading 8orms In order to load and unload the "orms, Load and Anload statements are used. 9he Load statement has the "ollowing s?ntax : Load LormEame 3nd the Anload statement has the "ollowing s?ntax : Anload LormEame 9he LormEame variable is the name o" the Lorm to be loaded or unloaded. Anli7e the .how method which cares o" both loading and displa?ing the Lorm, the load statement doesn`t show the Lorm. /ou have to call the Lorm`s .how method to displa? it on the des7top. S'o>ing and 7iding 8orms .how method is used to .how a Lorm. I" the Lorm is loaded but invisible, the .how method is used to bring the Lorm on 9op ever? other window. I" the Lorm is not loaded, the .how method loads it and then displa?s it. .?ntax o" the .how method o" the Lorm LormEame..how mode 9he LormEame variable is the Lorm`s name , and the optional argument mode determines whether the Lorm will be Modal or not. It can have one o" the "ollowing s?ntax : I =,Modeless )de"ault* a +,Modal Modeless Lorms are the normal Lorms. Modeless Lorms interact with the user and the user allowed to switch to an? other Lorm o" the application. I" ?ou do not speci"? the optional mode argument, b? de"ault the mode is set to modeless. 9he Modal Lorms ta7es the total control o" the application where user cannot switch to an? other Lorms in the application unless the Lorm is closed. 3 modal Lorm, thus, must have a (lose button or some means to close the Lorm in order to return to the Lorm where the Modal Lorm was loaded. 7iding 8orms 9he 2ide method is used to hide a Lorm. 9he "ollowing is the s?ntax o" the 2ide Method. LormEame.2ide 9o hide a Lorm "rom within its own code, the "ollowing code can be used. Me.2ide /ou must understand that the Lorms that are hidden are not unloaded J the? remains in the memor? and can be displa?ed instantl? with the .how Method. 6hen a Lorm is hidden, ?ou can still access its properties and code. Lor instance, ?ou can change the settings o" its (ontrol Properties or call an? Public "unctions in the Lorm. 9he "ollowing is an example illustrates the .how method and Mode statement a &pen a new Pro@ect and save the Pro@ect 8esign the application as shown below -+Ject ropert$ Setting 8orm (aption Eame Lorm+ "rm+ 8orm (aption Eame Lorm< "rm< 8orm (aption Eame Lorm: "rm: =a+el (aption Eame (lic7 on a button to displa? a Lorm Label+ 9he "ollowing code is t?ped in the (lic7 event o" the command buttons $un the application. (lic7ing on the buttons will displa? the Lorms respectivel?. But ?ou can see that in the cmd<W(lic7) * event additionall? !bModal argument has been added. /ou can see the di""erence a"ter ?ou displa? the "orms b? clic7ing on the command buttons. /ou can notice that ?ou cannot switch to an? other Lorms in the application unless ?ou close the Lorm:. (,o>nload t'e source code) 8inding out t'e difference +et>een !nload and 7ide met'od 9o 7now what the di""erence is between Anload and 2ide methods we will do an example. &pen a new pro@ect and save the pro@ect. 8raw two buttons on the "orm and name those as shown above. In the clic7 event o" the 2ide button Lollowing code is entered. Me.2ide In the clic7 event o" the Anload button "ollowing code is entered. Anload Me .ave the pro@ect and run the application. &nce ?ou clic7 on 2ide button ?ou can note that the Lorm is invisible but the application is still running. But when ?ou clic7 on Anload button ?ou can see that the application is terminated.