So I have some of my forms done. But I am stuck I need a basic code to go by so If anyone could provide a basic code I could maybe at least go into the right direction with this. T

This code is supost to go under a module for public use between all my forms in the shopping cart. Its an AddItem function procedure. It is suppost to accept the name of the book, add the book to the list, call the GetPrice, CalculateTax, CalculateShipping, and CalculateTotal to populate the fields on the main form. I will put the code I put into my module so far but I don't think it's all correct.

thanks in advace.


Module Module1
'Global-level Variables
Dim Subtotal As Decimal
Dim strSelectedBook As String
Dim Price As Integer
Dim lblSubTotal As String
Dim lblTax As String
Dim lblShipping As String
Dim lblTotal As String
Dim IstOutPut As String


'Declare class-level constants.
Const decSALESTAXPERCENT As Decimal = CDec(0.06) 'current sales tax
Const intPERITEMSHIPPING As Integer = 2 'item shipping charge

'Dim strInput As String ' Input
Dim strOut As String = String.Empty

Public selectChoice As Boolean = False

' This function adds the book to the list, calls the getprice, calculate tax, calc ship and cal total.


Public Function AddItem() As ItemActivation


End Function


End Module

Recommended Answers

All 2 Replies

How about creating a class instead.
That way you will be able to gather all calculations in one place.

Here's a simple example.

'In your form
Private clsAddItem As AddItemClass
Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button.Click
   clsAddItem = New AddItemClass("book title")
   TaxLabel.Text = clsAddItem.Tax
   ShippingLabel.Text = clsAddItem.Shipping
   ' and so on
End Sub

'A class file
Public Class AddItemClass
#Region " Member Variables "
    Private decSubTotal As Decimal

    Private strSelectedBook As String
    Private strSubTotal As String

    Private intPrice As Integer

    Const decSALESTAXPERCENT As Decimal = CDec(0.06) 'current sales tax
    Const intPERITEMSHIPPING As Integer = 2 'item shipping charge
#End Region

#Region " Constructors "
    Public Sub New()

    End Sub

    Public Sub New(ByVal BookTitle As String)
        strSelectedBook = BookTitle
    End Sub
#End Region

#Region " Private Methods "
    Private Function GetPrice() As String
        ' Check if strSelectedBook = ""
        Return "some price"
    End Function

    Private Function CalculateTax() As String
        ' Check if strSelectedBook = ""
        Return "some tax"
    End Function

    Private Function CalculateShipping() As String
        ' Check if strSelectedBook = ""
        Return "some shipping"
    End Function

    Private Function CalculateTotal() As Decimal
        ' Check if strSelectedBook = ""
        Return 0.0
    End Function
#End Region

#Region " Properties "
    Public ReadOnly Property Price() As String
        Get
            Return GetPrice()
        End Get
    End Property

    Public ReadOnly Property Tax() As String
        Get
            Return CalculateTax()
        End Get
    End Property

    Public ReadOnly Property Shipping() As String
        Get
            Return CalculateShipping()
        End Get
    End Property

    Public ReadOnly Property Total() As Decimal
        Get
            Return CalculateTotal()
        End Get
    End Property

    Public ReadOnly Property SubTotal() As Decimal
        Get
            Return decSubTotal
        End Get
    End Property
#End Region
End Class

Ok, I'll try it that way. I was just going by our teachers directions he gave us. he's not too much help anway. He gets me so more confused as Im not an It person but more in multimedia design so they make us take his class anyway. I'll redo and see if I can get the darn thing to work , thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.