Solved

VB.net Rate box not clearing properly

Posted on 2009-05-12
27
161 Views
Last Modified: 2012-05-06
I have a subroutine CalcDir which fires off when a checkbox called txtDirProdID is checked.  My txtRate box however is not clearing to 0 like it should if the box is unchecked.  My     CalcSubtotal()
 and CalcTotal() routines do set the txtTotal and txtSubtotal boxes to $0 if unchecked.    I am sure it is something small I am missing.  See the code below.
'On page Load
 

    'Set value for Directory Advertising if selected

        If ckDirAd.Checked Then

            txtDirProdID.Text = "1"

            Directory.Visible = True

        Else

            txtDirProdID.Text = "0"

            Directory.Visible = False

            txtDirColor.Text = "0"
 

'Subroutine
 

    Sub CalcDirectory()
 

        If ckDirAd.Checked = True And Val(txtDirOverride.Text) <= 0 Then

            txtDirRate.Text = FormatCurrency(Session("SizePrice") + Session("SpecialPrice") + Val(txtDirColor.Text))
 

        ElseIf ckDirAd.Checked = True And Val(txtDirOverride.Text) > 0 Then

            txtDirRate.Text = FormatCurrency(Session("DirOverride"))

        Else

            txtDirRate.Text = "0"

        End If

        ' Store value of txtDirRate as a Session Variable

        Dim DirRate As Double

        DirRate = txtDirRate.Text

        Session("DirRate") = DirRate

        CalcSubtotal()
 

    End Sub
 

    Sub CalcTotal()

        If Convert.ToDateTime(lblDateRequested.Text) <= Convert.ToDateTime("7/31/2009") And txtSubtotal.Text >= 1000 And ckEarlyBird.Checked = True Then

            lblEarlyBird.Text = "You qualify for the early bird special (10% Discount)"

            lblEarlyBird.Visible = True

            ckEarlyBird.Visible = True
 

            txtTotal.Text = FormatCurrency(txtSubtotal.Text * 0.9)

        Else

            txtTotal.Text = FormatCurrency(txtSubtotal.Text)

            lblEarlyBird.Visible = False

            ckEarlyBird.Visible = False

        End If

    End Sub

Open in new window

0
Comment
Question by:Albee_J
  • 16
  • 6
  • 5
27 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
Comment Utility
Check whether you are overriding txtdir value at any other place.

0
 

Author Comment

by:Albee_J
Comment Utility
I can't find it anywhere. I will post all of this massive code to see if another set of eyes can catch it.  I think I may be starring at it too long to see anything anymore *laugh*


Partial Class InsertOrders

    Inherits System.Web.UI.Page
 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim rightNow As DateTime = DateTime.Now

        lblDateRequested.Text = String.Format("{0:d}", rightNow)

        lblUserName.Text = User.Identity.Name
 

        'Hide Web Advertising unless Michael Scott is logged in

        If User.Identity.Name = "mscott" Then

            Michael.Visible = True

        End If

        'Set value for Directory Advertising if selected

        If ckDirAd.Checked Then

            txtDirProdID.Text = "1"

            Directory.Visible = True

        Else

            txtDirProdID.Text = "0"

            Directory.Visible = False

            txtDirColor.Text = "0"
 
 

        End If

        'Set value for Enhanced Listing if selected

        If ckEnhanced.Checked Then

            txtEnhancedProdID.Text = "7"

            Enhanced.Visible = True

        Else

            txtEnhancedProdID.Text = "0"

            Enhanced.Visible = False

        End If

        'Set value for Show Daily if selected

        If ckShowDaily.Checked Then

            txtShowDailyProdID.Text = "2"

            ShowDaily.Visible = True

        Else

            txtShowDailyProdID.Text = "0"

            ShowDaily.Visible = False

            txtShowColor.Text = "0"

        End If
 

        'Set value for Trade Show Map if selected

        If ckTradeShow.Checked Then

            txtTShowProdID.Text = "3"

            TradeShow.Visible = True

        Else

            txtTShowProdID.Text = "0"

            TradeShow.Visible = False

            txtShowColor.Text = "0"

        End If
 

        'Set value for Floor Logos if selected

        If ckFloorLogos.Checked Then

            txtFloorLogosProdID.Text = "4"

            FloorLogos.Visible = True

        Else

            txtFloorLogosProdID.Text = "0"

            FloorLogos.Visible = False

            txtCarpetRate.Text = "0"
 

        End If
 

        If Not Page.IsPostBack Then

            'Create data table to grab prices for Directory Advertising Product Sizes

            Dim dTable As New Data.DataTable

            Dim dbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", "Data Source=FMASQL;Initial Catalog=FabtechSales;Persist Security Info=True;User ID=**;Password=**")

            dbadp.Fill(dTable)

            '  txtTest.Text = "Table Row Count: " & dTable.Rows.Count

            dbadp.Dispose()

            Session("dTable") = dTable

            'then the ddl code here

            'ddlDirSize.DataSource = dTable

            ddlDirSize.DataTextField = "OptionType"

            ddlDirSize.DataValueField = "OptionID"
 

            ' Create data table to grab prices for Show Daily Product Sizes

            Dim ShowTable As New Data.DataTable

            Dim Showbadp As New Data.SqlClient.SqlDataAdapter("Select * from ProductSizes", "Data Source=FMASQL;Initial Catalog=FabtechSales;Persist Security Info=True;User ID=**;Password=**")

            Showbadp.Fill(ShowTable)

            Showbadp.Dispose()

            Session("ShowTable") = ShowTable

            'then the ddl code here

            ddlShowSize.DataTextField = "OptionType"

            ddlShowSize.DataValueField = "OptionID"
 

            'create Data table for Directory Advertising Premium Positions

            Dim sTable As New Data.DataTable

            Dim sbadp As New Data.SqlClient.SqlDataAdapter("Select * from SpecialPositions", "Data Source=FMASQL;Initial Catalog=FabtechSales;Persist Security Info=True;User ID=**;Password=**")

            sbadp.Fill(sTable)

            sbadp.Dispose()

            Session("sTable") = sTable

            'then the ddl code here

            ddlDirPremium.DataTextField = "Positions"

            ddlDirPremium.DataValueField = "SpecialPositionID"

           

            'create Data table for Show Daily Premium Positions

            Dim DailyTable As New Data.DataTable

            Dim Dailybadp As New Data.SqlClient.SqlDataAdapter("Select * from SpecialPositions", "Data Source=FMASQL;Initial Catalog=FabtechSales;Persist Security Info=True;User ID=**;Password=**")

            Dailybadp.Fill(DailyTable)

            Dailybadp.Dispose()

            Session("DailyTable") = DailyTable

            'then the ddl code here

            ddlShowPrem.DataTextField = "Positions"

            ddlShowPrem.DataValueField = "SpecialPositionID"

        End If
 

    End Sub

    Sub CalcMultiple()

        Const Multiple As Double = 500
 

        If ckMultiple.Checked = True And Val(txtMultipleOverride.Text) <= 0 Then

            txtMultipleRate.Text = FormatCurrency(Multiple)

        ElseIf ckMultiple.Checked = True And Val(txtMultipleOverride.Text) > 0 Then

            txtMultipleRate.Text = FormatCurrency(Session("MultipleOverride"))

        Else

            txtMultipleRate.Text = "0"

        End If
 

        ' Store value of txtMultipleRate as a Session Variable

        Dim DirMultiple As Double

        DirMultiple = txtMultipleRate.Text

        Session("DirMultiple") = DirMultiple
 
 

        CalcSubtotal()
 

    End Sub

    Sub CalcDirectory()
 

        If ckDirAd.Checked = True And Val(txtDirOverride.Text) <= 0 Then

            txtDirRate.Text = FormatCurrency(Session("SizePrice") + Session("SpecialPrice") + Val(txtDirColor.Text))
 

        ElseIf ckDirAd.Checked = True And Val(txtDirOverride.Text) > 0 Then

            txtDirRate.Text = FormatCurrency(Session("DirOverride"))

        Else

            txtDirRate.Text = "0"
 

        End If

        ' Store value of txtDirRate as a Session Variable

        Dim DirRate As Double

        DirRate = txtDirRate.Text

        Session("DirRate") = DirRate

        CalcSubtotal()
 

    End Sub

    Sub CalcShow()
 

        If ckShowDaily.Checked = True And Val(txtShowOverride.Text) <= 0 Then

            txtShowRate.Text = FormatCurrency(Session("ShowSize") + Session("ShowPremPrice") + Val(txtShowColor.Text))
 

        ElseIf ckShowDaily.Checked = True And Val(txtShowOverride.Text) > 0 Then

            txtShowRate.Text = FormatCurrency(Session("ShowOverride"))

        Else

            txtShowRate.Text = "0"

        End If

        ' Store value of txtShowRate as a Session Variable

        Dim ShowRate As Double

        ShowRate = txtShowRate.Text

        Session("ShowRate") = ShowRate

        CalcSubtotal()
 

    End Sub

    Sub CalcEnhanced()

        If ckEnhanced.Checked = True And Val(txtEnhRateOverride.Text) <= 0 Then

            txtEnhancedRate.Text = FormatCurrency(Val(txtWebLevel.Text))
 

        ElseIf ckEnhanced.Checked = True And Val(txtEnhRateOverride.Text) > 0 Then

            txtEnhancedRate.Text = FormatCurrency(Session("EnhancedOverride"))

        Else

            txtEnhancedRate.Text = "0"

        End If

        ' Store value of txtEnhancedRate as a Session Variable

        Dim EnhancedRate As Double

        EnhancedRate = txtEnhancedRate.Text

        Session("EnhancedRate") = EnhancedRate

        CalcSubtotal()
 

    End Sub

    Sub CalcTrade()
 

        If ckTradeShow.Checked = True And Val(txtTradeOverride.Text) <= 0 Then

            txtTradeRate.Text = FormatCurrency(Val(txtBCRate.Text) + Val(txtBackCoverRate.Text))
 

        ElseIf ckTradeShow.Checked = True And Val(txtTradeOverride.Text) > 0 Then

            txtTradeRate.Text = FormatCurrency(Session("TradeOverride"))

        Else

            txtTradeRate.Text = "0"

        End If

        ' Store value of txtEnhancedRate as a Session Variable

        Dim TradeRate As Double

        TradeRate = txtTradeRate.Text

        Session("TradeRate") = TradeRate

        CalcSubtotal()
 

    End Sub

    Sub CalcFloorLogos()

        If ckFloorLogos.Checked = True And Val(txtFloorOverride.Text) <= 0 Then

            txtFloorRate.Text = FormatCurrency(Val(txtCarpetRate.Text))
 

        ElseIf ckFloorLogos.Checked = True And Val(txtFloorOverride.Text) > 0 Then

            txtFloorRate.Text = FormatCurrency(Session("FloorOverride"))

        Else

            txtFloorRate.Text = "0"

        End If

        ' Store value of txtEnhancedRate as a Session Variable

        Dim FloorRate As Double

        FloorRate = txtFloorRate.Text

        Session("FloorRate") = FloorRate

        CalcSubtotal()
 

    End Sub

    Sub CalcSubtotal()

        txtSubtotal.Text = FormatCurrency(Session("DirRate") + Session("DirMultiple") + Session("EnhancedRate") + Session("ShowRate") + Session("TradeRate") + Session("FloorLogos"))

        CalcTotal()
 

    End Sub

    Sub CalcTotal()

        If Convert.ToDateTime(lblDateRequested.Text) <= Convert.ToDateTime("7/31/2009") And txtSubtotal.Text >= 1000 And ckEarlyBird.Checked = True Then

            lblEarlyBird.Text = "You qualify for the early bird special (10% Discount)"

            lblEarlyBird.Visible = True

            ckEarlyBird.Visible = True
 

            txtTotal.Text = FormatCurrency(txtSubtotal.Text * 0.9)

        Else

            txtTotal.Text = FormatCurrency(txtSubtotal.Text)

            lblEarlyBird.Visible = False

            ckEarlyBird.Visible = False

        End If

    End Sub

    Protected Sub txtMultiple_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckMultiple.CheckedChanged
 

        If ckMultiple.Checked = True Then

            lblSecondary.Text = "Secondary Company Name:"

            lblSecondary.ToolTip = "Enter in Secondary company name as it is to be shown in directory/web"

            lblMultipleIn.Visible = True

            ckMultipleIn.Visible = True

            lblMultipleRate.Visible = True

            txtMultipleRate.Visible = True

            lblMultipleOverride.Visible = True

            txtMultipleOverride.Visible = True
 
 

        Else

            lblSecondary.Text = "Other Advertiser:"

            lblSecondary.ToolTip = "Not Exhibiting or sharing a booth, list company name"

            lblMultipleIn.Visible = False

            ckMultipleIn.Visible = False

            lblMultipleRate.Visible = False

            txtMultipleRate.Visible = False

            lblMultipleOverride.Visible = False

            txtMultipleOverride.Visible = False
 

        End If

        CalcMultiple()

    End Sub

    Protected Sub ddlDirSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDirSize.SelectedIndexChanged
 

        'SelectedIndex changed

        Dim dTable As Data.DataTable = Session("dTable")

        If Not IsNothing(dTable) Then

            Dim ID As Integer = ddlDirSize.SelectedValue

            dTable.DefaultView.RowFilter = "OptionID=" & ID
 

            If dTable.DefaultView.Count = 1 Then

                Dim SizePrice As Integer

                SizePrice = dTable.DefaultView.Item(0).Item("OptionPrice")

                Session("SizePrice") = SizePrice

                txtDirSizePrice.Text = "Rate:" & " " & FormatCurrency(Session("SizePrice"))

            End If

        End If

        CalcDirectory()

    End Sub

    Protected Sub ddlDirPremium_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDirPremium.SelectedIndexChanged

        'SelectedIndex changed

        Dim sTable As Data.DataTable = Session("sTable")

        If Not IsNothing(sTable) Then

            Dim ID As Integer = ddlDirPremium.SelectedValue

            sTable.DefaultView.RowFilter = "SpecialPositionID=" & ID
 
 

            If sTable.DefaultView.Count = 1 Then

                Dim SpecialPrice As Integer

                SpecialPrice = sTable.DefaultView.Item(0).Item("PositionPrice")

                Session("SpecialPrice") = SpecialPrice

                txtDirPremPrice.Text = "Rate:" & " " & FormatCurrency(Session("SpecialPrice"))

            End If

        End If

        CalcDirectory()
 

    End Sub

    Protected Sub ckDirAd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirAd.CheckedChanged

        CalcDirectory()

    End Sub
 

    Protected Sub rdDirColor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdDirColor.SelectedIndexChanged

        If Page.IsPostBack Then

            If rdDirColor.SelectedItem.Value = "2 color" Then

                txtDirColor.Text = "400"

            ElseIf rdDirColor.SelectedItem.Value = "4 color" Then

                txtDirColor.Text = "900"

            Else

                txtDirColor.Text = "0"

            End If

        End If

        CalcDirectory()

    End Sub
 

    Protected Sub txtDirOverride_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDirOverride.TextChanged

        Dim DirOverride As Integer

        DirOverride = Val(txtDirOverride.Text)

        Session("DirOverride") = DirOverride

        CalcDirectory()

    End Sub
 

    Protected Sub rdWebLevel_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdWebLevel.SelectedIndexChanged

        If Page.IsPostBack Then

            If rdWebLevel.SelectedItem.Value = "Classic " Then

                txtWebLevel.Text = "500"

            ElseIf rdWebLevel.SelectedItem.Value = "Premium " Then

                txtWebLevel.Text = "750"

            ElseIf rdWebLevel.SelectedItem.Value = "Ultra" Then

                txtWebLevel.Text = "1700"

            Else

                txtWebLevel.Text = "0"

            End If

        End If
 

        CalcEnhanced()

    End Sub
 

    Protected Sub txtEnhRateOverride_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEnhRateOverride.TextChanged

        Dim EnhancedOverride As Integer

        EnhancedOverride = Val(txtEnhRateOverride.Text)

        Session("EnhancedOverride") = EnhancedOverride

        CalcEnhanced()

    End Sub
 

    Protected Sub ddlShowSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlShowSize.SelectedIndexChanged

        'SelectedIndex changed

        Dim ShowTable As Data.DataTable = Session("ShowTable")

        If Not IsNothing(ShowTable) Then

            Dim ID As Integer = ddlShowSize.SelectedValue

            ShowTable.DefaultView.RowFilter = "OptionID=" & ID
 

            If ShowTable.DefaultView.Count = 1 Then

                Dim ShowSize As Integer

                ShowSize = ShowTable.DefaultView.Item(0).Item("OptionPrice")

                Session("ShowSize") = ShowSize

                txtShowSizePrice.Text = "Rate:" & " " & FormatCurrency(Session("ShowSize"))

            End If

        End If

        CalcShow()

    End Sub
 

    Protected Sub ddlShowPrem_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlShowPrem.SelectedIndexChanged

        'SelectedIndex changed

        Dim DailyTable As Data.DataTable = Session("DailyTable")

        If Not IsNothing(DailyTable) Then

            Dim ID As Integer = ddlShowPrem.SelectedValue

            DailyTable.DefaultView.RowFilter = "SpecialPositionID=" & ID
 
 

            If DailyTable.DefaultView.Count = 1 Then

                Dim ShowPremPrice As Integer

                ShowPremPrice = DailyTable.DefaultView.Item(0).Item("PositionPrice")

                Session("ShowPremPrice") = ShowPremPrice

                txtShowPremPrice.Text = "Rate:" & " " & FormatCurrency(Session("ShowPremPrice"))

            End If

        End If

        CalcShow()

    End Sub
 

    Protected Sub rdShowColors_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdShowColors.SelectedIndexChanged

        If Page.IsPostBack Then

            If rdShowColors.SelectedItem.Value = "2 color" Then

                txtShowColor.Text = "400"

            ElseIf rdShowColors.SelectedItem.Value = "4 color" Then

                txtShowColor.Text = "900"

            Else

                txtShowColor.Text = "0"

            End If

        End If

        CalcShow()

    End Sub
 

    Protected Sub ckShowDaily_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckShowDaily.CheckedChanged

        CalcShow()

    End Sub
 

    Protected Sub txtShowOverride_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtShowOverride.TextChanged

        Dim ShowOverride As Integer

        ShowOverride = Val(txtShowOverride.Text)

        Session("ShowOverride") = ShowOverride

        CalcShow()

    End Sub
 

    Protected Sub ckEarlyBird_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckEarlyBird.CheckedChanged

        CalcTotal()

    End Sub
 

    Protected Sub ckBusinessCard_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckBusinessCard.CheckedChanged

        If ckBusinessCard.Checked = True Then

            txtBCRate.Text = "1995"

        Else

            txtBCRate.Text = "0"

        End If

        CalcTrade()

    End Sub
 

    Protected Sub ckBackCover_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckBackCover.CheckedChanged

        If ckBackCover.Checked = True Then

            txtBackCoverRate.Text = "4995"

        Else

            txtBackCoverRate.Text = "0"

        End If

        CalcTrade()

    End Sub
 

    Protected Sub txtTradeOverride_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTradeOverride.TextChanged

        Dim TradeOverride As Integer

        TradeOverride = Val(txtTradeOverride.Text)

        Session("TradeOverride") = TradeOverride

        CalcTrade()

    End Sub
 

    Protected Sub txtMultipleOverride_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMultipleOverride.TextChanged

        Dim MultipleOverride As Integer

        MultipleOverride = Val(txtMultipleOverride.Text)

        Session("MultipleOverride") = MultipleOverride

        CalcMultiple()

    End Sub
 

    Protected Sub ckCarpetOverlays_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckCarpetOverlays.CheckedChanged

        If ckCarpetOverlays.Checked = True Then

            txtCarpetRate.Text = "2000"

        Else

            txtCarpetRate.Text = "0"

        End If

        CalcFloorLogos()

    End Sub
 

    Protected Sub txtFloorOverride_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFloorOverride.TextChanged

        Dim FloorOverride As Integer

        FloorOverride = Val(txtFloorOverride.Text)

        Session("FloorOverride") = FloorOverride

        CalcFloorLogos()

    End Sub
 

    Protected Sub ckEnhanced_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckEnhanced.CheckedChanged

        CalcEnhanced()

    End Sub
 

    Protected Sub ckTradeShow_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckTradeShow.CheckedChanged

        CalcTrade()

    End Sub
 

    Protected Sub ckFloorLogos_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckFloorLogos.CheckedChanged

        CalcFloorLogos()

    End Sub

