CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Location
    FWB, FL
    Posts
    34

    problem with textboxes

    This application I created has an output display of all weekly revenue and hours worked. I can insert and delete data just fine but nothing shows up in my total revenue and total hours boxes. Here is my code.

    Code:
    Option Strict On
    Public Class frmWeeklyReport
        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
    
        '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 ColumnHeader1 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
        Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
        Friend WithEvents lstWeeklyHours As System.Windows.Forms.ListView
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmWeeklyReport))
            Me.lstWeeklyHours = New System.Windows.Forms.ListView
            Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
            Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
            Me.TextBox1 = New System.Windows.Forms.TextBox
            Me.TextBox2 = New System.Windows.Forms.TextBox
            Me.Label1 = New System.Windows.Forms.Label
            Me.Label2 = New System.Windows.Forms.Label
            Me.SuspendLayout()
            '
            'lstWeeklyHours
            '
            Me.lstWeeklyHours.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.lstWeeklyHours.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})
            Me.lstWeeklyHours.FullRowSelect = True
            Me.lstWeeklyHours.Location = New System.Drawing.Point(0, 0)
            Me.lstWeeklyHours.MultiSelect = False
            Me.lstWeeklyHours.Name = "lstWeeklyHours"
            Me.lstWeeklyHours.Size = New System.Drawing.Size(320, 176)
            Me.lstWeeklyHours.TabIndex = 0
            Me.lstWeeklyHours.View = System.Windows.Forms.View.Details
            '
            'ColumnHeader1
            '
            Me.ColumnHeader1.Text = "Employee Name"
            Me.ColumnHeader1.Width = 190
            '
            'ColumnHeader2
            '
            Me.ColumnHeader2.Text = "Hours"
            '
            'ColumnHeader3
            '
            Me.ColumnHeader3.Text = "Rate"
            '
            'TextBox1
            '
            Me.TextBox1.Anchor = System.Windows.Forms.AnchorStyles.Bottom
            Me.TextBox1.Location = New System.Drawing.Point(240, 192)
            Me.TextBox1.MaxLength = 100000
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.ReadOnly = True
            Me.TextBox1.Size = New System.Drawing.Size(64, 20)
            Me.TextBox1.TabIndex = 4
            Me.TextBox1.Text = "$0.00"
            Me.TextBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
            '
            'TextBox2
            '
            Me.TextBox2.Anchor = System.Windows.Forms.AnchorStyles.Bottom
            Me.TextBox2.Location = New System.Drawing.Point(240, 216)
            Me.TextBox2.Name = "TextBox2"
            Me.TextBox2.ReadOnly = True
            Me.TextBox2.Size = New System.Drawing.Size(64, 20)
            Me.TextBox2.TabIndex = 5
            Me.TextBox2.Text = "0"
            Me.TextBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
            '
            'Label1
            '
            Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.Bottom
            Me.Label1.Location = New System.Drawing.Point(152, 192)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(84, 16)
            Me.Label1.TabIndex = 6
            Me.Label1.Text = "Total revenue:"
            '
            'Label2
            '
            Me.Label2.Anchor = System.Windows.Forms.AnchorStyles.Bottom
            Me.Label2.Location = New System.Drawing.Point(152, 216)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(80, 16)
            Me.Label2.TabIndex = 7
            Me.Label2.Text = "Total hours:"
            '
            'frmWeeklyReport
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(320, 246)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.TextBox2)
            Me.Controls.Add(Me.TextBox1)
            Me.Controls.Add(Me.lstWeeklyHours)
            Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
            Me.Name = "frmWeeklyReport"
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "Weekly Revenue"
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
        ' Chapter 7:    Weekly Revenue
        ' Programmer:   Dennis Westermann
        ' Date:         April 14, 2007
        ' Purpose:      This form is the startup form for the Weekly
        '               Revenue application. The application 
        '               accepts input of employee name, hours worked,
        '               and rate. The application then calculates the
        '               total revenue for the week.
        Private Sub lstTodaysSales_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstWeeklyHours.KeyDown
            Dim intIndex, intListCount As Integer
            Dim sngTotalRevenue As Single = 0
            Dim sngHours As Single = 0
            Dim sngTotalHours As Single = 0
            Dim sngRate As Single = 0
            Dim strRate As String, strHours As String, strResults As String
    
            Select Case e.KeyCode
                Case Keys.Delete, Keys.D
                    If lstWeeklyHours.SelectedIndices.Count = 1 Then
                        lstWeeklyHours.Items.RemoveAt(lstWeeklyHours.SelectedIndices(0))
                    End If
                Case Keys.Insert, Keys.I
                    Dim objAddHoursForm As New frmAddEmployee
                    objAddHoursForm.ShowDialog()
                    If objAddHoursForm.txtEmployeeName.Text <> "" Then
                        Dim lviTodaysSales As New ListViewItem(objAddHoursForm.txtEmployeeName.Text)
                        lviTodaysSales.SubItems.Add(Format$(objAddHoursForm.nudHours.Value, "G"))
                        lviTodaysSales.SubItems.Add(Format$(objAddHoursForm.nudRate.Value, "Currency"))
                        lstWeeklyHours.Items.Add(lviTodaysSales)
                    End If
            End Select
    
            intListCount = Convert.ToInt32(lstWeeklyHours.Items.Count)
            For intIndex = 100000 To intListCount
                strRate = lstWeeklyHours.Items(intListCount).SubItems(1).Text
                strRate = strRate.Replace("$", "0")
                sngRate = Convert.ToSingle(strRate)
                strHours = lstWeeklyHours.Items(intIndex).SubItems(2).Text
                sngHours = Convert.ToSingle(strHours)
    
                sngTotalHours += sngHours
                sngTotalRevenue += sngHours * sngRate
            Next
    
            strResults = Format$(sngTotalRevenue, "Currency")
            TextBox1.Text = strResults
            TextBox2.Text = Convert.ToString(Format(sngTotalHours, "g"))
        End Sub
    
        Private Sub frmWeeklyReport_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
            Dim intColumn0Width As Integer
    
            intColumn0Width = Me.Width - lstWeeklyHours.Columns(1).Width - lstWeeklyHours.Columns(2).Width - 12
            If intColumn0Width > 0 Then
                lstWeeklyHours.Columns(0).Width = intColumn0Width
            End If
        End Sub
    End Class
    compiles fine and runs fine, just doesnt show my totals. Can anyone provide some input?

  2. #2
    Join Date
    Nov 2006
    Location
    FWB, FL
    Posts
    34

    Re: problem with textboxes

    anyone have some insight??

  3. #3
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: problem with textboxes

    My guess is that this for loop is never executed:

    For intIndex = 100000 To intListCount


    Put a break point on it and step thru with the debugger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured