ASP "IF" Problem

E

Ed Richter

I'm having problems getting an If statement to execute properly. Seems I've
had similar problems in the past whenever my if statements involve number
fields. For text, they work fine.

I have one statement where the statement is:

IF ref_L_name_value = First_L_name_value THEN

This works fine and returns the desired results. But then another statement
I have as follows:

IF Post_1st_Ref_value = ref_ID_num_value THEN

Post_Comment = "Posted"


END IF


I don't get the desired results.

I did a bunch of testing with adding response.write statements to verify
that the program is returning the correct data and it seems to be fine. All
of the variables listed return the expected answer. I did an "IF IsNum"
test
to make sure the results are numeric, again results came back OK


But no matter what I do, I can't seem to get the second IF statement to work
correctly. Seems I've experienced similar problems in the past always when
my IF statement contains numerical values.



Any suggestions as to why it's not working or tricks to do when dealing with
numerical data?



Thanks
 
T

Thomas A. Rowe

How about:

IF ref_L_name_value = First_L_name_value AND Post_1st_Ref_value = ref_ID_num_value THEN
Post_Comment = "Posted"

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
K

Kevin Spencer

Hi Ed,

Your question is a bit confusing.

You mention:
IF Post_1st_Ref_value = ref_ID_num_value THEN

Post_Comment = "Posted"

but then you state:
I did a bunch of testing with adding response.write statements to verify
that the program is returning the correct data and it seems to be fine.
All
of the variables listed return the expected answer. I did an "IF IsNum"
test
to make sure the results are numeric, again results came back OK

This is not clear at all. First, a Response.Write statement isn't going to
tell you anything about the data types. Response.Write always writes a
string. Second, you make a general statment that you "did an "IF IsNum" test
to make sure the "results" are numeric. Which "results" are you referring
to? What is "IsNum"? There is an InNumeric function in VBScript, but I've
never heard of an "IsNum" function. And what did you test with it? Did you
test Post_1st_Ref_value? Did you test ref_ID_num_value?

Finally, you state:
But no matter what I do, I can't seem to get the second IF statement to
work
correctly.

Define "work correctly." What is the nature of the misbehavior?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
E

Ed Richter

What I meant was, I added some, for example; response.write
Post_1st_Ref_value & ref_ID_value to make sure I really was returning a
value, to make sure the variable wasn't empty. That gave me the expected
results, so knew I did have values to compare in IF statement.

When I stated IsNum, I meant IsNumeric and again tested both variables I
was thinking maybe I was trying to use two variables where both were
numbers, but maybe one was a string and one a number so would then be trying
to compare a number to a string.

What I meant by "Work correctly is, I know in this case both
Post_1st_Ref_value and ref_ID_value have the same value, 56 so my IF
statement should be true. They won't always be true, but in this case, it
is, therefore if they are the same, it then should execute the line
Post_Comment = "Posted", but it's not, therefore I'm assuming the reaason
it's not is because it doesn't think bot hvariables are the same. Again the
response.write statements are showing them to be the same.
 
T

Thomas A. Rowe

How are you populating these variables?

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
K

Kevin Spencer

Hi Ed,

Thanks for the clarification. I can see why you're scratching your head. I
have one question: How do you know that the line

Post_Comment = "Posted"

isn't executing? That line just assigns a value to a variable. It doesn't
show any output. Have you tried doing

Response.Write(Post_Comment)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
E

Ed Richter

I do have a response.write Post_comment line and the result is empty Also
as a test I changed my is statement to read:
IF Post_1st_Ref_value <> ref_ID_num_value THEN (replaced = with <>) When
I did that, it did write the word "posted so again all indication are my IF
statement is not executing correctly, but why?
 
T

Thomas A. Rowe

Ed,

<> means that Post_1st_Ref_value is not equal to ref_ID_num_value, so you need to look at the two
values that your comparing and make sure they are the same type.

Were are these two value coming from, the database or from a form?

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
E

Ed Richter

The results are coming from a database. My response.write tag was NOT
getting the word "posted" written to it when I felt it should have. So that
told me that my IF statement for some reason doesn't recognize the two
variables as being equal, even though I'm displaying both of these variables
with other response.write tags, and by reading results can see they both
have the same value.

My thought was since I wasn't getting desired result with = sign, as a test,
let me change to <> and see what I get. Lo and behold the word "posted"
then shows up in response.write statement.

