473,416 Members | 1,727 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,416 software developers and data experts.

Comparing String with ASP.net

The following line of vb.net code works fine:

if(strAnswer.toUpper() = strUserAnswer.toUpper())

However in an ASP.net page I'm told

Object reference not set to an instance of an object

What am I doing wrong?

--

Steve Evans
Email Services
SDSU Foundation


Nov 18 '05 #1
4 1322
Its likely that either strAnswer or strUserAnswer is null.

If performance matters, you might also want to use the String.Compare()
function with the case-insensitive flag, as it's faster.

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
The following line of vb.net code works fine:

if(strAnswer.toUpper() = strUserAnswer.toUpper())

However in an ASP.net page I'm told

Object reference not set to an instance of an object

What am I doing wrong?

--

Steve Evans
Email Services
SDSU Foundation

Nov 18 '05 #2
The only possible thing that could be wrong in this case is that one of the
variable values is null. Those are the only 2 object references in the
statement.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
The following line of vb.net code works fine:

if(strAnswer.toUpper() = strUserAnswer.toUpper())

However in an ASP.net page I'm told

Object reference not set to an instance of an object

What am I doing wrong?

--

Steve Evans
Email Services
SDSU Foundation

Nov 18 '05 #3
Okay I found the problem. Apparently I'm having troubles with how to use
global variables.

<script language="VBScript" runat="server>
dim strAnswer as String

sub getInfo()
strAnswer = <the code to get the answer>
end sub

sub validateAnswer()
if(strAnswer.toUpper() = strUserAnswer.toUpper())
etc . . . . .
end sub
</script>

Should the strAnswer from getInfo() be the same strAnswer in
validateAnswer()?
--

Steve Evans
Email Services
SDSU Foundation

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
The only possible thing that could be wrong in this case is that one of the variable values is null. Those are the only 2 object references in the
statement.
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
The following line of vb.net code works fine:

if(strAnswer.toUpper() = strUserAnswer.toUpper())

However in an ASP.net page I'm told

Object reference not set to an instance of an object

What am I doing wrong?

--

Steve Evans
Email Services
SDSU Foundation


Nov 18 '05 #4
Hi Steve,

First of all, that's not a global variable. It's a Private field of your
inherited Page Class (remember, this is object-oriented programming, not
procedural ASP). Secondly, it is not anything until you assign a value to it
(it is null, or Nothing in VB.Net). A field or variable declaration is
simply a declaration that a certain amount of memory space (the size of the
data type) should be allocated for storing that type of data. It has no
value until one is assigned to it.

Your error indicates that an object reference has been used that is null.
There are only 2 objects in the statement; both are strings. Apparently, you
are not assigning a value to at least one of them prior to invoking the Sub
that is comparing them.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
Okay I found the problem. Apparently I'm having troubles with how to use
global variables.

<script language="VBScript" runat="server>
dim strAnswer as String

sub getInfo()
strAnswer = <the code to get the answer>
end sub

sub validateAnswer()
if(strAnswer.toUpper() = strUserAnswer.toUpper())
etc . . . . .
end sub
</script>

Should the strAnswer from getInfo() be the same strAnswer in
validateAnswer()?
--

Steve Evans
Email Services
SDSU Foundation

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
The only possible thing that could be wrong in this case is that one of

the
variable values is null. Those are the only 2 object references in the
statement.
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:eT**************@TK2MSFTNGP09.phx.gbl...
The following line of vb.net code works fine:

if(strAnswer.toUpper() = strUserAnswer.toUpper())

However in an ASP.net page I'm told

Object reference not set to an instance of an object

What am I doing wrong?

--

Steve Evans
Email Services
SDSU Foundation



Nov 18 '05 #5

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

Similar topics

11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
5
by: Curtis Gilchrist | last post by:
I am required to read in records from a file and store them in descending order by an customer number, which is a c-style string of length 5. I am storing these records in a linked list. My...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
88
by: William Krick | last post by:
I'm currently evaluating two implementations of a case insensitive string comparison function to replace the non-ANSI stricmp(). Both of the implementations below seem to work fine but I'm...
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
9
by: subramanian100in | last post by:
Suppose we have char *a = "test message" ; Consider the comparison if (a == "string") ..... Here "string" is an array of characters. So shouldn't the compiler
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.