Why Does this Modular Variable Value Change?

R

ryanwpenfold

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.Page

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

''' <summary>
''' Can be "Add" or "Edit"
''' </summary>
<System.ComponentModel.DefaultValue(GetType(PCC.Blogger.Function),
"Add")> Protected Property Mode() As PCC.Blogger.Function
Get
If BlogID = -1 Then
_intMode = PCC.Blogger.Function.Add
Else
_intMode = PCC.Blogger.Function.Edit
End If
Return _intMode
End Get
Set(ByVal value As PCC.Blogger.Function)
_intMode = value
End Set
End Property

<System.ComponentModel.DefaultValue(-1)> Protected Property BlogID()
As Integer
Get
If _intBlogID = -1 Then
Try
_intBlogID = CType(Request.QueryString("blogID"), 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.Function.Add
_intBlogID = -1
End Sub

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

End Class
 
A

Armin Zingler

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")> Protected Property Mode() As PCC.Blogger.Function
Get

You are calling the BlogID property here:
If BlogID = -1 Then

<System.ComponentModel.DefaultValue(-1)> Protected Property
BlogID() As Integer
Get
If _intBlogID = -1 Then
Try

And here you change the value, probably to 0:
_intBlogID = CType(Request.QueryString("blogID"), Integer)



Armin
 
R

ryanwpenfold

Hi Armin,

The value Request.QueryString("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
 
A

Armin Zingler

Hi Armin,

The value Request.QueryString("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
 
M

Michel Posseth [MCP]

in the case of a null ( Nothing ) ctype returns a 0 so i guess the
request.querystring 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.ComponentModel.DefaultValue(-1)> Protected Property BlogID() As
Integer

Get

If _intBlogID = -1 Then

If Not Integer.TryParse(Request.QueryString("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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top