End Class

Open in new window

0
 
LVL 11

Expert Comment

by:srikanthreddyn143
Comment Utility
Iam looking at the code mean while can u debug step by step and look into textbox value
0
 

Author Comment

by:Albee_J
Comment Utility
Yes, I will see if I can get the break and step by step to work. Last time I tried on this application it wouldn't debug properly even though I have it set to debug.
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
Comment Utility
Hit F11 to move into functions too so we can notice changes inside the funcs
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Do you mean that txtDirRate does not change to 0 in the else part of this code
     If ckDirAd.Checked = True And Val(txtDirOverride.Text) <= 0 Then
            txtDirRate.Text = FormatCurrency(Session("SizePrice") + Session("SpecialPrice") + Val(txtDirColor.Text))
 
        ElseIf ckDirAd.Checked = True And Val(txtDirOverride.Text) > 0 Then
            txtDirRate.Text = FormatCurrency(Session("DirOverride"))
        Else
            txtDirRate.Text = "0"
        End If
?
0
 

Author Comment

by:Albee_J
Comment Utility
I tried, I set a Breakpoint and it never breaks... I hit F11 fires off the application, never breaks.
0
 

Author Comment

by:Albee_J
Comment Utility
I would think this has to be working

Else
            txtDirRate.Text = "0"

 End If
        ' Store value of txtDirRate as a Session Variable
        Dim DirRate As Double
        DirRate = txtDirRate.Text
        Session("DirRate") = DirRate
        CalcSubtotal()


