5 Replies - 1146 Views - Last Post: 12 September 2013 - 09:47 AM Rate Topic: -----

#1 itsbird  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-September 13

Display calculations, label status bar only appears visible/not

Posted 12 September 2013 - 08:19 AM

Hi! I'm working on this code and I've been unable to get the calculations I've put in to display. I've tried different ways to code it but it still won't display. I'm also having problems with my status bar. It's actually a label in the program and I've only been able to get it to show up every time I click "Calculate Ticket Revenue". I'm not sure how to hide it until the proper time. It's supposed to be a Catch for when someone enters in a non-numerical value. I've been at this for several days now and I'm not getting anywhere, it feels. Here's the code:

Imports System.IO
Public Class Form1

    Dim dblPricePerTcktA As Double = 0.0 ' Price of Adult ticket
    Dim intTcktSoldA As Integer = 0 ' Tickets sold of Adult
    Dim dblPricePerTcktC As Double = 0.0 ' Price of Child ticket
    Dim intTcktSldC As Integer = 0 ' Tickets sold of Child
    Dim intAdltTcktSGrss As Integer = 0 ' Total gross ticket sales of Adult tickets
    Dim intChldTcktSleGrss As Integer = 0 ' Total gross ticket sales of Child tickets
    Dim dblAdltTcktSleNt As Double = 0.0 ' Total net sales of Adult tickets
    Dim dblChldTcktSleNt As Double = 0 ' Total net sales of Child tickets
    Dim dblTtlGrssRev As Double = 0.0 ' Total gross revenue
    Dim dblTtlNtRev As Double = 0.0 ' Total net revenue
    Dim dblAdltTcktSleG As Double = 0.0 ' Total gross sales of Adult tickets
    Dim dblChldTcktSleG As Double = 0.0 ' Total gross sales of Child tickets
    Const dblRATENET As Double = 0.2 ' Net Percentage to be used in calculations
 

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        ' Close the form.
        Me.Close()
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        ' Clear the text boxes
        lblAdltTcktSGrss.Clear()
        lblAdltTcktSleNt.Clear()
        lblChldTcktSleGrss.Clear()
        lblChldTcktSleNt.Clear()
        txtPricePerTcktA.Clear()
        txtPricePerTcktC.Clear()
        txtTcktSldC.Clear()
        txtTcktSoldA.Clear()
        lblTtlGrossRev.Clear()
        lblTtlNetRev.Clear()

        lblStatus.Visible = False ' Make status bar go away
    End Sub


    Private Sub btnCalcRev_Click(sender As Object, e As EventArgs) Handles btnCalcRev.Click
        ' Local level variables changed to class level in order to access the variables for the print to file button

        Try
            Dim dblTtlGrssRev As Decimal = CDbl(lblTtlGrossRev.Text) ' Total gross revenue.
            Dim dblTtlNtRev As Decimal = CDbl(lblTtlNetRev.Text) ' Total net revenue.
            Dim dblAdltTcktSleN As Integer = CInt(lblAdltTcktSleNt.Text) ' Total net adult ticket sales.
            Dim dblChldTcktSleN As Integer = CInt(lblChldTcktSleNt.Text) ' Total net child ticket sales.
            Dim dblAdltTcktSleG As Decimal = CDbl(lblAdltTcktSGrss.Text) ' Total gross adult sales.
            Dim dblChldTcktSleG As Decimal = CDbl(lblChldTcktSleGrss.Text) ' Total gross child sales.

            ' Get price of child tickets and adult tickets
            dblPricePerTcktA = CDbl(txtPricePerTcktA.Text)
            dblPricePerTcktC = CDbl(txtPricePerTcktC.Text)
            intTcktSldC = CInt(txtTcktSldC.Text)
            intTcktSoldA = CInt(txtTcktSoldA.Text)

            ' Calculate the gross adult sales
            dblAdltTcktSleG = dblPricePerTcktA * intTcktSoldA

            'Calculate the gross child sales
            dblChldTcktSleG = dblPricePerTcktC * intTcktSldC

            ' Calculate the gross total
            dblTtlGrssRev = intAdltTcktSGrss + intChldTcktSleGrss

            ' Calculate the net adult sales
            dblAdltTcktSleN = intAdltTcktSGrss * dblRATENET

            ' Calculate the net child sales
            dblChldTcktSleN = intChldTcktSleGrss * dblRATENET

            ' Calculate the net total
            dblTtlNtRev = dblAdltTcktSleN + dblChldTcktSleN

            ' Display totals
            lblAdltTcktSGrss.Text = intTcktSoldA.ToString("n") ' Display number of tickets sold for adult
            lblChldTcktSleGrss.Text = intTcktSldC.ToString("n") ' Display number of tickets sold for child
            lblAdltTcktSleNt.Text = dblAdltTcktSleN.ToString("c") ' Display net total of adult tickets sold
            lblChldTcktSleNt.Text = dblChldTcktSleN.ToString("c") ' Display net total of child tickets sold
            lblTtlNetRev.Text = dblTtlNtRev.ToString("c") ' Display total net revenue
            lblTtlGrossRev.Text = dblTtlGrssRev.ToString("c") ' Display total gross revenue

        Catch
            ' Display error message.
            lblStatus.Visible = True

            ' Have no idea how to make this only visible when a user enters non-numerical values


        End Try
    End Sub

    
    
    Private Sub btnPrntFle_Click(sender As Object, e As EventArgs) Handles btnPrntFle.Click
        ' Create print variable
        Dim prntFle As StreamWriter

        ' Create file printout
        prntFle = File.CreateText("RevenuePrintout.txt")

        ' Print information to the file
        prntFle.WriteLine("Gross Ticket Sales" & vbNewLine)
        prntFle.WriteLine("Adult Ticket Sales" & vbTab & vbTab & dblAdltTcktSleG.ToString("c"))
        prntFle.WriteLine("Child Ticket Sales" & vbTab & vbTab & dblChldTcktSleG.ToString("c"))
        prntFle.WriteLine("Total Gross Revenue" & vbTab & vbTab & dblTtlGrssRev.ToString("c"))
        prntFle.WriteLine("")
        prntFle.WriteLine("Net Ticket Sales" & vbNewLine)
        prntFle.WriteLine("Adult Ticket Sales" & vbTab & vbTab & dblAdltTcktSleNt.ToString("c"))
        prntFle.WriteLine("Child Ticket Sales" & vbTab & vbTab & dblChldTcktSleNt.ToString("c"))
        prntFle.WriteLine("Total Net Revenue" & vbTab & vbTab & dblTtlNtRev.ToString("c"))
        ' Close file
        prntFle.Close()
        ' Display message to user that info was printed to file
        MessageBox.Show("Calculations successfully printed to file!")
        ' I can print my form of nothing successfully, yay!

    End Sub


