Advertisement
Guest User

vba

a guest
Mar 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub CommandButton1_Click()
  2. Dim guess1 As Integer
  3. Dim guess2 As Integer
  4. Dim secret As Integer
  5.  
  6. secret = Me.Cells(1, 2)
  7. guess1 = InputBox("Lower Bound:")
  8. guess2 = InputBox("Upper Bound:")
  9.  
  10. While midpt <> secret
  11.  
  12. midpt = (guess1 + guess2) / 2
  13.  
  14. If midpt - secret > 0 Then
  15. guess2 = midpt
  16. midpt = (guess1 + guess2) / 2
  17. Else
  18. If midpt - secret < 0 Then
  19. guess1 = midpt
  20. midpt = (guess1 + guess2) / 2
  21. If midpt = secret Then
  22. MsgBox ("The secret number is " & secret)
  23. Else
  24. End If
  25. End If
  26. End If
  27.  
  28.  
  29. Wend
  30.  
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement