Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 30th, 2008, 10:12 AM   #1
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
Question Array Problems

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.
Attached Images
File Type: jpg jiasdfo.jpg (111.3 KB, 10 views)
kewlgeye is offline   Reply With Quote
Old Jan 30th, 2008, 11:39 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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?
Sane is offline   Reply With Quote
Old Jan 30th, 2008, 3:22 PM   #3
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
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
kewlgeye is offline   Reply With Quote
Old Jan 31st, 2008, 12:29 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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...
Sane is offline   Reply With Quote
Old Jan 31st, 2008, 1:33 PM   #5
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
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
kewlgeye is offline   Reply With Quote
Old Jan 31st, 2008, 2:23 PM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Array Problems

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

Psuedocode Syntax (Toggle Plain Text)
  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.
Sane is offline   Reply With Quote
Old Jan 31st, 2008, 4:06 PM   #7
kewlgeye
Programmer
 
Join Date: Jan 2008
Posts: 54
Rep Power: 1 kewlgeye is on a distinguished road
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.
kewlgeye is offline   Reply With Quote
Old Jan 31st, 2008, 4:24 PM   #8
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem processing file into a char array csrocker101 C++ 1 May 8th, 2007 11:50 PM
Array Problems? Wizard1988 C++ 5 Jul 2nd, 2006 5:03 PM
changing size of an array Eric the Red Java 3 Apr 3rd, 2006 8:19 PM
Problems reading a double into an array using scanf() bivhitscar C 8 Nov 1st, 2005 1:47 AM
Installing IPB 2.03 bh4575 Other Web Development Languages 0 Apr 23rd, 2005 2:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:44 PM.

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