Question
Please help, for the code below I need to convert the following sub-procedures into functions. Private Sub btnApply_Click(sender As Object, e As EventArgs) Handles btnApply.Click
Please help, for the code below I need to convert the following sub-procedures into functions.
Private Sub btnApply_Click(sender As Object, e As EventArgs) Handles btnApply.Click DateDiffbythirty() ' calling the function DateDiffbythirty() DateDiffbysixty() ' calling the function DateDiffbysixty()
lstOutput.Items.Clear() ' clearing the list items lstOutput.Items.Add("Price Reduction For " & Date.Now.Date) ' Displaying the current date on the top lstOutput.Items.Add("") For Each item As Shop In flowerShop lstOutput.Items.Add("Price Change for " & item.ProductDescription & ":" & " From $" & item.Oldprice & " To $" & item.RetailPrice) Next End Sub
'Need to convert to function!!! Private Sub DateDiffbythirty() 'Function to change retail price that have been in inventory over 30 days and less than or equal o 60 days For i As Integer = 0 To flowerShop.Count - 1 For i As Integer = 0 To flowerShop.Count - 1 flowerShop(i).Oldprice = flowerShop(i).RetailPrice 'storing old price value in oldprice Double Dim date1 As Date = Date.Now 'getting todays date and storing in date 1 Dim date2 As Date = flowerShop(i).PurchaseDate 'getting product purchase date and storing in date 2
Dim span = date1 - date2 ' calulating days difference
Dim days As Double = CDbl(FormatNumber(span.TotalDays, 0)) ' storing final formatted value in variable days If days > 30 And days <= 60 Then ' if product is inventory over 30 days and less than or equal o 60 days it will reduce product price by 20% or wholesale price whichever is greater flowerShop(i).RetailPrice = CDbl(FormatNumber(flowerShop(i).RetailPrice - (flowerShop(i).RetailPrice * 0.2), 2)) ElseIf flowerShop(i).RetailPrice < flowerShop(i).WholesailPrice Then flowerShop(i).RetailPrice = flowerShop(i).WholesailPrice End If Next End Sub
'Need to convert to function!!! Private Sub DateDiffbysixty() 'Function to change retail price that have been in inventory over 60 days For i As Integer = 0 To flowerShop.Count - 1 Dim date1 As Date = Date.Now 'getting todays date Dim date2 As Date = flowerShop(i).PurchaseDate 'getting product purchase date Dim span = date1 - date2 ' calulating days difference Dim days As Double = CDbl(FormatNumber(span.TotalDays, 0)) ' storing final formatted value in variable days If days > 60 Then ' if product is inventory over 60 days it will reduce product price by 50% flowerShop(i).RetailPrice = CDbl(FormatNumber(flowerShop(i).RetailPrice - (flowerShop(i).RetailPrice * 0.5), 2)) End If Next End Sub End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started