DOC PREVIEW
MSU LBS 126 - VB Strings and Functions
Course Lbs 126-
Pages 24

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

String and General ProceduresAnswer to the last question of Exam 1Statistics of Exam 1Slide 4StringsString Variables& Adding Two Strings &Adding text to a String VariableSpacingString RelationshipsString FunctionsSlide 12Mid StringInStr() – In StringWorking with Text StringsNumeric FunctionsProceduresEvent ProcedureGeneral ProceduresWhy using general procedures?Passing arguments to a procedureA computer without a output device?Functions procedureHomeworkString and General ProceduresString and General ProceduresAnswer to the last question of Answer to the last question of Exam 1Exam 1StartGet a numberDivide the NumberBy 2Is the quotient Equal to 1?PrintThe Remainto the left of previous remains NoPrint 1To the left ofPrevious remainsEndYesOutput numberIf numberEqual to 1 or0YesNoStatistics of Exam 1Statistics of Exam 1Max: 98Max: 98Average: 75.18Average: 75.18Median: 75Median: 75StringsStringsStrings are variables that hold letters, Strings are variables that hold letters, words, sentences, or even numberswords, sentences, or even numbersString holds a bunch of ASCII codes.String holds a bunch of ASCII codes.You can not do mathematical operations on You can not do mathematical operations on string.string.So you need to use Val(string) function to So you need to use Val(string) function to convert strings to numbers.convert strings to numbers.String VariablesString VariablesDeclaring StringsDeclaring StringsDim Phrase1 As StringDim Phrase1 As StringAssigning value to a string variableAssigning value to a string variable–Phrase1 = “Hello”Phrase1 = “Hello”Phrase1Hello72101108108111ASCII code& Adding Two Strings && Adding Two Strings &Phrase1 = TextBox1.TextPhrase1 = TextBox1.TextPhrase2 = TextBox2.TextPhrase2 = TextBox2.TextSentence = Phrase1 & Phrase2Sentence = Phrase1 & Phrase2Adding two strings is called Adding two strings is called ““CONCATENATINGCONCATENATING””Adding text to a String VariableAdding text to a String VariableDim TheAnswer as StringDim TheAnswer as StringTheAnswer = “a plague upon society!”TheAnswer = “a plague upon society!”Sentence= “Boy Bands are ” & “TheAnswer”Sentence= “Boy Bands are ” & “TheAnswer”Sentence= “Boy Bands are ” & TheAnswerSentence= “Boy Bands are ” & TheAnswerSpacingSpacingSpacing: Does not insert spaces for youSpacing: Does not insert spaces for you–““This is” & “not right” This is” & “not right”  This isnot rightThis isnot right–““This is ” & “right” This is ” & “right”  This is rightThis is rightSpace itself has an ASCII code, Space itself has an ASCII code, which is 32 (10 base), or 00100000 which is 32 (10 base), or 00100000 (binary)(binary)String RelationshipsString RelationshipsString can be compared.String can be compared.StringA = StringB : comparing if two string StringA = StringB : comparing if two string is identical.is identical.StringA <> StringB : different fromStringA <> StringB : different from–““Hello” <> “hello” is true.Hello” <> “hello” is true.StringA < StringB : if the string A will StringA < StringB : if the string A will appear earlier in a dictionary than B.appear earlier in a dictionary than B.>, <=, >=>, <=, >=String FunctionsString FunctionsFunctions are built in processes that do Functions are built in processes that do something to a variable or piece of something to a variable or piece of informationinformationFunctions have Functions have ARGUMENTSARGUMENTS, or values , or values that you put into themthat you put into themARGUMENTS go inside parenthesesARGUMENTS go inside parenthesesLeft(“fanatic”, 3) Left(“fanatic”, 3) Left(fanatic, 3)Left(fanatic, 3)String FunctionsString FunctionsLen(string) – finds lengthLen(string) – finds lengthLeft(string, n) takes left most Left(string, n) takes left most nn characterscharactersRight(string, n) does same from rightRight(string, n) does same from rightUcase(string) makes string UPPERCASEUcase(string) makes string UPPERCASETrim(string) – takes spaces off endsTrim(string) – takes spaces off endsMid(string, start, length) – takes a string from Mid(string, start, length) – takes a string from middle (great for dividing strings up into pieces)middle (great for dividing strings up into pieces)InStr(string, substring) searches for substring in InStr(string, substring) searches for substring in stringstringMid StringMid StringDNA=“ACGTGACACTGAC”DNA=“ACGTGACACTGAC”Base1=Mid(DNA, 1, 1)Base1=Mid(DNA, 1, 1) “A” “A”Base2=Mid(DNA, 2, Base2=Mid(DNA, 2, 44)) “CGTG” “CGTG”......Base6=Mid(DNA, 6, Base6=Mid(DNA, 6, 22)) “AC” “AC”InStrInStr()() – In String – In StringDNA=“ACGTGACACTGAC”DNA=“ACGTGACACTGAC”Location=InStr(DNA, “CACTG”)Location=InStr(DNA, “CACTG”)Returns location of first character of substringReturns location of first character of substringWorking with Text StringsWorking with Text StringsComparison = means “Comparison = means “identical toidentical to””““yes” is not equal to “Yes”yes” is not equal to “Yes”““yes “ is not equal to “yes”yes “ is not equal to “yes”Prepare strings for comparisonPrepare strings for comparison–answer = Ucase(answer) answer = Ucase(answer) – makes it all caps– makes it all caps–answer = Trim(answer) answer = Trim(answer) – takes off spaces– takes off spacesThen, compare to all caps!Then, compare to all caps! –if answer = “YES” thenif answer = “YES” thenNumeric FunctionsNumeric Functionsanswer = Sqr(varNum)answer = Sqr(varNum)answer = Int(varNum)answer = Int(varNum) – – truncatestruncates (cuts (cuts off decimal stuff) and makes integer off decimal stuff) and makes integer Int(3.7) Int(3.7)  3 3Int(-2.34) Int(-2.34)  -2 -2answer= Round(varNum)answer= Round(varNum) – rounds number – rounds numberRound(3.7)Round(3.7)  4 4ProceduresProceduresString and numeric functions belong to a String and numeric functions belong to a VB category called “procedure”VB category called “procedure”Procedures are pre-defined code fragments.Procedures are pre-defined code fragments.There are three types of procedures.There are three types of procedures.–Event procedure (event


View Full Document

MSU LBS 126 - VB Strings and Functions

Course: Lbs 126-
Pages: 24
Download VB Strings and Functions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view VB Strings and Functions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view VB Strings and Functions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?