Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepred By: Deborah Becker

Similar presentations


Presentation on theme: "Prepred By: Deborah Becker"— Presentation transcript:

1 Prepred By: Deborah Becker
VB STRINGS Chapter 3.4 Dale Carnegie Training® can help you manage the sweeping changes that continue to reshape the workplace. Organizations today need managers who are knowledgeable business partners skilled at managing change. As change agents, managers can play a vital role in helping their organizations remain competitive. Rely on the following process, and you will be more effective in managing organizational change. Be sure you have earned the right to deliver this program, are excited about the topic, and are eager to share with your audience. Speak from your own experiences. Set a good example. Help others benefit from what you have learned about managing organizational change. 1/2/2019 Prepred By: Deborah Becker

2 Prepred By: Deborah Becker
What is a string? A String Constant is a sequence of characters that is treated as a single item. A string’s content can be altered with an assignment statement It can be displayed using the print statement It can be combined using the & symbol Start by articulating a clear vision of what your organization should be. Present the vision clearly, and explain why it is important for your organization to achieve this vision. Include a picture of the leadership skills this vision will require. For example, global thinking, strategic partnering, etc. 1/2/2019 Prepred By: Deborah Becker

3 Prepred By: Deborah Becker
String Variables A name used to refer to a string (DATA ELEMENTS IN A FILE). Allowable naming conventions are the same for string and numeric variables Once you’ve communicated where you want to go, estimate how close you are to achieving the vision. Identify strengths of the organization. Also note areas where improvements must be made to bring you closer to the vision. Be sure to include the “As Is” of leadership strengths and areas for improvement. Organizations don’t change, people do. 1/2/2019 Prepred By: Deborah Becker

4 Naming Rules and Conventions
Identifier type Prefix Identifier (name) 1 to 255 characters Can use Letters, digits, underscores Cannot use spaces, or reserved words (Print, Name, Value, Sub, etc.) Naming convention requires: 1) Identifier is meaningful -- A name that indicates the purpose 2) Begins with lowercase prefix specifying data type   Starting with VB 6.0 the lowercase prefixes are now three letters as per the Microsoft MSDN Library e.g., str  for string int  for integer cur  for currency For variables, capitalize each word of name after prefix e.g.,          curHoursWorked For constants, use full uppercase and underscore e.g.,          curMINIMUM_WAGE strSocialSecurityNumber strLastName strAddress strCOMPANY_NAME (constant) 1/2/2019 Prepred By: Deborah Becker

5 Prepred By: Deborah Becker
Naming Conventions bln Boolean cur Currency dbl Double dtm Date int Integer lng Long sng Single str String vnt Variant (default) Refer back to your naming conventions handout. Two types of variable can be string– string and variant 1/2/2019 Prepred By: Deborah Becker

6 Which of these examples follow the naming rules?
strSub Caption conMaximum MinimumRate curMaximumCheck strCompanyName omitted int#Sold i Number Sold int.Number.Sold sng$Amount Sub 1/2/2019 Prepred By: Deborah Becker

7 Which of these examples follow the naming rules?
7. strSub 8. Caption 9. conMaximum 10. MinimumRate 11. curMaxCheck 12. strCompanyName omitted int#Sold i Number Sold int.Number.Sold sng$Amount Sub Does not indicate the data type Cannot contain special characters such as # No Blank spaces are allowed within an identifier The periods separate items like objects and properties and should not be used in a variable name Cannot contain special characters like $ Sub us a reserved word in Visual Basic Valid name. May not be a meaningful name Caption is a property name and therefore a reserve word Follows the naming rules but not the convention. A prefix should be used to indicate the data type. A prefix should be used to indicate the data type Valid 1/2/2019 Prepred By: Deborah Becker

8 Identify these variable types
dtmStoreHours curSalary strLastName blnPrerequisite vntFirstName sgnPayRate lngCityPopulation 1/2/2019 Prepred By: Deborah Becker

9 If a Variable is in Scope
When an identifier is in scope you cans read and set it’s values If it is out of scope you will not be able to access it Global variables are in scope from any where with in your program Modular variable are in scope within the module where they are declared Local variable can only be access in the procedure where they are declared 1/2/2019 Prepred By: Deborah Becker

10 Prepred By: Deborah Becker
Rules!!!!!!!!!!!!!!!!!! It is good programming technique to limit the scope of your variables to the most restrictive scope you can use If data needs to be maintained independently use module level variables 1/2/2019 Prepred By: Deborah Becker

11 Prepred By: Deborah Becker
Coding efficiencies Avoid the use of variants Variants are generally VB’s slowest data type Use integer variables where possible Integers and long integers are fast because they are the native data type of the computer hardware 1/2/2019 Prepred By: Deborah Becker

12 Assignment statements
strCOMPANY_NAME = “ADVENTURE UNLIMTED” When you use an assignment statement you are setting the leftside of the = sign equal to the rightside. The right side of the = sign must be contained in “” for a string literal 1/2/2019 Prepred By: Deborah Becker

13 Write the correct Assignment
Set the strCompanyName equal to Ford Motor Company Set the caption property of the lblMessage equal to strCompanyName = “Ford Motor Company” lblMessage.Caption = “Have a Nice Day” 1/2/2019 Prepred By: Deborah Becker

14 Correct this Procedure
Private Sub cmdCompute_Click() Dim interestRate As Single Dim principle As Single Dim phrase As String picBalance.Cls interestRate = 100 = principle phrase = “The loan balance is “ picBalance.Print phrase;(1 + interestRate) * principle End Sub 1/2/2019 Prepred By: Deborah Becker

15 Prepred By: Deborah Becker
Private Sub cmdCompute_Click() Dim sngInterestRate As Single Dim sngPrinciple As Single Dim strPhrase As String picBalance.Cls sngInterestRate = sngPrinciple = 100 strPhrase = “The loan balance is “ picBalance.Print strPhrase;(1 + sngInterestRate) * _ sngPrinciple End Sub 1/2/2019 Prepred By: Deborah Becker

16 Prepred By: Deborah Becker
Strings The string that contains no characters is called a null string or empty string A string defined as “ “ is not an empty string because it contains one space Assigning a string value to a numeric variable can result in the error message Type mismatch 1/2/2019 Prepred By: Deborah Becker

17 Prepred By: Deborah Becker
Strings In VB 6.0 the maximum allowable characters in a string is about 2 Billion Declaring variable is optional with VB but not in this class All variables must be declared with a DIM statement in the proper area. 1/2/2019 Prepred By: Deborah Becker

18 Prepred By: Deborah Becker
Strings Variable not declared are considered to be Implicitly declared You can display the type of a variable by Positing the mouse over the top of the word (variable) Press the Right Mouse button and Clicking on Quick Info 1/2/2019 Prepred By: Deborah Becker

19 The Val Function & Str Function
You can convert the content of a textBox to a numeric value by using the Val Function numVal = Val(txtBox.Text) You can convert the content of a numeric variable to string by use of the Str Function txtBox.Text = Str(intVal) 1/2/2019 Prepred By: Deborah Becker

20 Prepred By: Deborah Becker
VB Handling You can omit the Val and Str functions from your code and VB will handle the conversion for you, BUT intGrade = txtBox1.Text + txtBox2.Text If the value of txtBox1 = 34 and the value of txtBox2 = 56 then the computer would assign you a grade of 3456 and not 90 1/2/2019 Prepred By: Deborah Becker

21 Prepred By: Deborah Becker
VB Handling Evaluating a txtBox that is empty in a numeric equation in your program will result in an error message 1/2/2019 Prepred By: Deborah Becker

22 Prepred By: Deborah Becker
ANSI Character Set Refer to appendix A in the back of your book. Each letter, number or special character has a numeric value assigned to it. Upper and lower case letters have different values. Upper case letter have a lower numeric value then lower case letters. 1/2/2019 Prepred By: Deborah Becker

23 Prepred By: Deborah Becker
Evaluating the ANSI “Cat” = “cat” “Cat” > “cat” “Cat” < “cat” “big” > “Big” “A” > “a” “Z” < “a” 1/2/2019 Prepred By: Deborah Becker

24 Prepred By: Deborah Becker
Homework Do Exercises 3.4 page 93-94 Do Exercises 23, 26 page 95 1/2/2019 Prepred By: Deborah Becker


Download ppt "Prepred By: Deborah Becker"

Similar presentations


Ads by Google