2014-10-13 2 views
1

3 개의 레이블을 함께 추가하려고합니다. 그 중 2 개는 글로벌 변수에 해당하고, 3 번째는 2 개의 글로벌 변수에 대한 세금 계산에 해당합니다. 프로그램을 사용할 때 최종 세금 라벨이 아닌 두 개의 전역 변수 만 추가합니다.VB에서 3 개의 레이블을 추가하는 방법 6

Sub bill() 
    Total = Val(lblRefreshmentPrice) + Val(lblTicketprice) 
    lblBillTaxPrice = Format(Total * 0.13, "Currency") 
End Sub 

Private Sub Form_Load() 
    lblRefreshmentPrice = RefreshmentPrice 
    lblTicketprice = Ticketprice 
    lblFinalTotalPrice = Val(lblRefreshmentPrice) + Val(lblTicketprice) + Val(lblBillTaxPrice) 
    Call bill 
End Sub 
+0

코드가 있습니까? – matsjoyce

+0

그게 계산을위한 코드 일 뿐이며, 더 많은 것이 있습니다. 무엇을하려고합니까? 2 개의 글로벌 변수에 대한 세금을 계산 한 다음 2 개의 글로벌 변수를 추가합니다. 세금을 계산했습니다. –

+1

'Val (lblRefreshmentPrice) '를 사용하여 가치가 나쁘다. 산술을 수행 할 때 기본 숫자 값 (RefreshmentPrice)을 사용해야합니다. 레이블에서 값을 가져와야하는 경우 * Val (lblRefreshmentPrice.Caption)과 같은 숫자로 텍스트를 변환해야합니다. – djv

답변

1

확실하지 않은 것이 무엇인지 잘 모르겠습니다. 방금 청소했습니다.

Private RefreshmentPrice As Currency 
Private TicketPrice As Currency 
Private BillTaxPrice As Currency 
Private FinalTotalPrice As Currency 
Private Total As Currency 

Const TaxRate As Double = 0.13 


Sub bill() 
    ' calculate total before tax 
    Total = RefreshmentPrice + TicketPrice 
    ' calculate tax 
    BillTaxPrice = Total * TaxRate 
    ' calculate total price with tax 
    FinalTotalPrice = RefreshmentPrice + TicketPrice + BillTaxPrice 
    ' set labels 
    lblRefreshmentPrice.Caption = Format(RefreshmentPrice, "Currency") 
    lblTicketprice.Caption = Format(TicketPrice, "Currency") 
    lblFinalTotalPrice.Caption = Format(FinalTotalPrice, "Currency") 
    lblBillTaxPrice.Caption = Format(BillTaxPrice, "Currency") 
End Sub 

Private Sub Form_Load() 
    ' set up globals (for debug) 
    RefreshmentPrice = 8 
    TicketPrice = 50 
    ' calculate and set labels 
    bill 
End Sub 
+0

죄송합니다. Verlolino는 혼란 스럽지만 제가 도움이 필요한 것은 제 3 레이블을 추가하는 것입니다. 합산되는 유일한 것들은 ticketprice와 refreshmentprice입니다. –

+0

모두 안에 있습니다. 레이블이 아닌 숫자를 추가한다는 점에 유의하십시오. 그런 다음 레이블을 설정합니다. – djv

+0

그래서 나는 그것을 사용하려고했지만 프로그램은 Format (RefreshmentPrice)이 정의 된 변수가 아니라는 것을 알려주고있다. @Verdolino –

관련 문제