6 Replies - 352 Views - Last Post: 14 February 2018 - 08:09 AM Rate Topic: -----

#1 Mani1233   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-February 18

My code is not calculating

Posted 13 February 2018 - 05:02 AM

 Dim Title As String
        Dim Books As Integer
        Dim Costperbook As Single
        Dim Totalcost As Decimal
        Dim Voucher As String
        Dim DiscountRate As Single

        Costperbook = 15.99
        Voucher = 25
        txtTitle.Text = Title
        Books = txtBooks.Text
        txtTotalcost.Text = Totalcost

        txtTitle.Text = InputBox("Please Enter your book name")
        txtBooks.Text = InputBox("Please Enter Amount you'd like to buy")
        txtCostperbook.Text = InputBox("Please Enter the cost of the book", & 15.99 &)
        txtVoucher.Text = InputBox("Please Say yes or no")

        Books = InputBox("You cannot order less than 1 book or  more than 80", "Enter Amount")
        Do While Books <= 1 Or Books >= 80
            MsgBox("Your entry is out of range please choose amount from 1-80")
            Books = InputBox("You cannot order less than 1 book or  more than 80", "Enter Amount")
        Loop
        Voucher = InputBox("Please enter Y or y if you are using a voucher if not Enter N or n if you are not using voucher", "Pick an answear")
        Do Until Voucher = "Y" Or Voucher = "y" Or Voucher = "N" Or Voucher "n"
            MsgBox("Voucher incorrect, Please try again")
            Voucher = ("Please try again")

        Loop

        If Books <= 5 Or Books >= 10 Then
            DiscountRate = 0.05
        End If

        If Books <= 11 Or Books >= 50 Then
            DiscountRate = 0.075
        End If

        If Books <= 51 Or Books >= 80 Then
            DiscountRate = 0.1
        End If

        If Voucher = "Y" Or Voucher = "y" Then
            Totalcost = Format((Costperbook * Books) - DiscountRate - 25 "0.00")

        End If

        If Voucher = "N" Or Voucher = "n" Then
            Totalcost = Format(Books * Costperbook)
        End If
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtBooks.Clear()
        txtCostperbook.Clear()
        txtVoucher.Clear()
        txtTotalcost.Clear() 



I am getting errors like:BC30201 twice
then BC30205
.....BC302017

I've searched for help, my code is not working gives me error when i start it and it crashes plus it is not calculating

Is This A Good Question/Topic? 0
  • +

Replies To: My code is not calculating

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14101
  • View blog
  • Posts: 56,522
  • Joined: 12-June 08

Re: My code is not calculating

Posted 13 February 2018 - 07:36 AM

Please copy/paste the full error text.
Was This Post Helpful? 0
  • +
  • -

#3 maceysoftware   User is offline

  • Foo
  • member icon

Reputation: 353
  • View blog
  • Posts: 1,535
  • Joined: 07-September 13

Re: My code is not calculating

Posted 13 February 2018 - 10:18 AM

Not sure that this is the issue, however:

Line 44 is wrong:

Totalcost = Format((Costperbook * Books) - DiscountRate - 25 "0.00")

The function has two parameters which you are providing, however(kind of), you are missing a comma after 25 and before your second value.

Line 16

You don't need the & in the second parameter
Was This Post Helpful? 0
  • +
  • -

#4 Mallard8   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 05-February 18

Re: My code is not calculating

Posted 13 February 2018 - 02:50 PM

Here's how I got it to work not sure if it's the best way?
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim Books As Integer
        Dim Costperbook As Single
        Dim Totalcost As Decimal
        Dim Voucher As String
        Dim DiscountRate As Single

        Voucher = ""
        txtTitle.Text = ""


        txtTitle.Text = InputBox("Please Enter your book name")
        txtBooks.Text = InputBox("Please Enter Amount you'd like to buy")
        txtCostperbook.Text = InputBox("Please Enter the cost of the book", 15.99)
        Voucher = InputBox("Please enter Y or y if you are using a voucher if not Enter N or n if you are not using voucher", "Pick an answear")
        Books = Val(txtBooks.Text)
        txtTotalcost.Text = Totalcost

        Do While txtBooks.Text <= 1 Or Books >= 80
            MsgBox("Your entry is out of range please choose amount from 1-80")
            txtBooks.Text = InputBox("You cannot order less than 1 book or  more than 80", "Enter Amount")
        Loop


        If Books >= 5 And Books <= 10 And Voucher = "y" Then
            DiscountRate = 0.05
        ElseIf Books >= 11 And Books <= 50 And Voucher = "y" Then
            DiscountRate = 0.075
        ElseIf Books >= 51 And Books <= 80 And Voucher = "y" Then
            DiscountRate = 0.1
        End If

        If txtVoucher.Text = "Y" Or txtVoucher.Text = "y" Then
            Totalcost = Format((Costperbook * Books) - DiscountRate - 25, "0.00")
        End If

        If Voucher = "N" Or Voucher = "n" Or Voucher = "Y" Or Voucher = "y" Then
            txtTotalcost.Text = Books * Val(txtCostperbook.Text)
            txtTotalcost.Text = Val(txtTotalcost.Text) - DiscountRate
        End If
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtTitle.Clear()
        txtBooks.Clear()
        txtCostperbook.Clear()
        txtVoucher.Clear()
        txtTotalcost.Clear()

    End Sub


