Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Oct 24th, 2004, 1:07 PM   #1
swimboig83
Newbie
 
Join Date: Oct 2004
Posts: 1
Rep Power: 0 swimboig83 is on a distinguished road
Im a CIS major and I am writing a Structure Array for my Project. It Breaks and returns on the Array.Sort(Input) under the btnCalc_Click Sub. Any help on how to sort this properly would be appreciated. here is the code... my aim is swimboig84 if anyone can help me real time.
'Pizza movie Swimboig83...
'input zip and sales amount, output entered data...
'generate a report that shows the total sales per zip code, and the average sales per zip code.
Public Class Form1
  Inherits System.Windows.Forms.Form
  Structure Customer
    Dim Purchase As Double
    Dim Zip As Integer
  End Structure
  Structure ZipStored
    Dim Nbr As Integer
    Dim Zip As Integer
  End Structure
  Dim ZipStore() As ZipStored = {}
  Dim Input() As Customer = {}

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    lboIn.Items.Add("Purchase Amount".PadLeft(20) & "Zip Code".PadLeft(20))
    lboIn.Items.Add("==============".PadLeft(19) & "=======".PadLeft(19))

    lboOut.Items.Add("ZipCode".PadLeft(20) & " Number".PadLeft(20))
    lboOut.Items.Add("======".PadLeft(19) & " =====".PadLeft(19))

  End Sub

  'input zip and display in lboX
  Private Sub btnIn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnIn.Click
    Dim I As Integer
    Dim Pos As Integer

    Pos = UBound(Input) + 1
    ReDim Preserve Input(Pos)

    Input(Pos).Purchase = CDbl(InputBox("Enter purchase amount"))
    Input(Pos).Zip = CInt(InputBox("Enter customer zip"))
    lboIn.Items.Add(Input(Pos).Purchase.ToString.PadLeft(20) & Input(Pos).Zip.ToString.PadLeft(28))
  End Sub


  Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
    'total sales per zip, average sales per zip, zip
    lboOut.Visible = True
    Dim I As Integer
    Dim Pos As Integer
    Pos = UBound(Input) + 1
    Dim ZipStoredLoc As Integer = 0
    Dim Count As Integer = 0
    Array.Sort(Input)           'BROKEN HERE+++++++++++++
    Array.Sort(ZipStore)

    For I = 0 To UBound(Input)
      If (Input(I).Zip) <> ZipStore((Array.BinarySearch(ZipStore, Input(I).Zip))).Zip Then 'Zipstore(gets value if any where zipstore matches Input(I).zip, then puts it in Zipstore Indez so you can use the If statement
        Array.Sort(ZipStore)
        ZipStore(Count).Nbr = ZipStore(Count).Nbr + 1
        ZipStore(Count).Zip = Input(I).Zip
        Count += 1
        Array.Sort(ZipStore)
      ElseIf (Input(I).Zip) = ZipStore((Array.BinarySearch(ZipStore, Input(I).Zip))).Zip Then
        ZipStore(Array.BinarySearch(ZipStore, Input(I).Zip)).Nbr += 1 'adds 1 to the value where zipstore(at index where Input(I) matched Zipstore).Nbr
        Array.Sort(ZipStore)
      End If
    Next
    Array.Sort(ZipStore)
    For I = 0 To UBound(ZipStore)
      lboOut.Items.Add(ZipStore(I).Zip.ToString.PadLeft(20) & ZipStore(I).Nbr.ToString.PadLeft(20))
    Next
  End Sub
End Class
swimboig83 is offline   Reply With Quote
Old May 30th, 2005, 6:37 PM   #2
Wraith Daquell
Programmer
 
Join Date: Feb 2005
Location: Limbo
Posts: 39
Rep Power: 0 Wraith Daquell is on a distinguished road
I know this is kind of late, but we kind of have a rule that we can't help students with their school projects. It destroys the purpose of learning, after all.
However, the MSDN has a great amount of information on what you're trying to do. Think about what you're asking the computer to do... how is it supposed to sort the array? By Purchase? Zip? The solution is easy, finding it may not.
__________________
The meek will inherit the earth.

-WDaquell
Wraith Daquell 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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:53 AM.

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