Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Array Problems (http://www.programmingforums.org/showthread.php?t=15088)

kewlgeye Jan 30th, 2008 10:12 AM

Array Problems
 
1 Attachment(s)
Hello,

My problem here is that I am trying to print a form that stores the name of the selectedindex and the price side by side as you select one of the seat types. I keep getting the seats displaying on knew lines individually with their prices, but I don't want them to display individually, I want the price in the printpreview area to show the added price of the same seat when I click the print summary, not a knew line displaying that it was selected twice. Their is no summary form, just one form and an option to print your results. I have attached a picture of the form so you can see what it looks like. I only am showing a little of the code to keep things simple, and only one seat since the rest would be redundant I think.

Public Class clubForm
' Declare structure and module-level variables
Structure clubSale
Dim typeString As String
Dim quantityString As String
Dim priceDecimal As Decimal
End Structure

Private transactionclubSale(20) As clubSale
Private numberTransactionsInteger As Integer
Private priceDecimal() As Decimal = {40D, 27.5D, 15D, 10D}
Private selectedListString As String


Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
' Close the project.

Me.Close()
End Sub

Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click

' Look up the price using the type of seating.

Dim rowInteger As Integer
Dim salePriceDecimal As Decimal


With Me
' Allow only 20 transactions.
If numberTransactionsInteger < 20 Then
rowInteger = .clubListBox.SelectedIndex
If rowInteger <> -1 Then
Select Case selectedListString
Case "Orchestra"
rowInteger = 0
transactionclubSale(numberTransactionsInteger).typeString = "Orchestra"
End Select
' Retrieve price of selection
salePriceDecimal = priceDecimal(0)
priceTextBox.Text = salePriceDecimal.ToString("C")
' Save this transaction.
transactionclubSale(numberTransactionsInteger).typeString = .clubListBox.Text
transactionclubSale(numberTransactionsInteger).priceDecimal = salePriceDecimal
numberTransactionsInteger += 1

End If
End If
End With

Please share your thoughts on this. Thank you.

Sane Jan 30th, 2008 11:39 AM

Re: Array Problems
 
Firstly, please wrap your code in between [code] [/code] tags for readability.

Could you clarify what the print summary button does?

Quote:

I want the price in the printpreview area to show the added price of the same seat when I click the print summary
That's the only information I could find about that button. The added price of the same seat? That statement makes little sense, and I can't read your mind.

This is what I think you were trying to say: if you click calculate twice over "Orchestra", click calculate once over "Mezzanine", and then click "Print Summary", you get the price displayed for Orchestra+Orchestra+Mezzanine?

kewlgeye Jan 30th, 2008 3:22 PM

Re: Array Problems
 
Someone here told me about the code thing before, but I didn't know it has to be enclosed in code blocks like that, I will remember, thank you and sorry for the mess.

The print summary button opens a print preview window showing the amount of
seats ordered, the type of seat, and the total price of that particular seats orders (See Below). I am not worried about the amount of seat orders number right now,
because I haven't coded for it. But it should show the total amount for any seat
choosen. For example when the print summary button is hit a window pops up showing
the following.

Orchestra $120.00 (because everytime orchestra is clicked 40 gets added to the total.

Mezzanine $30.00 (because everytime mezzanine is choosen 15 is added and it the seat is displayed on a knew line.)

etc..




Right now it looks like this when I click the button


Orchestra $40

orchestra $40

orchestra $40

Mezzanine $15

Mezzanine $15

Sane Jan 31st, 2008 12:29 PM

Re: Array Problems
 
Quote:

am not worried about the amount of seat orders number right now,
because I haven't coded for it.
It looks like you do actually have it coded so it can display the number of seat orders.

You should loop through the transactionclubSale array, and keep track of how many are type "Orchestra". Keep a total for that. Output the total price (the sum of each priceDecimal), and the number of entries found (seats ordered).

Repeat for Mezzanine.

Repeat for General. Etc...

kewlgeye Jan 31st, 2008 1:33 PM

Re: Array Problems
 
So to loop I should code something like this.

:

transactionclubSale(numberTransactionsInteger).typeString = "Orchestra"
Loop transactionclubSale(numberTransactionsInteger).typeString = "Orchestra"
For each pricedecimal()
transactionclubSale(numberTransactionsInteger) += transactionclubSale(numberTransactionsInteger)
next


Sane Jan 31st, 2008 2:23 PM

Re: Array Problems
 
When the printsummary is called you should do something along the lines of:

:

  1. orchestraSeats = 0
  2. orchestraMoney = 0
  3.  
  4. for each item in transactionclubSale
  5.     if item.typeString is Orchestra
  6.         orchestraSeats += 1
  7.         orchestraMoney += item.priceDecimal
  8.  
  9. Output the orchestraSeats and orchestraMoney
  10.  
  11. Repeat for Mezzanine, General, etc...



There are more efficient ways of doing this, but that would be the easiest way with your level of programming experience.

kewlgeye Jan 31st, 2008 4:06 PM

Re: Array Problems
 
I understand.

I wanted to use arrays, so when you say more efficient are you referring to arrays? I know that my level of programming is rather novice, but I would like to know the more efficient ways if you could please tell me.

Sane Jan 31st, 2008 4:24 PM

Re: Array Problems
 
Yes, you could combine all 4 of those repetitions into 1 loop, by using an array to store each individual type's count. Where each type corresponds to a location in the array.

:

seats = new array of size 4, all set to 0
money = new array of size 4, all set to 0

for each item in transactionclubSale

    if item.typeString is Orchestra
        index = 0
    else if item.typeString is Mezzanine
        index = 1
    else if item.typeString is General
        index = 2
    else if item.typeString is Balcony
        index = 3

    seats[index] += 1
    money[index] += item.priceDecimal

Orchestra Seats and Orchestra Money is seats[0] and money[0]
Mezzanine Seats and Mezzanine Money is seats[1] and money[1]
General Seats  and General Money  is seats[2] and money[2]
Balcony Seats  and Balcony Money  is seats[3] and money[3]


But I would advise you try the first method before moving onto something more complicated, if you're a novice just starting to learn how to program.


All times are GMT -5. The time now is 3:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC