Why Does this Modular Variable Value Change?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ryanwpenfold@gmail.com

    #1

    Why Does this Modular Variable Value Change?

    Hi,

    The variable _intBlogID changes from -1 to 0 when the Mode_Get method
    is called. I don't understand why this happens. I included default
    property values, and that didn't help. I wrote and called the method
    Properties_Set( ) and that didn't help. Can anyone provide a solution?
    Please see code below.

    Thanks in advance.

    Ryan Penfold, Portsmouth, UK




    Option Strict On

    Partial Class AddEditBlog
    Inherits System.Web.UI.P age

    Protected _intMode As PCC.Blogger.Fun ction =
    PCC.Blogger.Fun ction.Add
    Protected _intBlogID As Integer = -1

    ''' <summary>
    ''' Can be "Add" or "Edit"
    ''' </summary>
    <System.Compone ntModel.Default Value(GetType(P CC.Blogger.Func tion),
    "Add")Prote cted Property Mode() As PCC.Blogger.Fun ction
    Get
    If BlogID = -1 Then
    _intMode = PCC.Blogger.Fun ction.Add
    Else
    _intMode = PCC.Blogger.Fun ction.Edit
    End If
    Return _intMode
    End Get
    Set(ByVal value As PCC.Blogger.Fun ction)
    _intMode = value
    End Set
    End Property

    <System.Compone ntModel.Default Value(-1)Protected Property BlogID()
    As Integer
    Get
    If _intBlogID = -1 Then
    Try
    _intBlogID = CType(Request.Q ueryString("blo gID"), Integer)
    Catch ee As Exception
    _intBlogID = -1
    End Try
    End If
    Return _intBlogID
    End Get
    Set(ByVal value As Integer)
    _intBlogID = value
    End Set
    End Property

    Protected Sub Properties_Set( )
    _intMode = PCC.Blogger.Fun ction.Add
    _intBlogID = -1
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    If Not IsPostBack Then
    Properties_Set( )
    End If
    lblAddEditBlog. Text = Mode.ToString & " Blog"
    End Sub

    End Class

  • Armin Zingler

    #2
    Re: Why Does this Modular Variable Value Change?

    <ryanwpenfold@g mail.comschrieb
    Hi,
    >
    The variable _intBlogID changes from -1 to 0 when the Mode_Get
    method is called. I don't understand why this happens. I included
    default property values, and that didn't help. I wrote and called
    the method Properties_Set( ) and that didn't help. Can anyone provide
    a solution? Please see code below.
    "Add")Prote cted Property Mode() As PCC.Blogger.Fun ction
    Get
    You are calling the BlogID property here:
    If BlogID = -1 Then
    <System.Compone ntModel.Default Value(-1)Protected Property
    BlogID() As Integer
    Get
    If _intBlogID = -1 Then
    Try
    And here you change the value, probably to 0:
    _intBlogID = CType(Request.Q ueryString("blo gID"), Integer)


    Armin

    Comment

    • ryanwpenfold@gmail.com

      #3
      Re: Why Does this Modular Variable Value Change?

      Hi Armin,

      The value Request.QuerySt ring("blogID") is equal to "", so an
      exception should be thrown / caught.

      I cannot set an initial value of BlogID to -1, it's always worked
      before, I can't think what I'm doing different.

      Ryan

      Comment

      • Armin Zingler

        #4
        Re: Why Does this Modular Variable Value Change?

        <ryanwpenfold@g mail.comschrieb
        Hi Armin,
        >
        The value Request.QuerySt ring("blogID") is equal to "", so an
        exception should be thrown / caught.
        >
        I cannot set an initial value of BlogID to -1, it's always worked
        before, I can't think what I'm doing different.

        I didn't know the value of Querystring, that's why I assumed that it returns
        0. Other than that, I don't see any code that can set it to 0.


        Armin

        Comment

        • Michel Posseth  [MCP]

          #5
          Re: Why Does this Modular Variable Value Change?

          in the case of a null ( Nothing ) ctype returns a 0 so i guess the
          request.queryst ring returns a null value instead of a "" empty string wich
          indeed wil raise an error by ctype

          proofe ?? copy paste this under a button

          msgbox (ctype(nothing, integer))

          you wil see that it returns 0

          so change your property code to this ( copy pastable )

          <System.Compone ntModel.Default Value(-1)Protected Property BlogID() As
          Integer

          Get

          If _intBlogID = -1 Then

          If Not Integer.TryPars e(Request.Query String("blogID" ), _intBlogID) Then

          _intBlogID = -1

          End If

          End If

          Return _intBlogID

          End Get

          Set(ByVal value As Integer)

          _intBlogID = value

          End Set

          End Property



          and it should work as you expected



          HTH



          Michel Posseth








          "Armin Zingler" <az.nospam@free net.deschreef in bericht
          news:e5$7ECp4HH A.1484@TK2MSFTN GP06.phx.gbl...
          <ryanwpenfold@g mail.comschrieb
          >Hi Armin,
          >>
          >The value Request.QuerySt ring("blogID") is equal to "", so an
          >exception should be thrown / caught.
          >>
          >I cannot set an initial value of BlogID to -1, it's always worked
          >before, I can't think what I'm doing different.
          >
          >
          I didn't know the value of Querystring, that's why I assumed that it
          returns
          0. Other than that, I don't see any code that can set it to 0.
          >
          >
          Armin
          >

          Comment

          • ryanwpenfold@gmail.com

            #6
            Re: Why Does this Modular Variable Value Change?

            Nice one Michel, does the job!

            -Ryan


            Comment

            Working...