473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.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.Bl ogger.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

Aug 19 '07 #1
5 1486
<ry**********@gmail.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")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
Aug 19 '07 #2
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

Aug 19 '07 #3
<ry**********@gmail.comschrieb
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

Aug 19 '07 #4
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


"Armin Zingler" <az*******@freenet.deschreef in bericht
news:e5**************@TK2MSFTNGP06.phx.gbl...
<ry**********@gmail.comschrieb
>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

Aug 19 '07 #5
Nice one Michel, does the job!

-Ryan
Aug 19 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
6
by: lkrubner | last post by:
I'm offering users the ability to type weblog posts into a form and post them. They type the text into a TEXTAREA which is on a form. The form, when submitted, hits a PHP script. Before it is...
26
by: I_AM_DON_AND_YOU? | last post by:
This is the scenario: I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right...
8
by: QQ | last post by:
SpreadsheetCell(const string& initialValue); I don't understand what & means here? Thank you very much! A C++ beginner
2
by: lotus | last post by:
HI All.. I'm realtively new to C#. I have MainForm which includes Parent usercontol, and this parent usercontrol also contains child usercontrol. MainForm --> Parent usercontrol --> child...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
52
by: Julie | last post by:
I'm supporting an application at work. Below are some code segments that I can't understand how they work. First let me say, I would never code this standard. I'm just really creeped out that it...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
22
by: Cogito | last post by:
For the first time, I'm attempting to write a small Javascript program using one on the online reference sites. I need some confirmation as to the behaviour of the break statement. In the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.