End Class



Thanks so much for any and all help in advance!

- Bird

Is This A Good Question/Topic? 0
  • +

Replies To: Display calculations, label status bar only appears visible/not

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2134
  • View blog
  • Posts: 3,272
  • Joined: 21-June 11

Re: Display calculations, label status bar only appears visible/not

Posted 12 September 2013 - 08:26 AM

When posting code in the "Other Languages" forum, please specify which language you're using - preferably in the title. If this is VB.net (which it looks like to my untrained eye), we have a forum for that.
Was This Post Helpful? 0
  • +
  • -

#3 itsbird  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-September 13

Re: Display calculations, label status bar only appears visible/not

Posted 12 September 2013 - 08:29 AM

I'm sorry! I didn't think it would be VB.NET since it's VB Express, actually. That's why I went here because I was worried that might be the wrong forum. I don't think there's a way I can fix it but I'll see if I can message an admin to add that in. I'll make sure to remember for next time!

- Bird
Was This Post Helpful? 0
  • +
  • -

#4 itsbird  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-September 13

Re: Display calculations, label status bar only appears visible/not

Posted 12 September 2013 - 09:26 AM

Okay, I got it to display! :D Now I'm just plugging away at that lblStatus bar thing. So I'm good to go on the display issue. Just an FYI.
Was This Post Helpful? 0
  • +
  • -

#5 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 255
  • View blog
  • Posts: 1,386
  • Joined: 11-May 12

Re: Display calculations, label status bar only appears visible/not

Posted 12 September 2013 - 09:42 AM

Why don't you just throw up a message box saying to only use numerical values, instead of a label? like so

Try
' your code here
Catch ex As Message
If Not IsNumeric(txtPricePerTcktA.Text) Or Not IsNumeric(txtPricePerTcktC).Text Or Not IsNumeric(txtTcktSldC.Text) Or Not IsNumeric(txtTcktSldA.Text) Then
MessageBox.Show("Please Only enter numeric Values.", "Numbers Only Please", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(ex.Message)
End If
End Try
Was This Post Helpful? 0
  • +
  • -

#6 itsbird  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-September 13

Re: Display calculations, label status bar only appears visible/not

Posted 12 September 2013 - 09:47 AM

I have to put in the label for this specific instance. Otherwise I would've used a message box. I've got a message box for the print to file. I think I might've figured out how to make it disappear and appear only when necessary. Now I need to work on my calculations because they're showing up wrong.

I would prefer, however, to use a message box. I like them better.

- Bird
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1