Counter not counting right when I try to compare random numbers.

Posted on 2007-10-01
Last Modified: 2010-03-19
Public Dim numDice As Long
    Public Dim numDice2 As Long
    Public Dim newResult1 As String
    Public Dim newResult2 As String

    Public Sub formMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     lblPlay.Text = 0
    End Sub

    Public Sub textBoxNumDice_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles  textBox6SidedNumDice.Leave
        Dim numDice As Long
            numDice = System.Convert.ToInt64(sender.Text())
        Catch exp As System.FormatException
            sender.Text() = "1"
        Catch exp As System.OverflowException
            sender.Text() = "1"
        End Try
        If (numDice <= 0) Then
            sender.Text() = "1"
        End If
    End Sub

    Public Sub buttonSided_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button6Sided.Click

        Select Case sender.Text()
      Case "6" '6-Sided Dice
                numDice = textBox6SidedNumDice.Text()
                textBox1.Text() = Int((numDice * 52) * Rnd() + (numDice * 1))
                newResult1 = textbox1.Text + Microsoft.VisualBasic.ChrW(13) + Microsoft.VisualBasic.ChrW(10)
                 numDice2 = textBox6SidedNumDice2.Text()
                 textBox2.Text() = Int((numDice2 * 52) * Rnd() + (numDice2 * 1))
                 newResult2 = textBox2.Text  + Microsoft.VisualBasic.ChrW(13) + Microsoft.VisualBasic.ChrW(10)
                butget.Text = newResult1
                butget2.Text = newResult2
                butget.Visible = True
                butget2.Visible = True
    End Select
      If (textBox1.Text > textBox2.Text) Then
                 lblPlay.Text = lblPlay.Text + 1
                 Else If (textBox2.Text > textBox1.Text)
                 lblPlay.Text = lblPlay.Text
           End If
    End Sub

I have tried comparing newResuult1 to newResult2.  butget.text() to butget2.text().  The counter seems to count when ever it wants.  EXAMPLE : When first random number is greater then second random number I want it to count as 1 and so on.  but when second number is less then first I don't want it to count, Ireally don't care if it is equal to number.  Some time counts sometimes it doesn't  like I get first random number 20 second random number 5, it counts, then I might get same result it doesn't count. Other example I get first random number 3 and second random number 10. It somtimes counts that for some reason or the other
Question by:tbirkhimer
    LVL 6

    Expert Comment

    I believe you need to "change" the textbox contents to a number in order to compare them the way you are wanting...


          If Cint(textBox1.Text) > Cint(textBox2.Text) Then
                     lblPlay.Text = lblPlay.Text + 1
          Else If Cint(textBox2.Text) > Cint(textBox1.Text)
                     lblPlay.Text = lblPlay.Text
          End If

    LVL 6

    Accepted Solution

    ... or in your case since you are using long data types

          If Clng(textBox1.Text) > Clng(textBox2.Text) Then
                     lblPlay.Text = lblPlay.Text + 1
          Else If Clng(textBox2.Text) > Clng(textBox1.Text)
                     lblPlay.Text = lblPlay.Text
          End If
    LVL 16

    Expert Comment

         If (newResult1 > newResult2) Then
                     lblPlay.Text = lblPlay.Text + 1
                     lblPlay.Text = lblPlay.Text
               End If

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now