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 1Max: 98Max: 98Average: 75.18Average: 75.18Median: 75Median: 75StringsStringsStrings are variables that hold letters, Strings are variables that hold letters, words, sentences, or even numberswords, sentences, or even numbersString 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 VariablesDeclaring StringsDeclaring StringsDim Phrase1 As StringDim Phrase1 As StringAssigning 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 VariableDim TheAnswer as StringDim TheAnswer as StringTheAnswer = “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 ” & TheAnswerSpacingSpacingSpacing: 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 rightSpace 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 RelationshipsString 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 FunctionsFunctions 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 informationinformationFunctions have Functions have ARGUMENTSARGUMENTS, or values , or values that you put into themthat you put into themARGUMENTS go inside parenthesesARGUMENTS go inside parenthesesLeft(“fanatic”, 3) Left(“fanatic”, 3) Left(fanatic, 3)Left(fanatic, 3)String FunctionsString FunctionsLen(string) – finds lengthLen(string) – finds lengthLeft(string, n) takes left most Left(string, n) takes left most nn characterscharactersRight(string, n) does same from rightRight(string, n) does same from rightUcase(string) makes string UPPERCASEUcase(string) makes string UPPERCASETrim(string) – takes spaces off endsTrim(string) – takes spaces off endsMid(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 StringDNA=“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 StringDNA=“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 StringsComparison = 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 spacesThen, 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 4ProceduresProceduresString 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