• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

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

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
        Try
            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
           
                Randomize()
                numDice = textBox6SidedNumDice.Text()
                textBox1.Text() = Int((numDice * 52) * Rnd() + (numDice * 1))
                newResult1 = textbox1.Text + Microsoft.VisualBasic.ChrW(13) + Microsoft.VisualBasic.ChrW(10)
               
                 Randomize()
                 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
0
tbirkhimer
Asked:
tbirkhimer
  • 2
1 Solution
 
MELeBlancCommented:
I believe you need to "change" the textbox contents to a number in order to compare them the way you are wanting...

e.g.

      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

-M
0
 
MELeBlancCommented:
... 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
0
 
SQL_SERVER_DBACommented:
     If (newResult1 > newResult2) Then
                 lblPlay.Text = lblPlay.Text + 1
                 Else
                 lblPlay.Text = lblPlay.Text
           End If
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now