Visual Basic By Leo Karlo Primero

29 Slides1.11 MB

Visual Basic By Leo Karlo Primero

What is Visual Basic? Understanding its foundation De facto standard Founded in 1987 by MSDN Competition with other languages Version 2.0 made it popular Went up to 6 until it was called BASIC.NET Newest version is Visual Basic 2010 4/18/2010 2

Visual Basic is What? A GUI – Graphics, tools, objects An OOP – “*Object Oriented Programming” – Objects make the application. 4/18/2010 *Italics - Taken from Starting out with Visual Basic 2008 page 7 3

Visual Basic is a GUI LOL it’s It is A GUI – Graphic User Interface Can create graphics for interaction Screen shot of Visual Basic’s Integrated Development Environment Between User and application Interaction: Text boxes, radio buttons, and more 4/18/2010 4

Visual Basic is Object Oriented Objects to play around with It all begins with a web form Screen shot of VB tool box – Then place in any object unto it A radio button, a text box, a progress bar, and anything They make application construction look so easy Visual Basic makes programming faster 4/18/2010 5

Don’t take my word for it Dan Mabbut, a BASIC language expert, said that “*excellent programs could be written faster and cheaper with Visual Basic than with any of those languages (C, C and Java).” 4/18/2010 *Italics - Taken from http://visualbasic.about.com/od/applicatio ns/a/whatisvb.htm 6

How do you code in Visual Basic? First Understand that each object has a class Look to your right 4/18/2010 This code is an example of a class Private Sub Form1 Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cboDistributorNo.Items.Add(100) cboDistributorNo.Items.Add(101) cboModelNo.Items.Add("puri-clear") cboModelNo.Items.Add("Envirn Safe") cboDistributorNo.SelectedIndex 0 cboModelNo.SelectedIndex 0 End Sub 7

What is a class? A class is a contemporary of an object It makes up the object – Underneath it are its codes Divided into subroutines Describes how the process work Main class is always at the top of the code What this codes does is to place the numbers into the cboDistributorNo.Items This can also be an option statement (rules of processing) You are going to see its output 4/18/2010 Private Sub Form1 Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cboDistributorNo.Items.Add(100) cboDistributorNo.Items.Add(101) cboModelNo.Items.Add("puri-clear") cboModelNo.Items.Add("Envirn Safe ") cboDistributorNo.SelectedIndex 0 cboModelNo.SelectedIndex 0 End Sub 8

Before and After BEFORE 4/18/2010 AFTER 9

A class and its codes is like a teacher and its students Class and codes A teacher instructs his student on what to do A class cannot function without Poor guy its codes A class name will appear first – But no functions It is an empty classroom with no activity The teacher is bored (no brain activity) A class needs codes to be active! – It will be bored like the teacher. 4/18/2010 10

Codes within classes are instances! Instances are – Data, string, procedures, events, calculations and etc. – They help make class work 4/18/2010 11

Coding part 1 – Naming conventions *“The first three letters of the name should be a lowercase prefix indicating the control’s type.“ Be serious about naming conventions No one wants a combo box to be called combName Preferably called cboDistributorNo. – It speaks to us “I am a cbo Distributor No. a combo box that distributes numbers ” 4/18/2010 *Italics - Taken from Starting out with Visual Basic 2008 page 14 12

Prefixes help Visual Basic detects prefixes Here is why 4/18/2010 13

Known prefix list lbl Label txt Text Box cbo Combo Box btn Button 4/18/2010 14

To give an object a name Go to Properties Window Find Name Type in value 4/18/2010 15

Coding Part 2 – Assigning a Variable A variable is an instance You must dim it first – Ex: Public Class frmTuitionCalc Dim ResidenceStatus As Integer – Then follow it up with an As statement 4/18/2010 16

it a valuea Variable CodingHow Partto2Give – Assigning To assign a value is simple – Ex: ResidenceStatus 0 You can do the same with a string – Ex: lblDateString.Text txtDayOfWeek.Text & ", " *What this does is that lblDateString.Text will have the same text as txtDayofWeek.Text If you see a “.” assume it connects to a property 4/18/2010 17

lblDateString.Text txtDayOfWeek.Text & ", " .Text is text property that will affect the highlighted area Here is the output of it to show you what I am talking about Look 4/18/2010 18