because the   CalcSubtotal() resets to 0 when I uncheck the box.
In the checkbox it has this code

 Protected Sub ckDirAd_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ckDirAd.CheckedChanged
        CalcDirectory()
    End Sub
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
Comment Utility
Try this

  Sub CalcDirectory()
       txtDirRate.Focus()
        If ckDirAd.Checked = True And Val(txtDirOverride.Text) <= 0 Then
            txtDirRate.Text = FormatCurrency(Session("SizePrice") + Session("SpecialPrice") + Val(txtDirColor.Text))
 
        ElseIf ckDirAd.Checked = True And Val(txtDirOverride.Text) > 0 Then
            txtDirRate.Text = FormatCurrency(Session("DirOverride"))
        Else
            txtDirRate.Text = "0"
        End If
        ' Store value of txtDirRate as a Session Variable
        Dim DirRate As Double
        DirRate = txtDirRate.Text
        Session("DirRate") = DirRate
        CalcSubtotal()
 
    End Sub
0
 

Author Comment

by:Albee_J
Comment Utility
Will do srikanthreddyn143.  I will test and post back
0
 

Author Comment

by:Albee_J
Comment Utility
txtDirRate.Focus()  didn't make any difference.  The   txtDirRate.Text box is still retaining its value after I uncheck the box.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Your use of Session suggests that its a web application. Have you set the AutoPostback property of the checkbox to true?
0
 

