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
What? Visual Basic is • A GUI • Graphics, tools, objects • An OOP – “*Object Oriented Programming” • Objects make the application. *Italics - Taken from Starting out with Visual Basic 2008 page 7
Visual Basic is a LOL it’s a GUI It is A GUI – Graphic User Interface Can create graphics for interaction Between User and application Interaction: Text boxes, radio buttons, and more Screen shot of Visual Basic’s Integrated Development Environment
Visual Basic is Object Oriented Objects to play around with Screen shot of VB tool box • It all begins with a web form… • 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
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).” *Italics - Taken from http://visualbasic.about.com/od/applications/a/whatisvb.htm
How do you code in Visual Basic? First 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 • Understand that each object has a class • Look to your right
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 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
Before and After… BEFORE… AFTER…
A class and its codesis like a teacher and its students Class and codes A teacher instructs his student on what to do Poor guy… • A class cannot function without 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.
Codes within classes are instances! • Instances are… • Data, string, procedures, events, calculations and etc. • They help make class work
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…” *Italics - Taken from Starting out with Visual Basic 2008 page 14
Prefixes help • Visual Basic detects prefixes • Here is why
Known prefix list • lbl = Label • txt = Text Box • cbo = Combo Box • btn = Button
To give an object a name • Go to Properties Window • Find Name • Type in value
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
Coding Part 2 – Assigning a Variable How to Give it a value • 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
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
What happened was • At the last slide lblDateString.Text gathered all the textual data of the other variables and placed them in one string.
Coding Part 3: Performing calculations • Operators: • + is addition • - is subtraction • *MOD gets remainder • / is *floating point division • \ is *Integer division • *^ is exponentiation • Examples Integer = 5 + 5; Integer = 5 MOD 5; (remainder shows) Integer = 5 / 5; *Italics -Taken from Starting out with Visual Basic 2008 page 122
Coding Part 4: Converting between variable types Conversion Example *Dim anInteger As Integer = 54 MsgBox (CStr(anInteger)) This will convert anInteger = 54 to output as a string “54” • Convert between items • Use a Ctype function *Italics -Taken from http://msdn.microsoft.com/en-us/library/8bzk8e8c%28v=VS.90%29.aspx
Coding Part 5: If…Then and If…Else…Then Statements Both statements are conditional statements 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 • 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
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)
Coding Part 6: The Case Statement Another condition statement Example 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 • There can be several options • However a condition must be met for one of them to work
How it works The code’s decision Here it is • User inputs hours taken • Then tuition will output base on a case • Typed-in 12 hours and checked International • International is Case 2 • Outputs $3,200
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
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.
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>.
FIN GOD DESERVES THIS GLORY I am thankful that He helped me persevere through this. Praise Jesus