Click here to Skip to main content
11,573,322 members (57,798 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB Visual-Studio Basic
Public Class MainForm
 
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
    Me.Close()
End Sub
 
Private Sub guestsTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles guestsTextBox.KeyPress
    ' allows only numbers and the Backspace key

    If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
        e.KeyChar <> ControlChars.Back Then
        e.Handled = True
    End If
End Sub
 
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'fills the list box and selects the first item

    typeListBox.Items.Add("Kid's Birthday")
    typeListBox.Items.Add("21st Birthday")
    typeListBox.Items.Add("40th Birthday")
    typeListBox.Items.Add("Other Birthday")
    typeListBox.SelectedIndex = 0
End Sub
 
Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calcButton.Click
    'displays the total charge

    Dim guests As Integer
    Dim typeIndex As Integer
    Dim guestPrice As Integer
    Dim totalCharge As Integer
 
    Integer.TryParse(guestsTextBox.Text, guests)
    typeIndex = typeListBox.SelectedIndex
 
    'determine the price per guest
    Select Case typeIndex
        Case 0 'Kid's Birthday
            guestPrice = 11
        Case 1 '21st Birthday
            guestPrice = 20
        Case 2 '40th Birthday
            guestPrice = 25
        Case Else 'other birthdays
            guestPrice = 15
    End Select
 
    'calculate and display the total charge
    totalCharge = guests * guestPrice
    totalLabel.Text = totalCharge.ToString("C0")
End Sub
 
Private Sub testDataButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles testDataButton.Click
    Dim guests As Integer
    Dim typeIndex As Integer
    Dim guestPrice As Integer
    Dim totalCharge As Integer
    Dim randomGen As New Random
    Dim setCounter As Integer = 1
 
    testDataLabel.Text = String.Empty
 
    Do
        guests = randomGen.Next(1, 51)
        typeIndex = randomGen.Next(0, 4)
 
        For Each I As Object In typeListBox.SelectedItems
            testDataLabel.Text += I.ToString() & ControlChars.NewLine
        Next
 
        'determine the price per guest
        Select Case typeListBox.SelectedIndex
            Case 0
                guestPrice = 11
            Case 1
                guestPrice = 20
            Case 2
                guestPrice = 25
            Case Else
                guestPrice = 15
        End Select
 
        'calculate and display the total charge
        totalCharge = guests * guestPrice
        testDataLabel.Text = testDataLabel.Text &
            typeIndex.ToString & "    " &
            guests.ToString & "    " &
            totalCharge.ToString("C0") &
            ControlChars.NewLine
        setCounter += 1
 

    Loop Until setCounter > 10
 
End Sub
 
Private Sub typeListBox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles typeListBox.SelectedIndexChanged
 
End Sub
End Class

http://i49.tinypic.com/293c405.png

When I click on a button named "Generate Test Data" It generates a list of random numbers in a label. I want these numbers to say the type of birthday instead of the number.

0 being "Kid's Birthday"

1 being "21st Birthday"

2 being "40th Birthday"

and 3 being "Other Birthday"

How would I go about doing this?

Any help would be much appreciated!
Posted 18-Apr-13 12:08pm
Edited 18-Apr-13 12:11pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

testDataLabel.Text = testDataLabel.Text &
    typeListBox.Items(typeIndex).ToString & "    " &
    guests.ToString & "    " &
    totalCharge.ToString("C0") & vbNewLine 
  Permalink  
v4
Comments
Zach Blomstrom at 18-Apr-13 18:52pm
   
That did it! Thank you so much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150624.2 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100