Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.49 KB | None | 0 0
  1. Public Class Form1
  2.     Dim arrText() As String
  3. #Region "Functions"
  4.     Function check(ByVal result) 'Checking the result
  5.         Select Case result
  6.             Case result = NumericUpDown1.Value = False 'result isn't same as our chosen result
  7.                 Return False
  8.             Case result = NumericUpDown1.Value = True 'result is same as our chosen result
  9.                 Return True
  10.         End Select
  11.     End Function
  12.     Function count() 'counting the X
  13.         Dim result As Double
  14.         Dim MathStr As String = String.Empty
  15.         Dim x As Integer
  16.         For x = 0 To 1000 'Counting with numbers 0 to 1000
  17.             For i As Integer = 0 To UBound(arrText)
  18.                 MathStr &= arrText(i) & If(i < UBound(arrText), "", "x")
  19.             Next
  20.             result = New DataTable().Compute(MathStr, Nothing) 'Counting
  21.             Select Case check(result) 'checking
  22.                 Case True 'if the result equals our chosen result
  23.                     Return x 'returns the lucky number
  24.                     Exit Function
  25.                 Case Else
  26.             End Select
  27.         Next
  28.     End Function
  29. #End Region
  30.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  31.         arrText = TextBox1.Text.Split("x")
  32.  
  33.         CheckForIllegalCrossThreadCalls = False
  34.         Dim t As New Threading.Thread(AddressOf count)
  35.         t.IsBackground = True
  36.         t.Start()
  37.         ListBox1.Items.Add(count())
  38.     End Sub
  39. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement