|
Weekly Quiz Review Terms for Visual Basic, Professor Floyd Jay Winters
These terms will be the basis of ten 10-question quizzes given in the lab via Angel once a week. All questions are very short multiple choice
questions with very short answers.
Quiz 1 | Quiz 2 | Quiz 3 | Quiz 4 | Quiz 5 | Quiz 6 | Quiz 7 | Quiz 8 | Quiz 9 | Q 10
Properties, objects, toolbox, “pegging” toolbox, form, frm, label, lbl, textbox, txt, button, btn, resetting the VB Windows layout, .sln, .vb, .exe, bin, Sub procedure Private Sub btnCalcPay_Click(ByVal sender As System.Object, ... lblCalcPay.Text = txtHours.Text * txtRate.Text End Sub
Object (ex: form, button, textbox), Class (pattern with properties and methods), Property, Method (object action), Event (user action), Procedure (code), comments/remarks (‘), null (“”), breakpoints, autosize, Val, Dim (Previously “Dimension” to declare or define a variable) lblCalcPay.Text = Val(txtHours.Text) * Val(txtRate.Text) OR Dim TotalInvoice As Decimal Dim TaxAmount As Decimal Dim TaxRate As Decimal = 0.07 Dim Tax As Decimal TotalInvoice = Val(txtPrice.text) * Val(txtQuantity.text) Tax = TotalInvoice * TaxRate lblCalcTotal.text = TotalInvoice
Dim (declare and initialize), Val, local/procedure scope: inside a Sub, module/global scope: after Class statement, defaults, null, lblCalcPay.Text = "", txtHours.Clear(), Numbers: right aligned, Hot key or Access key - ex: Exit (Text: E&xit), <, >, <=, < >, Hierarchy of math operations: ( ), ^, * /, + -, exponents
If / Then / Else / End IF, Nested If, Or (one condition is true), And (all conditions must be true), Validation, IsNumeric, MessageBox.Show(Prompt, Title/Caption, Buttons), MsgBox, Call, chkItem.Checked=True, FormatCurrency(x), FormatNumber(x,2), Format(X, "$##,##0.00"), Format(Now(), "Long Date"), Try / Catch / End Try, Region, ASCII values for Return (13), Space (32 decimal or 20 in Hex), Quote (34), 0 (48), A (65), a (97)
A loop is a programming structure which allows repetitive processing. For Next Loops work best when you know exactly how many times you will loop. For Next Loops automatically increment the Loop Counter The first line in a For Next Loop is For X; the last line is Next X For next Loops require less lines of code because the counter is automatically incremented Dim Count As Integer For Count = 1 To 10 ' Pretest - Evaluate befor execute lblFor.Text += Count & vbCrLf ' display new value of X, followed by Return Next Count
To count backwards: For Count = 10 To 1 Step -1 You can use variables: For Count = 1 To Months * 12
Do While loops work well with unknown ending Do While loops are PreTest Loops Do While loops require more code than For Next Loops, because of the need to create, initialize, and increment a counter. But they can be more dynamic. They begin with Do Until and end with the command Loop Dim Count As Integer = 0 ' Notice Count is Initialized at 0 Do While Count < 10 ' Pretest - Evaluate befor execute Count += 1 ' Notice in this case the counter is placed before the main code lblWhile.Text += Count & vbCrLf ' display new value of X, followed by Return Loop
Do Until Loops are PostTest Do Until Loops require more code than For Next Loops, because of the need to create, initialize, and increment a counter. But they can be more dynamic. Dim Count As Integer = 0 ' Notice Count is Initialized at 0 Do Until Count = 10 ' PostTest: always executes at least once Count += 1 ' Notice counter is placed before the main code lblUntil.Text += Count & vbCrLf ' display new value of X, followed by Return Loop
VB Quiz 6 Counters and Accumulators counter (Count +=1), increment, decrement, subtotal, GrandTotal, accumulator (Ex: GrandTotal +=Total), defining, initializing, variable types: integer or decimal?, also know concatenation &
' An Array can hold a list (or collection) of related objects (or values or data items) that have the same data type and are loaded in to a single variable ' Instead of Month1, Month2, Month3... (three objects) ' You have Month(1), Month(2), Month(3)... (one object) ' The above is read Month "sub" 1, Month "sub" 2, Month "sub" 3 ' An index or subscript is a second variable that is used to refer to the numerous related values by the same name. ' The individual values are called the elements of the array. ' An array is kind of like having one egg carton that holds 12 eggs, instead of having 12 individual mini egg cartons. ' In reality, instead of being cubby holes in an egg carton, an Array consists of cubby holes in RAM memory. ' Arrays are really handy when you have large files where it would be impossible to have thousands of individually named variable. ' Note: the first subscript in an array is sub(0), followed by sub(1), sub(2)...
' Statically define a 1 Dimensional array with 1 element or column (or 1 row) using only 1 index Dim Months As String() = {"Jan", "Feb", "Mar"} ' Define and initialize array Dim Num As Integer() = {1, 2, 3}
' OR you could do the following: Dim Month(12) As String ' You could actually do Month(11) because an array starts at 0 Month(1) = "Jan" ' Month "sub" 1 Month(2) = "Feb" ' Month "sub" 2
' If you know how many items are in an array, you can display or write all the items with a Loop For X = 1 To
Count ' X becomes 1, then X becomes 2, then 3...
= = =
You might declare a two-dimensional array (with rows and columns) with 12 rows (for the months) and 31 columns (for the days), using 2 indices. Note because the first subscript is 0 and not 1 the array out limit is 11 for months and 30 for days. (Although an array can have as many as 32 dimensions, it is rare to have more than three.) Dim Months(11) As String ' Above is a 1 dimensional array: 12 rows all in 1 column Dim salesAmounts(11, 30) As Double ' Above is a 2 dimensional array: 12 rows in 31 columns Dim salesAmounts(11, 30, 10) As Double ' Above is a 3 dimensional array: 12 months, 31 days, and a depth of 10 years = = = You can build your own Array to store each record added to your form: Dim Description(1000) As String Dim Quantity(1000) As Integer Dim rc As Integer ' Record Counter to increment the subscript Private Sub btnStoreRecord_Click... rc += 1 Description(rc) = txtDescription.Text ' “Description sub rc” Quantity(rc) = CInt(txtQuantity.Text) ' Store all relevant fields in array; Use an Accumulator to keep running totals ' Use a loop or listbox to display the Array. Ex: For X = 1 to rc ' Ex: ListBoxShowArray.Items.Add(Description(rc) & ControlChars.Tab & Quantity(rc)) End Sub
txtTotal.Text = FormatCurrency(txtTotal.Text) ' Defaults to two places txtAmt.Text = FormatNumber(txtAmt.Text, 1) txtAmt.Text = FormatNumber(txtAmt.Text, 3) ' 3 possible insignificant 0s txtAmt.Text = FormatPercent(txtAmt.Text, 2) txtAmt.Text = txtAmt.Text.ToString(“c”) ' Currency (Type . and pick choice) txtAmt.Text = Format(Val(txtAmt.Text), "$##,##0.00") ' The above is a Custom format. 0 means a 0 will be displayed as a place holder for insignificant 0s. Ex: .3 would produce $0.30 txtAmt.Text = Format(txtAmt.Text, "0.0%")' If txtAmt=1, the result is 100.0% txtBox7.Text = Format(Now(), "Long Date") txtBox8.Text = Format(Now(), "hh:mm tt") txtBox9.Text = Format(Now(), "MMM. dd, yyyy HH:mm:ss") ' 24 hour time lblToday.Text = FormatDateTime(Today, DateFormat.ShortDate) lblToday.Text = Format(Today.ToShortDateString) ' Type . and pick choice
= = = DateTimePicker1.Format = DateTimePickerFormat.Custom DateTimePicker1.CustomFormat = "MMM. dd, yyyy"
= = = Dim strToday As String = Today().ToString(“d”) ' Short date format Dim strToday As String = Today().ToString(“D”) ' Long date format
Dim datPayDate As Date datPayDate = CDate(txtDate.Text) txtDate.Text = Format(datPayDate, "MM-dd-yy")
= = = Dim fmtStr As String = "{0, -15}{1, 6:N1}{2, 10:C2}" ' 0, 1, 2 = Print Zones, 15, 6, 10 = Zone Widths, - means left justify ' N1 = format as Number 1 place, C2 = format as Currency 2 places Dim LastName As String = "Fitzgerald" Dim Hours As Integer = 40 : Dim Rate As Decimal = 10 ListBox1.Items.Add(String.Format(fmtStr, LastName, Hours, Rate)) ' Output: Fitzgerald 40.0 $10.00
Also Know for Format Quiz: txtItem.Text.ToUpper txtItem.Text.Length txtItem.Text.Substring(2, 3) txtItem.Text.Substring(0, 3) ' 0 is the first position txtItem.Text.Trim
VB Quiz 9 Microsoft Access and database terms See: 0ClassFolders/2171VB/DataBases/SamplePayrollReportAndTerms.gif Know: Database, Table, Record, Field, Data/Field Types, Primary/Key field, Rows, Columns, Reports, Header, Detail, Report Footer, Text File, CSV (Comma Separated Value), Delimited text file, Fixed Width text file. Related Tables: Linked by Key fields such as the Primary key ProductID in the [Products] Table being linked to the Foreign key ProductID in the [Invoices] table so that the Products.Description and Products.Price can be obtained. Access Queries are written in SQL – see below.
VB Quiz 10 SQL - Structured Query Language Select (Get Fields), From (Get Table), Where (Criteria – what you are searching for), As (Create an Alias that can also be used for a calculated value), OrderBy (Sort), Join (Link related tables) Related Tables: Linked by Key fields such as the Primary key SocSec in the [Employees] Table being linked to the Foreign key SocSec in the [Employees Weekly] table so that the Employees.LastName and Employees.FirstName can be obtained. Sample SQL Code from a Microsoft Access Query: SELECT [Employees Weekly].WeekEnding, Employees.LastName, Employees.FirstName, [Employees Weekly].SocSec, [Employees Weekly].HoursWorked, [Employees Weekly].PayRate, [HoursWorked]*[PayRate] AS Pay FROM Employees INNER JOIN [Employees Weekly] ON Employees.SocSec = [Employees Weekly].SocSec WHERE ((([Employees Weekly].HoursWorked)>=40)) ORDER BY [Employees Weekly].WeekEnding; |