This document discusses Visual Basic concepts like variable declaration and assignment, data types, operators, functions, and error handling. It provides examples of valid and invalid variable names, demonstrates declaring and assigning variables, calculates expressions, rewrites equations as Visual Basic statements, and determines whether code examples contain syntax, logical, or runtime errors. It tests understanding of Visual Basic fundamentals like scope, constants, keywords, and debugging tools.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
740 views7 pages
Chapter 3 Critical Thinking
This document discusses Visual Basic concepts like variable declaration and assignment, data types, operators, functions, and error handling. It provides examples of valid and invalid variable names, demonstrates declaring and assigning variables, calculates expressions, rewrites equations as Visual Basic statements, and determines whether code examples contain syntax, logical, or runtime errors. It tests understanding of Visual Basic fundamentals like scope, constants, keywords, and debugging tools.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7
Chapter 3 Critical Thinking
1a) List four legal identifier names.
Memes, length, height, mass b) List four illegal identifier names and explain why each is illegal. 5thfall (Cant have number in front) /num (Cant have symbol in front) &hat (Cant have symbol in front) George.bush (Cant have period, means something specific) 2a) In two statements, declare a variable named numCards and assign it the value 5. Dim numCards As Integer numCards = 5 b) In one statement, declare a variable names numCards and assign it the value 5. Dim numCards as Integer = 5 3a) What is the final value of yourNumber after the last statement executes? 13 b)What is the final value of youNumber after the last statement executes? 11 4) What is he primary purpose of a TextBox object? To obtain and use user input. 5) Why is the Val() function used in a statement that assigns the data from a text box to a numeric variable? If the textbox contains data that doesnt match the variable type, you would normally get an error; however, the Val() prevents this by converting the textbox data to a numeric value (which can be put with the variable type). 6a) What are labels near a text box called? A prompt. b) Why should text boxes have labels near them? So that you know what values to enter into the textbox. 7) Determine the appropriate data type for each of the following values: a) the number of basketballs in a department store. Integer b) the price of a basketball. Decimal c) the number of players on a basketball team Integer d) the average age of the players on a basketball team. Double e) whether a basketball player has received a jersey or not Boolean f) the first initial of a basketball players first name Character 8). a) Is the scope of value local or global? 0, because value is local and does not carry onto the 2 nd button b) What is shown in the label? Why? Value 9) What is the value of each of the following expressions? a) 10 / 5 * 4 8 b) 10 / 2 + 3 8 c) 6 Mod 3 + 4 4 d) 12 Mod 5 * 3 12 e) 12 Mod (5 * 3) 12 10) What is the result of the following expression ((x/10)Mod10) when x is 2005? When x is 1776? When x is 39? When x = 2005, 0. When x = 1776, 7 When x = 39, 3 11). a) the number of votes received by an election candidate Dim numboats As Integer b) the percentage of votes won by a candidate Dim percentage As Integer c) the first, middle, and last initials of an election candidate Dim Label As Character d) the year of the election Dim Year As Double 12) For each of the following determine if the code contains a syntax error, logical error, or runtime error, and then correct the code. a) Dim num = 6 Logical error, Dim num As Integer = 6 b) num = Value(Me.txtNum.Text) Syntax error, num = Val(Me.txtNum.Text) c) lblOutput = message Syntax error, lblOutput.text = message d) Logical error, change the Integer to Double e) Logical error, you must declare what numberTests is f) Logical error 13) What value is assigned to taxRate in the following statement if seven percent is typed in the txtTaxRate text box? taxRate = Val(Me.txtTaxRate.Text) 0 will show up if seven percent is typed in. 14) Write each equation as a visual basic assignment statement, assuming [pi] is a constant named PI a) A=lw A=L*W b) P=RC/N c) A = h * (b1 + b2) / N d) V = 4 / 3 * PI * r ^ 3 e) A=F+S+T/3 f) P=5*F/4*d^2 g) A=P+Prt A = P + Pr * t h) M = ( Pr * (1 + r) ^ n) / ((1 + r) ^ n 1) i) x = ( -b * (b ^ 2 4 * a * c)) ^ / (2 * a) 15) Rewrite the equations in parts a through h of question 14 to solve for the variable listed below and then write each equation as a visual basic assignment statement: a) l l=A/W b) R R = (P * N) C c) b1 b1 = (A * N / H) b2 d) r r = (V / (4/3 * PI)) ^ 1/3 e) T T = (A * 3) F T f) F F = 5 - P / (4 * d ^ 2) g) P P = Pr * t A 16) Determine if each of the following statements is true or false. If false, explain why. a) T b) F, only multiple variables with the same datat types can be declared in one statement. c) T d) F, it converts to a numeric value. e) T f) F, they are initialized to false. g) T h) T i) T j) F, that is only if they are global declarations. k) T l) F, keywords can not be used as variable identifiers. m) T n) T o) F, they are errors that are caused by statements that produce undesired results. p) F, run-time errors are not detected by the computer. q) F, the F8 key continues execution, not the right arrow.