Sinse both variables passed the ISNumeric test, doesn't that mean they must
be the same type?
 
T

Thomas A. Rowe

Should, but what is the actual field type for each in your database?

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================
 
S

Stefan B Rusynko

Test them separately
IF ISNumeric(Post_1st_Ref_value) Then
response.write "Post_1st_Ref_value is numeric and = " & Post_1st_Ref_value
Else
response.write "Post_1st_Ref_value is not numeric"
End IF
IF ISNumeric(ref_ID_num_value) Then
response.write "ref_ID_num_value is numeric and = " & ref_ID_num_value
Else
response.write "ref_ID_num_value is not numeric
End IF





| The results are coming from a database. My response.write tag was NOT
| getting the word "posted" written to it when I felt it should have. So that
| told me that my IF statement for some reason doesn't recognize the two
| variables as being equal, even though I'm displaying both of these variables
| with other response.write tags, and by reading results can see they both
| have the same value.
|
| My thought was since I wasn't getting desired result with = sign, as a test,
| let me change to <> and see what I get. Lo and behold the word "posted"
| then shows up in response.write statement.
|
| Sinse both variables passed the ISNumeric test, doesn't that mean they must
| be the same type?
|
|
| | > Ed,
| >
| > <> means that Post_1st_Ref_value is not equal to ref_ID_num_value, so you
| > need to look at the two values that your comparing and make sure they are
| > the same type.
| >
| > Were are these two value coming from, the database or from a form?
| >
| > --
| > ==============================================
| > Thomas A. Rowe (Microsoft MVP - FrontPage)
| > WEBMASTER Resources(tm)
| >
| > FrontPage Resources, WebCircle, MS KB Quick Links, etc.
| > ==============================================
| > To assist you in getting the best answers for FrontPage support see:
| > http://www.net-sites.com/sitebuilder/newsgroups.asp
| >
| > | >>I do have a response.write Post_comment line and the result is empty Also
| >>as a test I changed my is statement to read:
| >> IF Post_1st_Ref_value <> ref_ID_num_value THEN (replaced = with <>)
| >> When I did that, it did write the word "posted so again all indication
| >> are my IF statement is not executing correctly, but why?
| >>
| >>
| >> | >>> Hi Ed,
| >>>
| >>> Thanks for the clarification. I can see why you're scratching your head.
| >>> I have one question: How do you know that the line
| >>>
| >>> Post_Comment = "Posted"
| >>>
| >>> isn't executing? That line just assigns a value to a variable. It
| >>> doesn't show any output. Have you tried doing
| >>>
| >>> Response.Write(Post_Comment)
| >>>
| >>> --
| >>> HTH,
| >>>
| >>> Kevin Spencer
| >>> Microsoft MVP
| >>> .Net Developer
| >>> What You Seek Is What You Get.
| >>>
| >>> | >>>> What I meant was, I added some, for example; response.write
| >>>> Post_1st_Ref_value & ref_ID_value to make sure I really was returning a
| >>>> value, to make sure the variable wasn't empty. That gave me the
| >>>> expected results, so knew I did have values to compare in IF statement.
| >>>>
| >>>> When I stated IsNum, I meant IsNumeric and again tested both variables
| >>>> I was thinking maybe I was trying to use two variables where both were
| >>>> numbers, but maybe one was a string and one a number so would then be
| >>>> trying to compare a number to a string.
| >>>>
| >>>> What I meant by "Work correctly is, I know in this case both
| >>>> Post_1st_Ref_value and ref_ID_value have the same value, 56 so my IF
| >>>> statement should be true. They won't always be true, but in this case,
| >>>> it is, therefore if they are the same, it then should execute the line
| >>>> Post_Comment = "Posted", but it's not, therefore I'm assuming the
| >>>> reaason it's not is because it doesn't think bot hvariables are the
| >>>> same. Again the response.write statements are showing them to be the
| >>>> same.
| >>>>
| >>>>
| >>>> | >>>>> Hi Ed,
| >>>>>
| >>>>> Your question is a bit confusing.
| >>>>>
| >>>>> You mention:
| >>>>>
| >>>>>> IF Post_1st_Ref_value = ref_ID_num_value THEN
| >>>>>>
| >>>>>> Post_Comment = "Posted"
| >>>>>
| >>>>> but then you state:
| >>>>>
| >>>>>> I did a bunch of testing with adding response.write statements to
| >>>>>> verify
| >>>>>> that the program is returning the correct data and it seems to be
| >>>>>> fine. All
| >>>>>> of the variables listed return the expected answer. I did an "IF
| >>>>>> IsNum"
| >>>>>> test
| >>>>>> to make sure the results are numeric, again results came back OK
| >>>>>
| >>>>> This is not clear at all. First, a Response.Write statement isn't
| >>>>> going to tell you anything about the data types. Response.Write always
| >>>>> writes a string. Second, you make a general statment that you "did an
| >>>>> "IF IsNum" test to make sure the "results" are numeric. Which
| >>>>> "results" are you referring to? What is "IsNum"? There is an InNumeric
| >>>>> function in VBScript, but I've never heard of an "IsNum" function. And
| >>>>> what did you test with it? Did you test Post_1st_Ref_value? Did you
| >>>>> test ref_ID_num_value?
| >>>>>
| >>>>> Finally, you state:
| >>>>>
| >>>>>> But no matter what I do, I can't seem to get the second IF statement
| >>>>>> to work
| >>>>>> correctly.
| >>>>>
| >>>>> Define "work correctly." What is the nature of the misbehavior?
| >>>>>
| >>>>> --
| >>>>> HTH,
| >>>>>
| >>>>> Kevin Spencer
| >>>>> Microsoft MVP
| >>>>> .Net Developer
| >>>>> Neither a follower nor a lender be.
| >>>>>
| >>>>> | >>>>>> I'm having problems getting an If statement to execute properly.
| >>>>>> Seems I've
| >>>>>> had similar problems in the past whenever my if statements involve
| >>>>>> number
| >>>>>> fields. For text, they work fine.
| >>>>>>
| >>>>>> I have one statement where the statement is:
| >>>>>>
| >>>>>> IF ref_L_name_value = First_L_name_value THEN
| >>>>>>
| >>>>>> This works fine and returns the desired results. But then another
| >>>>>> statement
| >>>>>> I have as follows:
| >>>>>>
| >>>>>> IF Post_1st_Ref_value = ref_ID_num_value THEN
| >>>>>>
| >>>>>> Post_Comment = "Posted"
| >>>>>>
| >>>>>>
| >>>>>> END IF
| >>>>>>
| >>>>>>
| >>>>>> I don't get the desired results.
| >>>>>>
| >>>>>> I did a bunch of testing with adding response.write statements to
| >>>>>> verify
| >>>>>> that the program is returning the correct data and it seems to be
| >>>>>> fine. All
| >>>>>> of the variables listed return the expected answer. I did an "IF
| >>>>>> IsNum"
| >>>>>> test
| >>>>>> to make sure the results are numeric, again results came back OK
| >>>>>>
| >>>>>>
| >>>>>> But no matter what I do, I can't seem to get the second IF statement
| >>>>>> to work
| >>>>>> correctly. Seems I've experienced similar problems in the past
| >>>>>> always when
| >>>>>> my IF statement contains numerical values.
| >>>>>>
| >>>>>>
| >>>>>>
| >>>>>> Any suggestions as to why it's not working or tricks to do when
| >>>>>> dealing with
| >>>>>> numerical data?
| >>>>>>
| >>>>>>
| >>>>>>
| >>>>>> Thanks
| >>>>>>
| >>>>>>
| >>>>>>
| >>>>>
| >>>>>
| >>>>
| >>>>
| >>>
| >>>
| >>
| >>
| >
| >
|
|
 