Was This Post Helpful? 0
  • +
  • -

#5 Mallard8   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 05-February 18

Re: My code is not calculating

Posted 14 February 2018 - 02:20 AM

Changed, had to post again as I couldn't figure how to edit post?
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim Books As Integer
        Dim Costperbook As Single
        Dim Totalcost As Decimal
        Dim Voucher As String
        Dim DiscountRate As Single

        Voucher = ""
        txtTitle.Text = ""

        txtTitle.Text = InputBox("Please Enter your book name")
        txtBooks.Text = InputBox("Please Enter Amount you'd like to buy")
        Books = Val(txtBooks.Text)
        Do While Books <= 1 Or Books >= 80 'Check amount of books before moving on
            MsgBox("Your entry is out of range please choose amount from 1-80")
            txtBooks.Text = InputBox("You cannot order less than 1 book or  more than 80", "Enter Amount")
            Books = Val(txtBooks.Text) 'Reset amount of books
        Loop
        txtCostperbook.Text = InputBox("Please Enter the cost of the book", 15.99)
        Voucher = InputBox("Please enter Y or y if you are using a voucher if not Enter N or n if you are not using voucher", "Pick an answear")
        txtTotalcost.Text = Totalcost

        If Books >= 5 And Books <= 10 And Voucher = "y" Then
            DiscountRate = 0.5
            txtVoucher.Text = "Discount Applied"
        ElseIf Books >= 11 And Books <= 50 And Voucher = "y" Then
            DiscountRate = 0.75
            txtVoucher.Text = "Discount Applied"
        ElseIf Books >= 51 And Books <= 80 And Voucher = "y" Then
            DiscountRate = 0.1
            txtVoucher.Text = "Discount Applied"
        Else
            txtVoucher.Text = "No Discount"
        End If

        If txtVoucher.Text = "Y" Or txtVoucher.Text = "y" Then
            Totalcost = Format((Costperbook * Books) - DiscountRate - 25, "0.00")
        End If

        If Voucher = "N" Or Voucher = "n" Or Voucher = "Y" Or Voucher = "y" Then
            txtTotalcost.Text = Books * Val(txtCostperbook.Text)
            txtTotalcost.Text = Val(txtTotalcost.Text) - DiscountRate
        End If

    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtTitle.Clear()
        txtBooks.Clear()
        txtCostperbook.Clear()
        txtVoucher.Clear()
        txtTotalcost.Clear()
    End Sub
End Class



Was This Post Helpful? 0
  • +
  • -

#6 Mallard8   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 05-February 18

Re: My code is not calculating

Posted 14 February 2018 - 08:05 AM

Another way, which I think is better still. Now shows cost before and after discount.
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim Books As Integer
        Dim Totalcost, DiscountRate As Decimal
        Dim Voucher As String

        Voucher = ""
        txtTitle.Text = ""

        txtTitle.Text = InputBox("Please Enter your book name")
        txtBooks.Text = InputBox("Please Enter Amount you'd like to buy")
        Books = Val(txtBooks.Text)
        Do While Books <= 1 Or Books >= 80 'Check amount of books before moving on
            MsgBox("Your entry is out of range please choose amount from 1-80")
            txtBooks.Text = InputBox("You cannot order less than 1 book or  more than 80", "Enter Amount")
            Books = Val(txtBooks.Text) 'Reset amount of books
        Loop
        txtCostperbook.Text = InputBox("Please Enter the cost of the book", 15.99)
        Voucher = InputBox("Please enter Y or y if you are using a voucher if not Enter N or n if you are not using voucher", "Pick an answear")

        If Books >= 5 And Books <= 10 And Voucher = "y" Then
            DiscountRate = 5 '5% Discount
            txtVoucher.Text = "5% Discount Applied"
        ElseIf Books >= 11 And Books <= 50 And Voucher = "y" Then
            DiscountRate = 10 '10% Discount
            txtVoucher.Text = " 10% Discount Applied"
        ElseIf Books >= 51 And Books <= 80 And Voucher = "y" Then
            DiscountRate = 15 '15% Discount
            txtVoucher.Text = "15% Disount Applied"
        Else
            txtVoucher.Text = "No Discount"
        End If

        If Voucher = "N" Or Voucher = "n" Or Voucher = "Y" Or Voucher = "y" Then
            Totalcost = Books * Val(txtCostperbook.Text)
            txtBeforeDiscount.Text = FormatCurrency(Totalcost)
            txtTotalcost.Text = FormatCurrency(Totalcost - (DiscountRate / 100) * Totalcost)
        End If
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtTitle.Clear()
        txtBooks.Clear()
        txtCostperbook.Clear()
        txtVoucher.Clear()
        txtTotalcost.Clear()
    End Sub
End Class



Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14101
  • View blog
  • Posts: 56,522
  • Joined: 12-June 08

Re: My code is not calculating

Posted 14 February 2018 - 08:09 AM

@mallard8 - would you explain what you did? We hope folk try and not just do other's homework for them or just dump code and run sans explanation. Typically that helps the OP now, and any one reading in the future.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1