Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,925 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,916 people online right now. Registration is fast and FREE... Join Now!




ListBox items question

 
Reply to this topicStart new topic

ListBox items question

mbowers
12 Dec, 2007 - 07:08 PM
Post #1

New D.I.C Head
*

Joined: 12 Dec, 2007
Posts: 1


My Contributions
CODE
Public Class Form1

    Private strMovie(9) As String
    Private intMatinee(9) As Integer
    Private intEvening(9) As Integer
    Private intCounter As Integer = 0


    Private Sub btnAddMovie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddMovie.Click

        strMovie(intCounter) = InputBox("Enter the movie name")
        intMatinee(intCounter) = InputBox("Enter the number of matinee tickets sold")
        intEvening(intCounter) = InputBox("Enter the number of evening tickets sold")
        lstMovies.Items.Add(strMovie(intCounter))
        intCounter += 1

    End Sub

    Private Sub btnShowSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowSelected.Click
        Dim strMovie As String = ""
        Dim decTicketSales As Decimal = 0

        strMovie = lstMovies.SelectedItem
        decTicketSales = intMatinee(lstMovies.SelectedIndex) * 6 + _
            intEvening(lstMovies.SelectedIndex) * 8

        lblOutput.Text = "The sales for movie " & strMovie & _
            " is " & decTicketSales.ToString("c")

    End Sub

    Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
        Dim decTicketSales As Decimal
        Dim strMovie As String = ""

        strMovie = lstMovies.SelectedItem

        If radMatinee.Checked Then
            decTicketSales = intMatinee(lstMovies.SelectedIndex) * 6
        Else : decTicketSales = intEvening(lstMovies.SelectedIndex) * 8
        End If

        lblOutput.Text = "The total ticket sales for movie " & strMovie & _
        " are " & decTicketSales.ToString("c")
    End Sub

    Private Sub btnHighest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHighest.Click

    End Sub
End Class


This is a final project for my VB05 class. We add movies to the list box then the number of matinee and evening tickets sold per movie. Got that part down. Got the option of choosing the total tickets sales per movie for matinee or evening. Also have that done. BtnHighest and BtnLowest are the only things causing me a problem. They select the highest or lowest ticket sales for the day with either matinee or evening selected.

The program runs fine with the exception of those 2 buttons. Any suggestions as to how to get those to work are greatly appreciated. If you can suggest anyway to clean up my code a little also, that would be great. Still a beginner at this.

Thanks in advance.
User is offlineProfile CardPM
+Quote Post

ahmad_511
RE: ListBox Items Question
14 Dec, 2007 - 12:36 PM
Post #2

D.I.C Regular
Group Icon

Joined: 28 Apr, 2007
Posts: 351



Thanked: 8 times
Dream Kudos: 400
My Contributions
Hello ...

I figure out this .. try this code

CODE

    Private Sub btnHighest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHighest.Click
        lstMovies.SelectedIndex = HighLow(True)
    End Sub

    Private Sub btnLowest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLowest.Click
        lstMovies.SelectedIndex = HighLow(False)
    End Sub
    Private Function HighLow(ByVal IsHieghest As Boolean) As Integer

        Dim X, hNDX, lNDX As Integer
        Dim Total As Integer
        Dim Max As Integer = 0
        Dim Min As Integer = 9999

        For X = 0 To lstMovies.Items.Count - 1
            Total = intEvening(X) * 8 + intMatinee(X) * 6
            If Total > Max Then Max = Total : hNDX = X
            If Total < Min Then Min = Total : lNDX = X
        Next

        If IsHieghest Then Return hNDX Else Return lNDX

    End Function


The function calculate the maximum and minimum of each movie alone and returns the index of the movie in the list.

note ... if you pass true, the function return the max movie index other wise will return min movie index

P.S. you need to use
CODE

If lstMovies.SelectedIndex = -1 then Exit sub


... to prevent errors .. i beleive you know this ...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 02:56PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month