Author Comment

by:Albee_J
Comment Utility
Yes.  I think I may have narrowed the problem down.

In the Directory area there is a dropdown list that I am populating with a data table. It is this value that the textbox is holding onto even though the ddl looks to be set to the 'none' option on refresh.

   Protected Sub ddlDirSize_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDirSize.SelectedIndexChanged

        'SelectedIndex changed
        Dim dTable As Data.DataTable = Session("dTable")
        If Not IsNothing(dTable) Then
            Dim ID As Integer = ddlDirSize.SelectedValue
            dTable.DefaultView.RowFilter = "OptionID=" & ID

            If dTable.DefaultView.Count = 1 Then
                Dim SizePrice As Integer
                SizePrice = dTable.DefaultView.Item(0).Item("OptionPrice")
                Session("SizePrice") = SizePrice
                txtDirSizePrice.Text = "Rate:" & " " & FormatCurrency(Session("SizePrice"))
            End If
        End If
        CalcDirectory()
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Now i am confused. You problem is that the txtDirRate is not being set to 0 in the if condition here

 If ckDirAd.Checked = True And Val(txtDirOverride.Text) <= 0 Then
            txtDirRate.Text = FormatCurrency(Session("SizePrice") + Session("SpecialPrice") + Val(txtDirColor.Text))
 
        ElseIf ckDirAd.Checked = True And Val(txtDirOverride.Text) > 0 Then
            txtDirRate.Text = FormatCurrency(Session("DirOverride"))
        Else
            txtDirRate.Text = "0"
        End If


