[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-10-01
3
Medium Priority
?
150 Views
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
        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
Comment
Question by:tbirkhimer
  • 2
3 Comments
 
LVL 6

Expert Comment

by:MELeBlanc
ID: 19991474
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
 
LVL 6

Accepted Solution

by:
MELeBlanc earned 2000 total points
ID: 19991484
... 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
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 19991490
     If (newResult1 > newResult2) Then
                 lblPlay.Text = lblPlay.Text + 1
                 Else
                 lblPlay.Text = lblPlay.Text
           End If
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

834 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