Attribute VB_Name = "Module1" 'Testing the ability to return an arbitrary string response ' to a parameter that is, presumably, the category or summary line of a case. Function topic(s As String) As String If s = "Network" Then topic = "Network" Else topic = "Dunno" End If End Function Function TopicCase(s As String) As String Select Case s Case "Network" TopicCase = "You said " & s Case "Dunno" MsgBox "I respond " & s Case Else MsgBox "What was that word?" End Select End Function Function SubTopic(summary As String, t As String) As String MsgBox "Topic is " & t & " Summary is " & summary SubTopic = ActiveSheet.Name End Function Function WordInString(s As String) As String If InStr(LCase(s), "eudora") Then WordInString = "email" Else: WordInString = "something else" End Function 'Another approach is to define an array of strings containing keywords ' that I'm looking for. Compare each word in the argument to all of the ' strings in the array; if it matches, you win. If not, then you have ' to read them by hand. Function SearchStringArray(s As String) As String ' define an array of strings. ' loop through the whole array to compare s to the other strings. ' presumably this argument s is one of the words in the summary line ' of the case or the software field. ' Maybe the string array is multidimensional of the form: ' array[n][0] = "Name of category" ' array[n][1] = "keywords associated with that category" ' e.g., "email" and "eudora outlook mail entourage " and so on. ' if the routine sees those keyaords, then it kicks out and returns the ' first argument. '(Note that all this algorithmic stuff could be done in C or Perl ' on a delimited text file. Next time.) Dim i As Integer Dim strKeywords(1 To 15, 1 To 3) As String strKeywords(1, 1) = "Email" strKeywords(1, 2) = "Eudora Outlook inbox entourage " strKeywords(2, 1) = "Network" strKeywords(2, 2) = "DHCP Network Register connect conflict tether visitor" strKeywords(3, 1) = "Software" strKeywords(3, 2) = "cert certificate installer word excel filezilla master kerberos vpn" strKeywords(4, 1) = "Accounts" strKeywords(4, 2) = "quota password login account" strKeywords(5, 1) = "Printing" strKeywords(5, 2) = "print printing printer" strKeywords(6, 1) = "Backup" strKeywords(6, 2) = "tsm retrospect" strKeywords(7, 1) = "Services" strKeywords(7, 2) = "athena stellar websis calendar events" strKeywords(8, 1) = "Security" strKeywords(8, 2) = "spyware virus" strKeywords(9, 1) = "OS" strKeywords(9, 2) = "XP reinstall panther machine boot hangs operating" strKeywords(10, 1) = "Hardware" strKeywords(10, 2) = "cdrw harddrive harddisk card drive dock power modem floppy display mouse keyboard" Dim strFoundIn As String Dim testresult As Integer Dim msg As String strFoundIn = "" rowFound = 0 ' MsgBox (" looking for " & s) For i = 1 To 10 ' msg = Str(i) & ": " & strKeywords(i, 1) & " " & strKeywords(i, 2) ' MsgBox (msg) t = InStr(1, strKeywords(i, 2), LCase(s), vbTextCompare) If t > 0 Then rowFound = i ' MsgBox (LCase(s) & " returns test result" & Str(t) & " in " & strKeywords(i, 2)) Next i SearchStringArray = "test result" & Str(rowFound) & " " & strKeywords(rowFound, 1) End Function Function Tokenize(s As String) As Variant Dim strArray As Variant strArray = Split(s, " ") For i = 1 To UBound(strArray) ' msg = strArray(i) & ", " Next i ' MsgBox (Str(UBound(strArray)) & "words, including" & strArray(0) & " " & strArray(UBound(strArray))) Tokenize = UBound(strArray) End Function 'Nov 4, 2004: the algorithm is becoming: ' a.) split the source string into all its words. ' b.) split the target string into all of its words. ' c.) one by cne compare all the words in the source agsinst all the words in the target ' record the number of hits in the counter array element of each major word bucket. ' the one with the most hits is declared the winner and its classification ' is reported back to the calling sheet. In this way we can assert ' something like: the terms found have some hits in software but more hits in ' Network. CHances are then that it's a network case. Hmmm. ' I need to be sure I find "network" within "networking", but not ' find "word" within "password". So if the starting character is greater than 1, skip. ' That way only words that match and are left-aligned will count. Function FindWord(source As String, target As String) As String ' returns the name of the keyword family in which the word was found. Dim sourceArray As Variant Dim targetArray As Variant Dim i As Integer Dim j As Integer Dim found As Integer 'counts the number of times source words are in target string Dim position As Integer 'the column where the words, if found, aligh. ' for every word in the source string, assuming space separator sourceArray = Split(source) ' for every word in the target string, assuming space separator targetArray = Split(target) ' is the word in the source found in the target? ' MsgBox ("Looking for " & source & " in " & target) found = 0 For i = 0 To UBound(sourceArray) For j = 0 To UBound(targetArray) position = InStr(1, sourceArray(i), targetArray(j), vbTextCompare) If position = 1 Then found = found + 1 'only count it if it's the left edge that aligns ' MsgBox (" checking " & sourceArray(i) & " against " & targetArray(j) & " gives position as " & Str(position)) Next j Next i ' if yes, is the position of the match equal to the left edge? ' return 1 if it is found, zero if not. FindWord = Str(found) End Function