From jacobson@math-cs.cns.uni.edu Fri Nov 21 10:50:57 2003 Date: Fri, 21 Nov 2003 10:17:29 -0600 (CST) From: Mark Jacobson To: 810-022-01@uni.edu Subject: [810-022-01] **** Review of today's class on FIND() and INSTR() **** VBA macros View menu, Immediate command ?InStr("Ghostbusters","s") 4 ?InStr(Instr("Ghostbusters","s")+1,"Ghostbusters","s") 8 ?InStr(5,"MISSISSIPPI", "S") 6 Function ourFind(theData As String, findMe As String) As Integer whereFound = InStr(theData, findMe) ourFind = whereFound End Function Panthers 8 8 Ghostbusters 4 4 UNI #VALUE! 0 Fall #VALUE! 0 Christmas 5 5 Ballet #VALUE! 0 Panthers =FIND("s",A1) =ourFind(A1,"s") Ghostbusters =FIND("s",A2) =ourFind(A2,"s") UNI =FIND("s",A3) =ourFind(A3,"s") Fall =FIND("s",A4) =ourFind(A4,"s") Christmas =FIND("s",A5) =ourFind(A5,"s") Ballet =FIND("s",A6) =ourFind(A6,"s") Function ourFind(theData As String, findMe As String) As Integer whereFound = InStr(theData, findMe) ourFind = whereFound End Function The function requires as input two arguments. The first argument is theData, which will be the string to search. The 2nd argument is findMe, which will be the string to find or locate. The function returns an INTEGER result. Addition requires two arguments. Example 9 + 12 9 is the first argument, 12 is the 2nd argument. The result is 21, also an integer. Function Add(number1 As Integer, number2 As Integer) As Integer sum = number1 + number2 Add = sum End Function =Add(A2, B2) is now an Excel formula we could type in that would Add the contents of cells A2 and B2. We could type that formula into cell C2, for example, or use Insert menu, Function command to put the Add() function we just wrote into the C2 cell. The animation is NOT due before Thanksgiving. The TFE Time For Execution experiment with VBA variables is the only assignment due before Thanksgiving break! Please speak up DURING class about such matters! :-) ------ DURING is better than AFTER!!!! Mark