Here is the first part of the If Statement: 1: We then print to the console and read the line. Next we initialize our variable myVAT and create a new object when you use a new keyword you are creating an object. Here we have a variable called f which is nothing. Copy this: Dim f As String = NothingĬonsole.WriteLine("PRESS C TO CALCULATE TOTAL PRODUCT COST INC VAT, PRESS R TO CALCULATE VAT AMOUNT PAID, PRESS A TO CALCULATE ORIGINAL PRICE") Inside this method we will write our code, and we will use an If Statement to determine the function the user has chosen. There are 3 functions in our application. Return to Module.vb and add the following below the Sub Main method: Sub VATApp() Now that we have written the methods it is time to call them. Then we simply subtract itemcost from original price. First we get the percentage multiplier, and then we divide the product cost by the percentage multiplier. The last method finds the amount of VAT paid when VAT is already included in the price. ![]() Method 3 Public Function origPrice(ByVal itemCost As Double, ByVal vatRate As Double) ![]() This method is similar to the previous one, except we return the totalCost (VAT has been added) subtracted from productCost (original amount ex VAT). Public Function CalculateVAT(ByVal productCost As Double, ByVal currentRate As Double)ĭim CR As Double = (currentRate + 100) / 100 This time we will calculate the VAT amount which is being paid. We also have two parameters, pCost and cRate, which are used to make the calculation when we ask the user for the product cost and VAT rate. We have a variable called CR which calculates the percentage multiplier, and we then return pCost * CR (ProductCost * CurrentRate). To calculate the VAT we use the percentage multiplier, so the current VAT rate is 20%: This method calculates the total product cost when VAT is added. Calculate the amount of VAT paid when the product already has VAT addedĬomment out the previous code you have written, and then make a new class file and name it VAT.vb. We will write three methods: Method 1 Public Function totalProductCost(ByVal pCost As Double, ByVal cRate As Double).Calculate total product cost including VAT.When you type m圜ar. you will get the list of methods this class has. Finally, we print out the details the user entered. Then we print to the console and read the user’s results, as in previous tutorials. ![]() This class is quite simple: First we create the variable m圜ar and then initialize it. In the Module.vb file, add: Dim m圜ar As New Car()Ĭonsole.WriteLine("Please enter your car manufacturer: ")ĭim m As String = m圜ar.manufacturer(Console.ReadLine())Ĭonsole.WriteLine("Please enter car model :")ĭim mo As String = m圜ar.model(Console.ReadLine())Ĭonsole.WriteLine("Please enter car colour")ĭim c As String = m圜ar.colour(Console.ReadLine())Ĭonsole.WriteLine("You car details: " & vbLf & " " & m & " " & vbLf & " " & mo & vbLf & " " & c) Here we have made several methods and are simply returning the parameter. Public Function colour(vcolour As String) Copy the code below: Public Function manufacturer(vmanufacturer As String) Next we are going to create some methods. In solution explorer, right click on classes and make a new class file. Create a new Visual Basic Console Application and name it Classes.
0 Comments
Leave a Reply. |