What happened was At the last slide lblDateString.Text gathered all the textual data of the other variables and placed them in one string. 4/18/2010 19

Coding Part 3: Performing calculations Operators: – – – – Examples is addition - is subtraction *MOD gets remainder / is *floating point division – \ is *Integer division – * is exponentiation 4/18/2010 Integer 5 5; Integer 5 MOD 5; (remainder shows) Integer 5 / 5; *Italics -Taken from Starting out with Visual Basic 2008 page 122 20

Coding Part 4: Converting between variable types Conversion Convert between items Use a Ctype function 4/18/2010 Example *Dim anInteger As Integer 54 MsgBox (CStr(anInteger)) This will convert anInteger 54 to output as a string “54” *Italics -Taken from http://msdn.microsoft.com/en-us/library/8 bzk8e8c%28v VS.90%29.aspx 21

Coding Part 5: If Then and If Else Then Statements Both statements are conditional statements Visual Basic is unique on this If Then is one condition is met If Else Then is if one condition is not met then another event will trigger 4/18/2010 Example Private Sub chkRush Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkRush.Click If chkRush.Checked Then rbtUPS.Enabled True rbtSpecialCarrier.Enabled True Else rbtUPS.Enabled False rbtSpecialCarrier.Enabled False End If End Sub 22

Here is how it works Before After The code implies that if chkRush.Checked True(Rush Order is checked) then rbtUPS (UPS radio button) and rbtSpecialCarrier (Special Carrier radio button) will be enabled (made usable) 4/18/2010 23

Coding Part 6: The Case Statement Another condition statement Example There can be several options However a condition must be met for one of them to work Private Sub rbtInternational Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbtInternational.Click ResidenceStatus 2 End Sub Case Is 12 Select Case ResidenceStatus Case 0 Tuition 1500 Case 1 Tuition 2300 Case 2 Tuition 3200 End Select *NOTE: This is a shortened version of the actual code 4/18/2010 24

How it works The code’s decision User inputs hours taken Then tuition will output base on a case Typed-in 12 hours and checked International Here it is – International is Case 2 Outputs 3,200 4/18/2010 25

My view on Visual Basic I find it faster to finish applications but it takes time to learn. The community is quite active – There are people helping each other online I find it to be very reliable A programmer can decide how to tighten his application’s security – I have a template that has a log-in feature MSDN is still maintaining it with bug fixes and updates – As long as the user downloads them When anyone needs help with Visual Basic he can ask help from MSDN Visual Basic has its own Online Help Visual Basic’s history has shown me that MSDN still updates it and even changes VB’s external and internal structures. Visual Basic’s unique features made it an all-around programming language – Besides Programmers coded VB’s codes to create advanced applications One major downside is that it does not focus on actual programming – People may not be programmers to use Visual Basic 4/18/2010 26

Outcome for Visual Basic So far for what I see Visual Basic is persistent and may last for a very long time. I believe that after it fixes up its problems Visual Basic will still have a lot of customers that are willing to quickly make applications. 4/18/2010 27

Works Cited Gaddis, Tony, and Kip Irvine. Starting out with Visual Basic 2008. Fourth. Boston: Pearson Education, Inc., 2008. 7. Print. Gaddis, Tony, and Kip Irvine. Starting out with Visual Basic 2008. Fourth. Boston: Pearson Education, Inc., 2008. 14. Print. Gaddis, Tony, and Kip Irvine. Starting out with Visual Basic 2008. Fourth. Boston: Pearson Education, Inc., 2008. 122. Print. n.p., "Closer Look: Converting from One Variable Type to Another." MSDN.Microsoft.com. MSDN, n.d. Web. 18 Apr 2010. http://msdn.microsoft.com/en-us/library/8bzk8e8c %28v VS.90%29.aspx Mabbut, Dan. "What is Visual Basic?." VisualBasic.About.com. About.com, n.d. Web. 18 Apr 2010. http://visualbasic.about.com/od/applications/a/whatisvb.htm . 4/18/2010 28

FIN GOD DESERVES THIS GLORY I am thankful that He helped me persevere through this. Praise Jesus 4/18/2010 29

Back to top button