I am a beginner in vb.net and I have problem with my code which I do not know how to modify. Any assistance will be highly appreciated.
Here´s the case:
The code that I have wrote calculates the taxation of a service for a specific year. E.g. If we would like to calculate the tax for year 2000 and the management contract commenced on 1/1/2000 and the management contract expired on 31/12/2002, the code calculates the tax for years 2000-2002. I would like to modify the code to calculate the tax from 1/1/2000 until 31/12/2000 eventhough the contract expires in 2002 since the year for tax calculation is 2000. How do i do that?
Here´s the code:
<%@ Page Language="VB" EnableEventValidation="true" %>
<script runat="server">
Private strParam1 As String = ""
Private intYear As Integer = Year(DateTime.Now) - 1
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Page.IsPostBack = False Then
Try
ddlTaxYear.SelectedIndex = ddlTaxYear.Items.IndexOf(ddlTaxYear.Items.FindByValue(intYear))
ddlFromYear.SelectedIndex = ddlFromYear.Items.IndexOf(ddlFromYear.Items.FindByValue(intYear))
ddlToYear.SelectedIndex = ddlToYear.Items.IndexOf(ddlToYear.Items.FindByValue(intYear))
Response.Write(strParam1)
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End If
End Sub
Protected Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If ValidateFields() = True Then
CalculateTonnageTax()
End If
End Sub
Private Function ValidateFields() As Boolean
Dim ret As Boolean = True
lblError1.Text = ""
lblError2.Text = ""
lblError3.Text = ""
lblError4.Text = ""
lblResult.Text = ""
If txtYearLaid.Text.Trim = "" Then
lblError1.Text = " * Required Field"
Return False
End If
If IsNumeric(txtYearLaid.Text.Trim) = False Then
lblError1.Text = " * Invalid Year"
Return False
End If
If CInt(txtYearLaid.Text.Trim) < 1900 Or CInt(txtYearLaid.Text.Trim) > 2015 Then
lblError1.Text = " * Year must be between 1900 and 2015"
Return False
End If
If txtTonnage.Text.Trim = "" Then
lblError2.Text = " * Required Field"
Return False
End If
If IsNumeric(txtTonnage.Text.Trim) = False Then
lblError2.Text = " * Invalid Gross Tonnage"
Return False
End If
Dim strDateFrom As String = ddlFromDay.SelectedItem.Value & "-" & ddlFromMonth.SelectedItem.Text & "-" & ddlFromYear.SelectedItem.Value
Dim strDateTo As String = ddlToDay.SelectedItem.Value & "-" & ddlToMonth.SelectedItem.Text & "-" & ddlToYear.SelectedItem.Value
If IsDate(strDateFrom) = False Then
lblError3.Text = " * Invalid Date"
Return False
End If
If IsDate(strDateTo) = False Then
lblError4.Text = " * Invalid Date"
Return False
End If
If CDate(strDateFrom) > CDate(strDateTo) Then
lblError4.Text = " * From Date Field cannot be greater than the To Date Field"
Return False
End If
Return True
End Function
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("Shipping1.aspx")
End Sub
Private Sub CalculateTonnageTax()
Dim dtDateFrom As Date = CDate(ddlFromDay.SelectedItem.Value & "-" & ddlFromMonth.SelectedItem.Text & "-" & ddlFromYear.SelectedItem.Value)
Dim dtDateTo As Date = CDate(ddlToDay.SelectedItem.Value & "-" & ddlToMonth.SelectedItem.Text & "-" & ddlToYear.SelectedItem.Value)
Dim dblTonnage As Double = txtTonnage.Text
Dim intTaxYear As Integer = ddlTaxYear.SelectedItem.Value
Dim intYearLaid As Integer = CInt(txtYearLaid.Text)
Dim intAge As Integer = intTaxYear - intYearLaid
Dim intDayDiff As Integer = DateDiff(DateInterval.Day, dtDateFrom, dtDateTo)
Dim intMonthDiff As Integer = DateDiff(DateInterval.Month, dtDateFrom, dtDateTo) + 1
Dim dblTax As Double = 0
If dblTonnage <= 1600 Then
dblTax = dblTonnage * 0.444236
ElseIf dblTonnage <= 10000 Then
dblTax = (1600 * 0.444236) + ((dblTonnage - 1600) * 0.273376)
ElseIf dblTonnage <= 50000 Then
dblTax = (1600 * 0.444236) + (8400 * 0.273376) + ((dblTonnage - 10000) * 0.102516)
Else
dblTax = (1600 * 0.444236) + (8400 * 0.273376) + (40000 * 0.102516) + ((dblTonnage - 50000) * 0.068344)
End If
dblTax = dblTax + 170.86
If intAge <= 10 Then
dblTax = dblTax * 0.75
ElseIf intAge <= 20 Then
dblTax = dblTax * 1.0
Else
dblTax = dblTax * 1.3
End If
If (intMonthDiff <= 1) And (intDayDiff <= 30) Then
'dblTax = 0
intMonthDiff = 0
End If
dblTax = (dblTax * 0.25) * (intMonthDiff / 12)
If rblShipType.SelectedItem.Value = "ship" Then
dblTax = dblTax * 2
End If
lblResult.Text = "Calculated Tax is: €" & dblTax.ToString("#,###.00")
End Sub
Protected Sub ddlFromDay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
</script>
Thanking you in advance.
Here´s the case:
The code that I have wrote calculates the taxation of a service for a specific year. E.g. If we would like to calculate the tax for year 2000 and the management contract commenced on 1/1/2000 and the management contract expired on 31/12/2002, the code calculates the tax for years 2000-2002. I would like to modify the code to calculate the tax from 1/1/2000 until 31/12/2000 eventhough the contract expires in 2002 since the year for tax calculation is 2000. How do i do that?
Here´s the code:
<%@ Page Language="VB" EnableEventValidation="true" %>
<script runat="server">
Private strParam1 As String = ""
Private intYear As Integer = Year(DateTime.Now) - 1
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Page.IsPostBack = False Then
Try
ddlTaxYear.SelectedIndex = ddlTaxYear.Items.IndexOf(ddlTaxYear.Items.FindByValue(intYear))
ddlFromYear.SelectedIndex = ddlFromYear.Items.IndexOf(ddlFromYear.Items.FindByValue(intYear))
ddlToYear.SelectedIndex = ddlToYear.Items.IndexOf(ddlToYear.Items.FindByValue(intYear))
Response.Write(strParam1)
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End If
End Sub
Protected Sub btnCalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If ValidateFields() = True Then
CalculateTonnageTax()
End If
End Sub
Private Function ValidateFields() As Boolean
Dim ret As Boolean = True
lblError1.Text = ""
lblError2.Text = ""
lblError3.Text = ""
lblError4.Text = ""
lblResult.Text = ""
If txtYearLaid.Text.Trim = "" Then
lblError1.Text = " * Required Field"
Return False
End If
If IsNumeric(txtYearLaid.Text.Trim) = False Then
lblError1.Text = " * Invalid Year"
Return False
End If
If CInt(txtYearLaid.Text.Trim) < 1900 Or CInt(txtYearLaid.Text.Trim) > 2015 Then
lblError1.Text = " * Year must be between 1900 and 2015"
Return False
End If
If txtTonnage.Text.Trim = "" Then
lblError2.Text = " * Required Field"
Return False
End If
If IsNumeric(txtTonnage.Text.Trim) = False Then
lblError2.Text = " * Invalid Gross Tonnage"
Return False
End If
Dim strDateFrom As String = ddlFromDay.SelectedItem.Value & "-" & ddlFromMonth.SelectedItem.Text & "-" & ddlFromYear.SelectedItem.Value
Dim strDateTo As String = ddlToDay.SelectedItem.Value & "-" & ddlToMonth.SelectedItem.Text & "-" & ddlToYear.SelectedItem.Value
If IsDate(strDateFrom) = False Then
lblError3.Text = " * Invalid Date"
Return False
End If
If IsDate(strDateTo) = False Then
lblError4.Text = " * Invalid Date"
Return False
End If
If CDate(strDateFrom) > CDate(strDateTo) Then
lblError4.Text = " * From Date Field cannot be greater than the To Date Field"
Return False
End If
Return True
End Function
Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("Shipping1.aspx")
End Sub
Private Sub CalculateTonnageTax()
Dim dtDateFrom As Date = CDate(ddlFromDay.SelectedItem.Value & "-" & ddlFromMonth.SelectedItem.Text & "-" & ddlFromYear.SelectedItem.Value)
Dim dtDateTo As Date = CDate(ddlToDay.SelectedItem.Value & "-" & ddlToMonth.SelectedItem.Text & "-" & ddlToYear.SelectedItem.Value)
Dim dblTonnage As Double = txtTonnage.Text
Dim intTaxYear As Integer = ddlTaxYear.SelectedItem.Value
Dim intYearLaid As Integer = CInt(txtYearLaid.Text)
Dim intAge As Integer = intTaxYear - intYearLaid
Dim intDayDiff As Integer = DateDiff(DateInterval.Day, dtDateFrom, dtDateTo)
Dim intMonthDiff As Integer = DateDiff(DateInterval.Month, dtDateFrom, dtDateTo) + 1
Dim dblTax As Double = 0
If dblTonnage <= 1600 Then
dblTax = dblTonnage * 0.444236
ElseIf dblTonnage <= 10000 Then
dblTax = (1600 * 0.444236) + ((dblTonnage - 1600) * 0.273376)
ElseIf dblTonnage <= 50000 Then
dblTax = (1600 * 0.444236) + (8400 * 0.273376) + ((dblTonnage - 10000) * 0.102516)
Else
dblTax = (1600 * 0.444236) + (8400 * 0.273376) + (40000 * 0.102516) + ((dblTonnage - 50000) * 0.068344)
End If
dblTax = dblTax + 170.86
If intAge <= 10 Then
dblTax = dblTax * 0.75
ElseIf intAge <= 20 Then
dblTax = dblTax * 1.0
Else
dblTax = dblTax * 1.3
End If
If (intMonthDiff <= 1) And (intDayDiff <= 30) Then
'dblTax = 0
intMonthDiff = 0
End If
dblTax = (dblTax * 0.25) * (intMonthDiff / 12)
If rblShipType.SelectedItem.Value = "ship" Then
dblTax = dblTax * 2
End If
lblResult.Text = "Calculated Tax is: €" & dblTax.ToString("#,###.00")
End Sub
Protected Sub ddlFromDay_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
</script>
Thanking you in advance.