R

Ronx

Not necessarily.
It means both are numeric, but one may be an integer, and the other a
decimal number. This type difference could give a discrepancy in the
15th decimal place - not significant for the response.write function,
but enough to throw the equality.
 
S

Stefan B Rusynko

Agree
To test for the decimals the user could use TypeName(varname)
- returns the data type (integer, decimal, string, etc)

IF ISNumeric(Post_1st_Ref_value) Then
response.write "Post_1st_Ref_value is a " & TypeName(Post_1st_Ref_value) & " and = " & Post_1st_Ref_value & "<br>"
Else
response.write "Post_1st_Ref_value is Not numeric and is a " & TypeName(Post_1st_Ref_value)
End IF

IF ISNumeric(ref_ID_num_value) Then
response.write "ref_ID_num_value is a " & TypeName(ref_ID_num_value) & " and = " & ref_ID_num_value & "<br>"
Else
response.write "ref_ID_num_value is Not numeric and is a " & TypeName(ref_ID_num_value)
End IF




| Not necessarily.
| It means both are numeric, but one may be an integer, and the other a
| decimal number. This type difference could give a discrepancy in the
| 15th decimal place - not significant for the response.write function,
| but enough to throw the equality.
|
| --
| Ron Symonds
| Microsoft MVP (FrontPage)
| Reply only to group - emails will be deleted unread.
|
|
| | > The results are coming from a database. My response.write tag was
| > NOT getting the word "posted" written to it when I felt it should
| > have. So that told me that my IF statement for some reason doesn't
| > recognize the two variables as being equal, even though I'm
| > displaying both of these variables with other response.write tags,
| > and by reading results can see they both have the same value.
| >
| > My thought was since I wasn't getting desired result with = sign, as
| > a test, let me change to <> and see what I get. Lo and behold the
| > word "posted" then shows up in response.write statement.
| >
| > Sinse both variables passed the ISNumeric test, doesn't that mean
| > they must be the same type?
| >
| >
| > | >> Ed,
| >>
| >> <> means that Post_1st_Ref_value is not equal to ref_ID_num_value,
| >> so you need to look at the two values that your comparing and make
| >> sure they are the same type.
| >>
| >> Were are these two value coming from, the database or from a form?
| >>
| >> --
| >> ==============================================
| >> Thomas A. Rowe (Microsoft MVP - FrontPage)
| >> WEBMASTER Resources(tm)
| >>
| >> FrontPage Resources, WebCircle, MS KB Quick Links, etc.
| >> ==============================================
| >> To assist you in getting the best answers for FrontPage support
| >> see:
| >> http://www.net-sites.com/sitebuilder/newsgroups.asp
| >>
| >> | >>>I do have a response.write Post_comment line and the result is
| >>>empty Also as a test I changed my is statement to read:
| >>> IF Post_1st_Ref_value <> ref_ID_num_value THEN (replaced = with
| >>> <>) When I did that, it did write the word "posted so again all
| >>> indication are my IF statement is not executing correctly, but
| >>> why?
| >>>
| >>>
| >>> message | >>>> Hi Ed,
| >>>>
| >>>> Thanks for the clarification. I can see why you're scratching
| >>>> your head. I have one question: How do you know that the line
| >>>>
| >>>> Post_Comment = "Posted"
| >>>>
| >>>> isn't executing? That line just assigns a value to a variable. It
| >>>> doesn't show any output. Have you tried doing
| >>>>
| >>>> Response.Write(Post_Comment)
| >>>>
| >>>> --
| >>>> HTH,
| >>>>
| >>>> Kevin Spencer
| >>>> Microsoft MVP
| >>>> .Net Developer
| >>>> What You Seek Is What You Get.
| >>>>
| >>>> | >>>>> What I meant was, I added some, for example; response.write
| >>>>> Post_1st_Ref_value & ref_ID_value to make sure I really was
| >>>>> returning a value, to make sure the variable wasn't empty. That
| >>>>> gave me the expected results, so knew I did have values to
| >>>>> compare in IF statement.
| >>>>>
| >>>>> When I stated IsNum, I meant IsNumeric and again tested both
| >>>>> variables I was thinking maybe I was trying to use two variables
| >>>>> where both were numbers, but maybe one was a string and one a
| >>>>> number so would then be trying to compare a number to a string.
| >>>>>
| >>>>> What I meant by "Work correctly is, I know in this case both
| >>>>> Post_1st_Ref_value and ref_ID_value have the same value, 56 so
| >>>>> my IF statement should be true. They won't always be true, but
| >>>>> in this case, it is, therefore if they are the same, it then
| >>>>> should execute the line Post_Comment = "Posted", but it's not,
| >>>>> therefore I'm assuming the reaason it's not is because it
| >>>>> doesn't think bot hvariables are the same. Again the
| >>>>> response.write statements are showing them to be the same.
| >>>>>
| >>>>>
| >>>>> message | >>>>>> Hi Ed,
| >>>>>>
| >>>>>> Your question is a bit confusing.
| >>>>>>
| >>>>>> You mention:
| >>>>>>
| >>>>>>> IF Post_1st_Ref_value = ref_ID_num_value THEN
| >>>>>>>
| >>>>>>> Post_Comment = "Posted"
| >>>>>>
| >>>>>> but then you state:
| >>>>>>
| >>>>>>> I did a bunch of testing with adding response.write statements
| >>>>>>> to verify
| >>>>>>> that the program is returning the correct data and it seems to
| >>>>>>> be fine. All
| >>>>>>> of the variables listed return the expected answer. I did an
| >>>>>>> "IF IsNum"
| >>>>>>> test
| >>>>>>> to make sure the results are numeric, again results came back
| >>>>>>> OK
| >>>>>>
| >>>>>> This is not clear at all. First, a Response.Write statement
| >>>>>> isn't going to tell you anything about the data types.
| >>>>>> Response.Write always writes a string. Second, you make a
| >>>>>> general statment that you "did an "IF IsNum" test to make sure
| >>>>>> the "results" are numeric. Which "results" are you referring
| >>>>>> to? What is "IsNum"? There is an InNumeric function in
| >>>>>> VBScript, but I've never heard of an "IsNum" function. And what
| >>>>>> did you test with it? Did you test Post_1st_Ref_value? Did you
| >>>>>> test ref_ID_num_value?
| >>>>>>
| >>>>>> Finally, you state:
| >>>>>>
| >>>>>>> But no matter what I do, I can't seem to get the second IF
| >>>>>>> statement to work
| >>>>>>> correctly.
| >>>>>>
| >>>>>> Define "work correctly." What is the nature of the misbehavior?
| >>>>>>
| >>>>>> --
| >>>>>> HTH,
| >>>>>>
| >>>>>> Kevin Spencer
| >>>>>> Microsoft MVP
| >>>>>> .Net Developer
| >>>>>> Neither a follower nor a lender be.
| >>>>>>
| >>>>>> | >>>>>>> I'm having problems getting an If statement to execute
| >>>>>>> properly. Seems I've
| >>>>>>> had similar problems in the past whenever my if statements
| >>>>>>> involve number
| >>>>>>> fields. For text, they work fine.
| >>>>>>>
| >>>>>>> I have one statement where the statement is:
| >>>>>>>
| >>>>>>> IF ref_L_name_value = First_L_name_value THEN
| >>>>>>>
| >>>>>>> This works fine and returns the desired results. But then
| >>>>>>> another statement
| >>>>>>> I have as follows:
| >>>>>>>
| >>>>>>> IF Post_1st_Ref_value = ref_ID_num_value THEN
| >>>>>>>
| >>>>>>> Post_Comment = "Posted"
| >>>>>>>
| >>>>>>>
| >>>>>>> END IF
| >>>>>>>
| >>>>>>>
| >>>>>>> I don't get the desired results.
| >>>>>>>
| >>>>>>> I did a bunch of testing with adding response.write statements
| >>>>>>> to verify
| >>>>>>> that the program is returning the correct data and it seems to
| >>>>>>> be fine. All
| >>>>>>> of the variables listed return the expected answer. I did an
| >>>>>>> "IF IsNum"
| >>>>>>> test
| >>>>>>> to make sure the results are numeric, again results came back
| >>>>>>> OK
| >>>>>>>
| >>>>>>>
| >>>>>>> But no matter what I do, I can't seem to get the second IF
| >>>>>>> statement to work
| >>>>>>> correctly. Seems I've experienced similar problems in the
| >>>>>>> past always when
| >>>>>>> my IF statement contains numerical values.
| >>>>>>>
| >>>>>>>
| >>>>>>>
| >>>>>>> Any suggestions as to why it's not working or tricks to do
| >>>>>>> when dealing with
| >>>>>>> numerical data?
| >>>>>>>
| >>>>>>>
| >>>>>>>
| >>>>>>> Thanks
| >>>>>>>
| >>>>>>>
| >>>>>>>
| >>>>>>
| >>>>>>
| >>>>>
| >>>>>
| >>>>
| >>>>
| >>>
| >>>
| >>
| >>
| >
| >
|
|
 
E

Ed Richter

OK, may have found part of the problem

In my database the field Post_1st_Ref_value comes from a text value while
the field ref_ID_num_value comes from an auto number field.

But the part then that confuses me is why when I tested both values using
the ISNumeric test, did they pass?

So since one is a text field and one an autonumber, do I convert the
autonumber to text and then compare? Do I use something like:
ref_ID_num_value = Cstr(nameObj("ID_num")) to change it to a string/text??
 
Top