jeudi 9 juin 2016

How can I use elseif to fix my code?

I have this Excel VBA code that should tell me which sum to pay based on the product, but wether I type "credit" or any other product it skips the first IF statement and gets to the second one.

I'd like to know how I can use else if so it will genarate the right sum.

Here is the code:

Dim prod As String
Dim sumam As Integer
Dim total As Integer
Dim rate As Integer

prod = InputBox("Introduceti tipul de produs")
total = InputBox("Introduceti suma totala de plata")

If prod = credit Then
   If total < 1000 Then sumam = 175
   If total > 1000 And total < 3000 Then sumam = 350
   If total > 3000 And total < 6000 Then sumam = 425
Else
   If total < 1000 Then sumam = 150
   If total > 1000 And total < 2000 Then sumam = 200
   If total > 2000 And total < 5000 Then sumam = 325
   If total > 5000 And total < 8000 Then sumam = 450
   If total > 8000 And total < 12000 Then sumam = 550
   If total > 12000 Then sumam = 675
rate = total / sumam

textprod.Text = prod
textprod.TextAlign = fmTextAlignRight
texttot.Text = total
texttot.TextAlign = fmTextAlignRight
textsumm.Text = sumam
textsumm.TextAlign = fmTextAlignRight
textrate.Text = rate
textrate.TextAlign = fmTextAlignRight

End If
End Sub

Aucun commentaire:

Enregistrer un commentaire