0

I need to get the false value if any of the captured words not found in dictionary. But what I got so far is, if it finds at least one word in the dicionary it returns the value true.

Sub stringnotfound()

Dim ibmCurrentTerminal As IbmTerminal
Dim ibmCurrentScreen As IbmScreen
Dim hiddenTextEntry As String
Dim returnValue As Integer
Dim timeout As Integer
Dim waitText As String
Dim alert(0 To 1) As String
timeout = 15000

Set ibmCurrentTerminal = ThisFrame.SelectedView.control
Set ibmCurrentScreen = ibmCurrentTerminal.screen


Dim Pos(1) As String
Dim wordDictonary   As String
Dim myArray         As Variant
Dim cnt             As Long
Dim lin             As Long
Dim hasWord         As Boolean

wordDictonary = "Lorem ipsum1,Lorem ipsum2,Lorem ipsum3,Lorem ipsum3,Lorem ipsum3,Lorem ipsum4"

myArray = Split(wordDictonary, ",")

If ibmCurrentScreen.GetText(13, 7, 12) <> "" Then Pos(0) = ibmCurrentScreen.GetText(13, 7, 12)
If ibmCurrentScreen.GetText(14, 7, 12) <> "" Then Pos(1) = ibmCurrentScreen.GetText(14, 7, 12)

For lin = 0 To 1
    For cnt = LBound(myArray) To UBound(myArray)
             If InStr(1, Pos(lin), Trim(myArray(cnt))) Then hasWord = True
    Next cnt
Next lin
    
    If hasWord = False Then MsgBox "captured" & MISSING & "words missing from the dictionary"

End Sub

Any help would be greatly appreciated. Thank you.

  • You could use an actual Dictionary object instead of just a string with commas in it... Those make it really simple to check to see if an item exists in the dictionary... https://stackoverflow.com/questions/915317/does-vba-have-dictionary-structure – braX Nov 30 '20 at 22:37
  • Thank you very much! – Pedro Silva Dec 01 '20 at 13:50

1 Answers1

0

If you use a dictionary object and check for a word NOT being in the dictionary, the code will be simplified and work as you desire:

   Dim i As Integer
   Dim MyDictionary As Dictionary
   Dim MyWords(1) As String
   
   Set MyDictionary = New Dictionary
   MyDictionary.Add "Lorem ipsum1", "Lorem ipsum1"
   MyDictionary.Add "Lorem ipsum2", "Lorem ipsum2"
   MyDictionary.Add "Lorem ipsum3", "Lorem ipsum3"

   MyWords(0) = "Lorem ipsum2"
   MyWords(1) = "Lorem ipsum4"

   For i = LBound(MyWords) To UBound(MyWords)
      If Not MyDictionary.Exists(MyWords(i)) Then
         MsgBox "Words missing from the dictionary"
         Exit For
      End If
   Next
Brian M Stafford
  • 8,483
  • 2
  • 16
  • 25