Is that correct? If not please explain in functional terms which line of code you have problem with.
0
 

Author Comment

by:Albee_J
Comment Utility
Sorry.

Ok. The problem lies if I select a value in the drop down list. ddlDirSize  which is part of the   CalcDirectory() Subroutine. (Session("SizePrice")  

If I uncheck the box which fires off the CalcDirectory() Subroutine the   txtDirRate.Text = "0" is not really showing. It is still holding the value of  (Session("SizePrice")    not matter what.



0
 

Author Comment

by:Albee_J
Comment Utility
I figure it out!

On page load I added this    Session.Clear()  to the code below.

 'Set value for Directory Advertising if selected
        If ckDirAd.Checked Then
            txtDirProdID.Text = "1"
            Directory.Visible = True
        Else
            txtDirProdID.Text = "0"
            Directory.Visible = False
            txtDirColor.Text = "0"
            Session.Clear()
0
 

Author Comment

by:Albee_J
Comment Utility
crap I spoke to soon that clears too much LOL
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
My question again is "is the autopostback set to true on checkbox" or in more plain terms "does the page postback when you tick or untick the checkbox?"
0
 

Author Comment

by:Albee_J
Comment Utility
Yes it does. The autopostback function on the checkbox is set to true. The value from the dropdown list which is stored as a variable is not clearing.


I think I may have figured it out again..

       Session.Remove("SizePrice")
0
 

Accepted Solution

by:
Albee_J earned 0 total points
Comment Utility
Yep that was it.

I added        Session.Remove("SizePrice")  to my page load

  'Set value for Directory Advertising if selected
        If ckDirAd.Checked Then
            txtDirProdID.Text = "1"
            Directory.Visible = True
        Else
            txtDirProdID.Text = "0"
            Directory.Visible = False
            txtDirColor.Text = "0"
            ' Clear the values of the drop down lists
            Session.Remove("SizePrice")
            Session.Remove("SpecialPrice")
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Hmm. So it means wrong condition is being met in your calcdir method! I think the problem is this if condition
Val(txtDirOverride.Text) <= 0

Try changing this to
Val(txtDirOverride.Text) = 0
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
Comment Utility
Any have the checkbox is unchecked, that makes the if condition false and goes to txtdirrate.text = "0". Am I Right?
0
 

Author Comment

by:Albee_J
Comment Utility
ah k lemme try that.
0
 

Author Comment

by:Albee_J
Comment Utility
CodeCruiser:  That didn't work. the textbox still has the drop down list rate in it.  
0
 

Author Comment

by:Albee_J
Comment Utility
srikanthreddyn143,

Yes that is what it is supposed to do.
0
 

Author Comment

by:Albee_J
Comment Utility
This is on page load

-----------------------------

   'Set value for Show Daily if selected
        If ckShowDaily.Checked Then
            txtShowDailyProdID.Text = "2"
            ShowDaily.Visible = True
        Else
            txtShowDailyProdID.Text = "0"
            ShowDaily.Visible = False
            txtShowColor.Text = "0"
            Session.Remove("ShowSize")
            Session.Remove("ShowPremPrice")
        End If

------------------------------
This also fired when the checkbox is checked

    Sub CalcDirectory()
        txtDirRate.Focus()
        If ckDirAd.Checked = True And Val(txtDirOverride.Text) <= 0 Then
            txtDirRate.Text = FormatCurrency(Session("SizePrice") + Session("SpecialPrice") + Val(txtDirColor.Text))

        ElseIf ckDirAd.Checked = True And Val(txtDirOverride.Text) > 0 Then
            txtDirRate.Text = FormatCurrency(Session("DirOverride"))
        Else
            txtDirRate.Text = "0"
            txtDirOverride.Text = "0"


        End If
        ' Store value of txtDirRate as a Session Variable
        Dim DirRate As Double
        DirRate = txtDirRate.Text
        Session("DirRate") = DirRate
        CalcSubtotal()

    End Sub
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
@srikanthreddyn143
True. I overlooked.
Anyway, the problem is solved now by removing the session value on load.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now