Click here to Skip to main content
15,881,380 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionWorking from scratch based on created application Pin
Herboren3-Oct-12 5:49
Herboren3-Oct-12 5:49 
I have a teacher who gave us a compiled application. He did not provide us the code. We have to generate the code in our head and write it out. It must act like his application in every possible way. I have it written out but for some reason when I type in the value of two(2) pieces the two(2) isn't calculated yet every other number I type calculates just fine. Why?

two(2) falls within range of 1-199 so its price would be calculated as rangeA * two(2) pieces = price for two, but no result is returned, my text does not display in the textbox either.

VB
 Dim priceArrayElements(20) As Decimal ' Store Prices calculated, 21 count
    Dim pieceArrayElements(20) As Integer ' Store Pieces counted, 21 count

    Dim addedPieces ' Total of all Piece elements added together
    Dim totalAveragePieces ' Average of Piece elements added together / element count

    Dim addedPrices As Decimal ' Total of all price elements added together
    Dim totalAveragePrices As Decimal ' Average of Price elements added together / element count

    Dim elementCounter As Decimal ' Global Counter for both arrays

    Dim rangeA As Decimal = 0.5  ' Price applies to range   1 - 199
    Dim rangeB As Decimal = 0.55 ' Price applies to range 200 - 399
    Dim rangeC As Decimal = 0.6  ' Price applies to range 400 - 599
    Dim rangeD As Decimal = 0.65 ' Price applies to range 600 - >

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case False
            Case IsNumeric(txtPieces.Text)
                MessageBox.Show("Pieces completed must be numeric.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtPieces.Text = ""

            Case Not IsNumeric(txtName.Text)
                MessageBox.Show("Name is required.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtName.Text = ""

            Case Else

                Select Case txtPieces.Text
                    Case 1 To 199
                        Try
                            For i As Integer = 0 To priceArrayElements.Length
                                priceArrayElements(i) = (Decimal.Parse(txtPieces.Text) * rangeA)
                                txtEarned.Text = FormatCurrency(priceArrayElements(i).ToString())
                            Next
                        Catch ex As Exception
                            'Supress Message
                        End Try
                    Case 200 To 399
                        Try
                            For i As Integer = 0 To priceArrayElements.Length
                                priceArrayElements(i) = (Decimal.Parse(txtPieces.Text) * rangeB)
                                txtEarned.Text = FormatCurrency(priceArrayElements(i).ToString())
                            Next
                        Catch ex As Exception
                            'Supress Message
                        End Try
                    Case 400 To 599
                        Try
                            For i As Integer = 0 To priceArrayElements.Length
                                priceArrayElements(i) = (Decimal.Parse(txtPieces.Text) * rangeC)
                                txtEarned.Text = FormatCurrency(priceArrayElements(i).ToString())
                            Next
                        Catch ex As Exception
                            'Supress Message
                        End Try
                    Case Else
                        If Int32.Parse(txtPieces.Text) >= 600 Then
                            Try
                                For i As Integer = 0 To priceArrayElements.Length
                                    priceArrayElements(i) = (Decimal.Parse(txtPieces.Text) * rangeD)
                                    txtEarned.Text = FormatCurrency(priceArrayElements(i).ToString())
                                Next
                            Catch ex As Exception
                                'Supress Message
                            End Try
                        End If
                End Select

        End Select

    End Sub

End Class

AnswerRe: Working from scratch based on created application Pin
Eddy Vluggen3-Oct-12 22:46
professionalEddy Vluggen3-Oct-12 22:46 
AnswerRe: Working from scratch based on created application Pin
Dominick Marciano11-Oct-12 19:02
professionalDominick Marciano11-Oct-12 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.