?
Solved

I've created a form that determines the highest number out of 4 text boxes after adding a timer to self eval it broke

Posted on 2005-04-13
4
Medium Priority
?
177 Views
Last Modified: 2010-04-23
To: All

This is an odd one.

The program has 4 text boxes.  I'll start by entering 12, 11, 10, 9 and click evalute and it will show that 12 is the greatest number.

I can change any number and it will still work.

It dies when I empty/delete a field.  I have added a checker to see it a blank exist and ignore it but that doesn't seem to help.

Thanks inadvance


Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    Dim WithEvents tmrMyTimer As New Timers.Timer(2000)


    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents resultField As System.Windows.Forms.TextBox
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents item1 As System.Windows.Forms.TextBox
    Friend WithEvents item2 As System.Windows.Forms.TextBox
    Friend WithEvents item3 As System.Windows.Forms.TextBox
    Friend WithEvents item4 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.item1 = New System.Windows.Forms.TextBox()
        Me.item2 = New System.Windows.Forms.TextBox()
        Me.item3 = New System.Windows.Forms.TextBox()
        Me.item4 = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.resultField = New System.Windows.Forms.TextBox()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'item1
        '
        Me.item1.Location = New System.Drawing.Point(88, 80)
        Me.item1.Name = "item1"
        Me.item1.Size = New System.Drawing.Size(64, 20)
        Me.item1.TabIndex = 0
        Me.item1.Text = ""
        '
        'item2
        '
        Me.item2.Location = New System.Drawing.Point(176, 80)
        Me.item2.Name = "item2"
        Me.item2.Size = New System.Drawing.Size(64, 20)
        Me.item2.TabIndex = 1
        Me.item2.Text = ""
        '
        'item3
        '
        Me.item3.Location = New System.Drawing.Point(272, 80)
        Me.item3.Name = "item3"
        Me.item3.Size = New System.Drawing.Size(64, 20)
        Me.item3.TabIndex = 2
        Me.item3.Text = ""
        '
        'item4
        '
        Me.item4.Location = New System.Drawing.Point(360, 80)
        Me.item4.Name = "item4"
        Me.item4.Size = New System.Drawing.Size(64, 20)
        Me.item4.TabIndex = 3
        Me.item4.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(88, 48)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.TabIndex = 14
        Me.Label1.Text = "Item1"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(184, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 16)
        Me.Label2.TabIndex = 15
        Me.Label2.Text = "Item2"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(272, 48)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(64, 16)
        Me.Label3.TabIndex = 16
        Me.Label3.Text = "Item3"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(360, 48)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(64, 16)
        Me.Label4.TabIndex = 17
        Me.Label4.Text = "Item4"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(32, 176)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(144, 24)
        Me.Button1.TabIndex = 23
        Me.Button1.Text = "Evaluate"
        '
        'resultField
        '
        Me.resultField.Location = New System.Drawing.Point(32, 224)
        Me.resultField.Name = "resultField"
        Me.resultField.Size = New System.Drawing.Size(680, 20)
        Me.resultField.TabIndex = 24
        Me.resultField.Text = ""
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(232, 176)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(120, 24)
        Me.Button2.TabIndex = 25
        Me.Button2.Text = "Stop Eval"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(736, 389)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.resultField, Me.Button1, Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.item4, Me.item3, Me.item2, Me.item1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

    Private Function GetHand(ByVal i1 As String, ByVal i2 As String, ByVal i3 As String, ByVal i4 As String) As String

        Dim results As String

        Dim maxValue As Integer

        Dim counter As New Hashtable()

       

        If (i1.Length.ToString <> 0) Then
            counter(i1) += 1
        End If

        If (i2.Length.ToString <> 0) Then
            counter(i2) += 1
        End If

        If (i3.Length.ToString <> 0) Then
            counter(i3) += 1
        End If

        If (i4.Length.ToString <> 0) Then
            counter(i4) += 1
        End If




        Dim en As IDictionaryEnumerator = counter.GetEnumerator

        While en.MoveNext

            ' MessageBox.Show("Inside While")

            results = results & en.Key & "=>" & en.Value & " " 'Console.WriteLine(en.Key & " : " & en.Value)

            ' Capture Value

            If (en.Key > maxValue) Then

                maxValue = en.Key

            End If


        End While

        results = results & " maxValue => " & maxValue

        'MessageBox.Show("Returning Result")

        Return results



    End Function

   

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        tmrMyTimer.Start()
    End Sub


    Sub tmrEvent(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs) Handles tmrMyTimer.Elapsed
        tmrMyTimer.Stop()
        'timer has elapsed
        'MessageBox.Show("help")
        resultField.Text = GetHand(item1.Text, item2.Text, item3.Text, item4.Text)
        tmrMyTimer.Start()
    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        tmrMyTimer.Stop()
    End Sub
End Class
0
Comment
Question by:vaultworld
  • 2
4 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13774824
The purpose of GetHand() is to return the highest of the 4 values?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 13774910
This code bothers me:

        If (i1.Length.ToString <> 0) Then
            counter(i1) += 1
        End If

        If (i2.Length.ToString <> 0) Then
            counter(i2) += 1
        End If

        If (i3.Length.ToString <> 0) Then
            counter(i3) += 1
        End If

        If (i4.Length.ToString <> 0) Then
            counter(i4) += 1
        End If

Why are you converting Length to a String and then comparing it with a number?  Either change 0 to "0" or don't use the ToString part:

        If (i1.Length <> 0) Then
            counter(i1) += 1
        End If

        ' etc..
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13774958
maybe they meant to do...

        If (i1.ToString.Length <> 0) Then
            counter(i1) += 1
        End If

==========

although that is kinda useless since i1 is a string already

=========

I'm just waitin to see what that function does... my tired head can't compute what it's meant to be doing, so I just asked and was planning on writing something from scratch instead....  but I might just leave it in your capable hands :P
0
 
LVL 1

Author Comment

by:vaultworld
ID: 13776357
thanks, I swear I tried that first and it didn't work but apparently not.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

807 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