title: Set textbox text with SendMessage()
body: <p>I am trying to set the text value of an 'edit' control text box with the SendMessage() function. I am able to set the text about 75% of the time but sometimes the function fails. Why would it work sometimes and fail others? I am always getting the correct window handle and am confused as to what else it could be? Here's my code:</p>
  
  <pre><code>attempt = 1
  retry:
      'Find open window textbox
      temp_id = 0
      temp_id = FindWindowEx(open_id, ByVal 0&amp;, "ComboBoxEx32", vbNullString)
      temp_id = FindWindowEx(temp_id, ByVal 0&amp;, "ComboBox", vbNullString)
      text_id = FindWindowEx(temp_id, ByVal 0&amp;, "Edit", vbNullString)
  
      'Select textbox and enter text then press open button
      Call SendMessage(text_id, WM_LBUTTONDBLCLK, 0, 0)
      Sleep 100
      text = filename
  
      Call SendMessage(text_id, WM_SETTEXT, 0&amp;, ByVal text)
      DoEvents
      Sleep 100
  
      If GetWindowTextLength(text_id) = 0 Then
          If attempt &lt; 3 Then
              attempt = attempt + 1
              GoTo retry
          End If
      End If
  </code></pre>