visual basic programming by victor mavhiki
-
Upload
victor-mavhiki -
Category
Documents
-
view
234 -
download
0
Transcript of visual basic programming by victor mavhiki
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 1/15
Victor Mavhiki
Question 1
An application to accept a character from the keyboard and display whether it is avowel or not.
output
PublicClassfrm_vowelCheck
'Declarin VariablesDim c AsChar
Private!ubbtn_check_Click"sender As#b$ect% e As&ventArs(andlesbtn_check.Click
'Assinin characters to the te)tbo)
c * t)t_char.+e)t
'Displayin &rror Messae if numeric or characters are entered,f ,s-umeric"t)t_char.+e)t +henMessaeo).!how"/Please &nter an Alphabetical 0etter/% /+his is not anAlphabetical letter/
'Clearin the te)tbo)es after the &rror messae displayedt)t_result.Clear"
1234 514 621 Pae 7
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 2/15
Victor Mavhiki
t)t_char.Clear"
&lse,f c * /A/#r c * /&/#r c * /,/#r c * /#/#r c * /8/ +hen
'Displayin te)t /V#9&0/ in the te)tbo) if a vowel is enteredt)t_result.+e)t * /V#9&0/
&lse,f c * /a/#r c * /e/#r c * /i/#r c * /o/#r c * /u/ +hen
'Displayin te)t /V#9&0/ in the te)tbo) if a vowel is enteredt)t_result.+e)t * /V#9&0/
&lse'Displayin te)t /-#+ V#9&0/ in the te)tbo) if a non:vowel letter is entered
t)t_result.+e)t * /-#+ V#9&0/&nd,f &nd!ub
Private!ubbtn_clear_Click"sender As#b$ect% e As&ventArs(andlesbtn_clear.Click'Clear the te)tbo)est)t_char.Clear"t)t_result.Clear"&nd!ub
Private!ubbtn_e)it_Click"sender As#b$ect% e As&ventArs(andlesbtn_e)it.Click'&ndin the operations&nd&nd!ub
&ndClass
1234 514 621 Pae 4
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 3/15
Victor Mavhiki
Question 2
An application to accept a strin and convert the case of characters.
Output
PublicClassfrm_caseConv
'declarin variablesDimte)As!trin
Private!ubbtn_convert_Click"sender As#b$ect% e As&ventArs(andlesbtn_convert.Click
'Assinin strin to the te)tbo)te) * t)t_char.+e)t
'Displayin &rror messae if numeric data is entered,f ,s-umeric"t)t_char.+e)t +henMessaeo).!how"/Please &nter characters/%/+his is numeric/
'Clearin the te)tbo)es after the &rror messae displayedt)t_char.Clear"t)t_con.Clear"
1234 514 621 Pae ;
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 4/15
Victor Mavhiki
&lse,f t)t_char.+e)t * 0Case"t)t_char.+e)t +hen
'Convertin strin to upper caset)t_con.Append+e)t"8Case"t)t_char.+e)t
&lse,f t)t_char.+e)t * 8Case"t)t_char.+e)t +hen
'Convertin strin to lower caset)t_con.Append+e)t"0Case"t)t_char.+e)t&nd,f &nd!ub
Private!ubbtn_clear_Click"sender As#b$ect% e As&ventArs(andlesbtn_clear.Click
'Clearin the te)tbo)es as initiated by the button Cleart)t_con.Clear"t)t_char.Clear"
&nd!ub
Private!ubbtn_e)it_Click"sender As#b$ect% e As&ventArs(andlesbtn_e)it.Click
'end all operatios or Close&nd&nd!ub
&ndClass
1234 514 621 Pae 5
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 5/15
Victor Mavhiki
Question 5
An application to pick a date from a calendar control and display the day% month%year in separate te)tbo)es.
Output
PublicClassfrm_calender
Private!ub Date+imePicker7_ValueChaned"sender As#b$ect% e As&ventArs(andles Date+imePicker7.ValueChaned'assinin day's date to the te)bo) from date pickert)t_date.+e)t * Date+imePicker7.Value.Day
'assinin day of the week to the te)bo) from date picker
1234 514 621 Pae <
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 6/15
Victor Mavhiki
t)t_day.+e)t * Date+imePicker7.Value.Day#f9eek.+o!trin
'assinin month to the te)bo) from date pickert)t_month.+e)t * Date+imePicker7.Value.Month
'assinin year to the te)bo) from date pickert)t_year.+e)t * Date+imePicker7.Value.=ear&nd!ub
Private!ubbtn_clear_Click"sender As#b$ect% e As&ventArs(andlesbtn_clear.Click'clearin date te)bo)t)t_date.Clear"
'clearin day te)bo)t)t_day.Clear"
'clearin month te)bo)t)t_month.Clear"
'clearin year te)bo)t)t_year.Clear"&nd!ub
Private!ubbtn_e)it_Click"sender As#b$ect% e As&ventArs(andlesbtn_e)it.Click
'&nd the proram&nd
&nd!ub
&ndClass
1234 514 621 Pae 6
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 7/15
Victor Mavhiki
Question 4
A case select construct application to implement the calculator with memory andrecall operations.
Output
PublicClassfrm_calculator
'Delarin VariablesDim a% m As,nteerDim#ptnAsChar
Private!ubbtn_one_Click"sender As#b$ect% e As&ventArs(andlesbtn_one.Click
'Assinin the value /7/ to the te)tbo)t)t_operaations.Append+e)t"/7/&nd!ub
1234 514 621 Pae 2
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 8/15
Victor Mavhiki
Private!ubbtn_two_Click"sender As#b$ect% e As&ventArs(andlesbtn_two.Click
'Assinin the value /4/ to the te)tbo)t)t_operaations.Append+e)t"/4/&nd!ub
Private!ubbtn_three_Click"sender As#b$ect% e As&ventArs(andlesbtn_three.Click
'Assinin the value /;/ to the te)tbo)t)t_operaations.Append+e)t"/;/&nd!ub
Private!ubbtn_four_Click"sender As#b$ect% e As&ventArs(andlesbtn_four.Click
'Assinin the value /5/ to the te)tbo)t)t_operaations.Append+e)t"/5/&nd!ub
Private!ubbtn_>ve_Click"sender As#b$ect% e As&ventArs(andlesbtn_>ve.Click
'Assinin the value /</ to the te)tbo)t)t_operaations.Append+e)t"/</&nd!ub
Private!ubbtn_si)_Click"sender As#b$ect% e As&ventArs(andlesbtn_si).Click
'Assinin the value /6/ to the te)tbo)t)t_operaations.Append+e)t"/6/&nd!ub
1234 514 621 Pae 3
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 9/15
Victor Mavhiki
Private!ubbtn_seven_Click"sender As#b$ect% e As&ventArs(andlesbtn_seven.Click
'Assinin the value /2/ to the te)tbo)t)t_operaations.Append+e)t"/2/&nd!ub
Private!ubbtn_eiht_Click"sender As#b$ect% e As&ventArs(andlesbtn_eiht.Click
'Assinin the value /2/ to the te)tbo)t)t_operaations.Append+e)t"/3/&nd!ub
Private!ubbtn_nine_Click"sender As#b$ect% e As&ventArs(andlesbtn_nine.Click
'Assinin the value /?/ to the te)tbo)t)t_operaations.Append+e)t"/?/&nd!ub
Private!ubbtn_@ero_Click"sender As#b$ect% e As&ventArs([email protected]
'Assinin the value /1/ to the te)tbo)t)t_operaations.Append+e)t"/1/&nd!ub
Private!ubbtn_add_Click"sender As#b$ect% e As&ventArs(andlesbtn_add.Click
a * Val"t)t_operaations.+e)t'Assinin the #ption // to the te)tbo)#ptn * //t)t_operaations.Clear"&nd!ub
1234 514 621 Pae ?
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 10/15
Victor Mavhiki
Private!ubbtn_devide_Click"sender As#b$ect% e As&ventArs(andlesbtn_devide.Click
a * Val"t)t_operaations.+e)t'Assinin the #ption /B/ to the te)tbo)#ptn * /B/t)t_operaations.Clear"&nd!ub
Private!ubbtn_multiply_Click"sender As#b$ect% e As&ventArs(andlesbtn_multiply.Click
a * Val"t)t_operaations.+e)t'Assinin the #ption // to the te)tbo)#ptn * //t)t_operaations.Clear"&nd!ub
Private!ubbtn_subtract_Click"sender As#b$ect% e
As&ventArs(andlesbtn_subtract.Click
a * Val"t)t_operaations.+e)t'Assinin the #ption /:/ to the te)tbo)#ptn * /:/t)t_operaations.Clear"&nd!ub
Private!ubbtn_memory_Click"sender As#b$ect% e As&ventArs(andlesbtn_memory.Click
'Assinin the contents of the te)tbo) to the memory m * t)t_operaations.+e)tt)t_operaations.Clear"&nd!ub
1234 514 621 Pae 71
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 11/15
Victor Mavhiki
Private!ubbtn_recall_Click"sender As#b$ect% e As&ventArs(andlesbtn_recall.Click
'recallin what is in the memoryt)t_operaations.+e)t * m&nd!ub
Private!ubbtn_cancel_Click"sender As#b$ect% e As&ventArs(andlesbtn_cancel.Click
'cancellin the operations in the te)tbo)t)t_operaations.Clear"&nd!ub
Private!ubbtn_euals_Click"sender As#b$ect% e As&ventArs(andlesbtn_euals.Click
'selectin the operations / % :% % B/!electCase#ptnCase//t)t_operaations.+e)t * a Val"t)t_operaations.+e)tCase/:/t)t_operaations.+e)t * a : Val"t)t_operaations.+e)tCase//t)t_operaations.+e)t * a Val"t)t_operaations.+e)tCase/B/t)t_operaations.+e)t * a B Val"t)t_operaations.+e)t
&nd!elect&nd!ub
Private!ubbtn_e)it_Click"sender As#b$ect% e As&ventArs(andlesbtn_e)it.Click
'endin all the operations
1234 514 621 Pae 77
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 12/15
Victor Mavhiki
&nd&nd!ub&ndClass
Question 3
A menu based application to implement te)t editor with cut% copy% paste% save andclose operations.
Output
PublicClassEorm7
Private!ub Eorm7_0oad"sender As#b$ect% e As&ventArs (andlesMyase.0oad
'(idin the lable% te)tbo) and a button on the formlbl_saveAs.Visible * Ealset)t_te)t!ave.Visible * Ealse
btn_save.Visible * Ealse&nd!ub
Private!ubbtn_save_Click"sender As#b$ect% e As&ventArs (andlesbtn_save.Click
'(ide the button% lable and te)tbo) on the form after savin the te)trt)_te)t&nter.!aveEile"C!tr"t)t_te)tsave.+e)tlbl_saveAs.Visible * Ealse
1234 514 621 Pae 74
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 13/15
Victor Mavhiki
t)t_te)tsave.Visible * Ealsebtn_save.Visible * Ealse&nd!ub
Private!ub!ave+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andles!ave+ool!tripMenu,tem.Click
'unhide the lable% te)tbo) and a button on the formlbl_saveAs.Visible * +ruet)t_te)t!ave.Visible * +ruebtn_save.Visible * +rue&nd!ub
Private!ub-ew+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs (andles-ew+ool!tripMenu,tem.Click
'Clearin the richte)tbo)rt)_te)t&nter.Clear"&nd!ub
Private!ubCopy+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andlesCopy+ool!tripMenu,tem.Click
'copyin the te)t in the richte)tbo)rt)_te)t&nter.Copy"&nd!ub
Private!ubCut+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andlesCut+ool!tripMenu,tem.Click
'cut the te)t in the richte)tbo)rt)_te)t&nter.Cut"&nd!ub
1234 514 621 Pae 7;
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 14/15
Victor Mavhiki
Private!ubPaste+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andlesPaste+ool!tripMenu,tem.Click
'paste the te)t copied or cut form the richte)tbo)rt)_te)t&nter.Paste"
&nd!ub
Private!ub8ndo+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andles8ndo+ool!tripMenu,tem.Click
'undo the operationrt)_te)t&nter.8ndo"&nd!ub
Private!ubFedo+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andlesFedo+ool!tripMenu,tem.Click
'redo the operationrt)_te)t&nter.Fedo"&nd!ub
Private!ub&)it+ool!tripMenu,tem_Click"sender As#b$ect% e As&ventArs(andles&)it+ool!tripMenu,tem.ClickMessaeo).!how"/Are you sure you want to e)it/% /Continue/&nd&nd!ub
Private!ub Close+ool!tripMenu,tem_Click_7"sender As#b$ect% e As&ventArs(andlesClose+ool!tripMenu,tem.Click
Messaeo).!how"/Are you sure you want to close/% /Continue/
'Clossin the oprations&nd&nd!ub
Private!ub -ew+ool!tripMenu,tem7_Click"sender As#b$ect% e As&ventArs(andles -ew+ool!tripMenu,tem7.Click
1234 514 621 Pae 75
7/23/2019 visual basic programming by victor mavhiki
http://slidepdf.com/reader/full/visual-basic-programming-by-victor-mavhiki 15/15
Victor Mavhiki
'Clearin the richte)tbo)rt)_te)t&nter.Clear"&nd!ub
&ndClass
1234 514 621 Pae 7<