моя программа Visual Basi c для расчета квитанции (с использованием подпрограмм и функции проверки) не работает - PullRequest
1 голос
/ 29 февраля 2020

Это мой код для программы для расчета квитанции с использованием подпрограмм и функции проверки. часть проверки не работает вообще. пожалуйста, помогите, я новичок в области визуальных основ c

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        'program to add prices to get a receipt

        'declare variables 
        Dim price1 As Single
        Dim price2 As Single
        Dim price3 As Single
        Dim receipt As Single

        'call procedures
        Call get_prices(price1, price2, price3)
        Call calculate_receipt(price1, price2, price3, receipt)
        Call display_receipt(receipt)

        price1 = validateprice(price1)
        price2 = validateprice(price2)
        price3 = validateprice(price3)
    End Sub


    Sub get_prices(ByRef price1, ByRef price2, ByRef price3)
        price1 = InputBox("Enter first price.")
        price2 = InputBox("Enter second price.")
        price3 = InputBox("Enter third price.")
    End Sub


    Sub calculate_receipt(ByVal price1, ByVal price2, ByVal price3, ByRef receipt)
        receipt = price1 + price2 + price3
    End Sub


    Sub display_receipt(ByVal receipt)
        ListBox1.Items.Add("The receipt is £" & receipt)
    End Sub


    'function validate price
    Function validateprice(price)
        Do
            If price < 2 Or price > 49.99 Then
                MsgBox("Incorrect value. Enter again.")
                price = InputBox("Enter value between £2 and £49.99")
            End If
        Loop Until price >= 2 And price <= 49.99
        validateprice = price
    End Function

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End
    End Sub
End Class

1 Ответ

0 голосов
/ 02 марта 2020

Мне может понадобиться более подробная информация по этому вопросу, но похоже, что все не в порядке.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    'program to add prices to get a receipt

    'declare variables 
    Dim price1 As Single
    Dim price2 As Single
    Dim price3 As Single
    Dim receipt As Single

    'call procedures
    'commenting this out - Call get_prices(price1, price2, price3)
    'Please note the order of this, now this should get your value and validate!
    price1 = validateprice(price1)
    price2 = validateprice(price2)
    price3 = validateprice(price3)
    Call calculate_receipt(price1, price2, price3, receipt)
    Call display_receipt(receipt)


End Sub

Кроме того, закомментируйте эту строку

'MsgBox("Incorrect value. Enter again.") 'so you can have it ask in the same place. 

Вы можете предоставить подсказку как значение тоже.

'function validate price
Function validateprice(price, prompt)
    Do
        If price < 2 Or price > 49.99 Then
            'MsgBox("Incorrect value. Enter again.")
            price = InputBox(prompt)
        End If
    Loop Until price >= 2 And price <= 49.99
    validateprice = price
End Function
...