If statement on ASP Page not working.

Hello values experts. I am having an issue with an IF statement I added to an ASP Page. Here is the run down. I have this ASP page and on this page one of the things it does is some calulations and comes up with a number for off-line inspection. Well I made the Off-line Inspection text box hidden and I tried using the number it comes up with for that box in my if statement to decide whether to use MinInspection or MaxInspection values which are fields in the excel sheet that drives this asp form. I hope this is clear. Anyway belwo is the IF statement.
Right now the box just stays blank and does not get populated with anything, I cant figure out why.
<%
DIM PPMVal
	
If PPMNumber < rs.fields("MinInspection")then 
%>
<%
PPMVal = rs.Fields("MinInspection")
%>
<%
else 
%>
<%
PPMVal = rs.Fields("MaxInspection")
%>
<%
end if
%>

Open in new window

jlcannonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
>>I made the Off-line Inspection text box hidden
OK, so if you are submitting an html <form>, then you should be using:
Request("MinInspection") instead of rs.Fields(...)
SriVaddadiCommented:
Try this

<%
DIM PPMVal
     
If PPMNumber < rs.fields("MinInspection")then  


PPMVal = rs.Fields("MinInspection")


else  

 
PPMVal = rs.Fields("MaxInspection")


end if
%>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jlcannonAuthor Commented:
still no value. I have verified there is a number for PPMNumber but PPMVal still has no number. I have copied and pasted the whole section belwo. it is your if statement plus the code for the 2 seperate text boxes the one called PPMNumber and the one called PPMVal
<% 
DIM PPMVal 
     
If PPMNumber < rs.fields("MinInspection")then  


PPMVal = rs.Fields("MinInspection") 


else  

 
PPMVal = rs.Fields("MaxInspection") 


end if 
%>

<td width="80%" class="tablesmall"><input type="Text" size="5" name="PPMNumber" Readonly value="<%=rs.fields("Off-Line Inspection Period")%>">
<input type="Text" size="5" name="PPMValue" Readonly value="<%=PPMVal%>"></td>

Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

hieloCommented:
try the attached code to see what it reveals.
<% 
DIM PPMVal 

If PPMNumber < rs.fields("MinInspection") then  
	Response.Write("If clause - Expect the following value: " & rs.Fields("MinInspection"))
	PPMVal = rs.Fields("MinInspection") 
else  
	Response.Write("Else clause - Expect the following value: " & rs.Fields("MaxInspection"))
	PPMVal = rs.Fields("MaxInspection") 
end if 
%>

<td width="80%" class="tablesmall"><input type="Text" size="5" name="PPMNumber" readonly value="<%=rs.fields("Off-Line Inspection Period")%>">
<input type="Text" size="5" name="PPMValue" readonly value="<%=PPMVal%>"></td>

Open in new window

SriVaddadiCommented:
Do you have values for both rs.Fields("MinInspection")  and rs.Fields("MaxInspection") ?

Looks like PPMVal  is a local variable and is going out of scope after that block execution.

declare the variable in global section and try
rg20Commented:
Your quotes in the first one might be throwing you off

Change
<input type="Text" size="5" name="PPMNumber" Readonly value="<%=rs.fields("Off-Line Inspection Period")%>">
to
<input type="Text" size="5" name="PPMNumber" Readonly value=<%=rs.fields("Off-Line Inspection Period")%>>
jlcannonAuthor Commented:
rg20, the quotes made no difference.

SriVaddadi, Yes I have put numbers in both columns in the excel sheet and made sure those columns were included in the named region fro tblData.
ok so here is an interesting thing. in the textbox named PPMNumber I get a number but if I do a reponse.write PPMNumber right after it I get nothing. even though there is a number in the box... any suggestions?
rg20Commented:
You mean to say

<%
    response.write("First Number" &PPMNumber)
%>
<input type="Text" size="5" name="PPMNumber" Readonly value="<%=rs.fields("Off-Line Inspection Period")%>">

<%
    response.write("Second Number" & PPMNumber)
%>

The first time it shows a number, the second it doesn't?

Is there code we are missing/needing to assist here?
Are you reassigning the value of PPMNumber?
Is it after a submit of a form?
hieloCommented:
Initially, this:
<td width="80%" class="tablesmall"><input type="Text" size="5" name="PPMNumber" readonly value="<%=rs.fields("Off-Line Inspection Period")%>">
<%=Response.Write( Request("PPMNumber"))%>

will likely put a value in the PPMNumber field, but the Response.Write will NOT display anything because you have NOT submitted the form. After the initial load, if you sumit the form so that it submit back to the same page, THEN you will see the value of Request("PPMNumber").

So first check to see if Request("PPMNumber") was submitted:

<td width="80%" class="tablesmall"><input type="Text" size="5" name="PPMNumber" readonly value="<%=rs.fields("Off-Line Inspection Period")%>">
<%
If "" <>  Trim(Request("PPMNumber")) Then
  Response.Write( Request("PPMNumber") )
Else
  Response.Write( rs.fields("Off-Line Inspection Period") )
End If
%>

Open in new window

jlcannonAuthor Commented:
Ok well I guess I have unintentionally missleading. This page is an ASP page with text boxes and radio buttons and dropdown boxes but there is no submitting the form. Ok for instance the textbox that is called PPMNumber, which looks like this:
<td width="80%" class="tablesmall"><input type="Text" size="5" name="PPMNumber" value=<%=rs.fields("Off-Line Inspection Period")%>>
this textbox is down near the bottom of the page and the whole premis of this page is lets say you go to this page and you select a type of equipment, for example let say an electric motor once you select your equipment type a whole set of questions pop up and at the top there is a hidden text box called BaseNumber and this is a number pulled directly from the excel sheet in this case lets say its 80, which means 80 months before an inspection is needed and as you scroll down the page and answer questions like for Type of environment; you have radio button choices of clean, dusty, outdoor/dirty and based on that choice it takes a number from the excel sheet that the column coresponds to and adds or subtracts from that BaseNumber and that is the number that you get in the textbox called PPMNumber.
in my example about I used environment and here is that radio button choice for outdoor-dusty:
<td width="14%"><input type="radio" name="atm" value="<%=rs.fields("Outdoor - Dusty")%>" onclick="myrecalc()"></td>

see the on click it runs a function called myrecalc.
I have attached that function as a code snippet.
I hope this clears up my misguidance.
sub myrecalc()

	  if myform.recalcT.value = "y" then
		basenumber = myform.basenumber.value
		selectedparameters = ""
'		Age = myform.AgeT.value
'		inout = myform.InOutT.value

		if myform.AgeT.value = "y" then
			For i = 0 to 6 'Equipment Age
				if myform.age(i).checked then basenumber = basenumber + int(myform.age(i).value)
			next
		end if
		if myform.nosT.value = "y" then
			For i = 0 to 2 ' Nature of Service
				if myform.nos(i).checked then basenumber = basenumber + int(myform.nos(i).value)
			next
		end if
		if myform.atmT.value = "y" then
			For i = 0 to 6 ' Atmosphere
				if myform.atm(i).checked then basenumber = basenumber + int(myform.atm(i).value)
			next
		end if
		if myform.operT.value = "y" then
			For i = 0 to 1 ' Operating Cond.
				if myform.oper(i).checked then basenumber = basenumber + int(myform.oper(i).value)
			next
		end if
		if myform.insmedT.value = "y" then
			For i = 0 to 2 ' Insulation Medium
				if myform.insmed(i).checked then basenumber = basenumber + int(myform.insmed(i).value)
			next
		end if
		if myform.viT.value = "y" then
			For i = 0 to 3 ' Visual Inspection
				if myform.vi(i).checked then basenumber = basenumber + int(myform.vi(i).value)
			next
		end if
		if myform.relmetT.value = "y" then
			For i = 0 to 3 ' Monitoring/Alarms
				if myform.relmet(i).checked then basenumber = basenumber + int(myform.relmet(i).value)
			next
		end if
		if myform.hovT.value = "y" then
			For i = 0 to 6 ' High Output Voltage
				if myform.hov(i).checked then basenumber = basenumber + int(myform.hov(i).value)
			next
		end if
		if myform.ttT.value = "y" then
			For i = 0 to 2 ' Transformer type
				if myform.tt(i).checked then basenumber = basenumber + int(myform.tt(i).value)
			next
		end if
		if myform.btT.value = "y" then
			For i = 0 to 3 ' Bus type
				if myform.bt(i).checked then basenumber = basenumber + int(myform.bt(i).value)
			next
		end if
		if myform.stT.value = "y" then
			For i = 0 to 3 ' Infrared testing
				if myform.st(i).checked then basenumber = basenumber + int(myform.st(i).value)
			next
		end if
		if myform.mtT.value = "y" then
			For i = 0 to 3 ' Motor type
				if myform.mt(i).checked then basenumber = basenumber + int(myform.mt(i).value)
			next
		end if
		if myform.msT.value = "y" then
			For i = 0 to 3 ' Motor starts
				if myform.ms(i).checked then basenumber = basenumber + int(myform.ms(i).value)
			next
		end if
		if myform.mcT.value = "y" then
			For i = 0 to 1 ' Motor Configuration
				if myform.mc(i).checked then basenumber = basenumber + int(myform.mc(i).value)
			next
		end if
		if myform.confT.value = "y" then
			For i = 0 to 2 ' Configuration
				if myform.conf(i).checked then basenumber = basenumber + int(myform.conf(i).value)
			next
		end if
		if myform.ttbdT.value = "y" then
			For i = 0 to 3 ' Configuration
				if myform.ttbd(i).checked then basenumber = basenumber + int(myform.ttbd(i).value)
			next
		end if
		myform.ppmnumber.value = basenumber
	  end if
	end sub

Open in new window

rg20Commented:
Think about this.

In your VBScript function, you are addressing variables by the variable name, but for PPMNumber you are trying to call it by the VBScript variable,

Once you leave the script, the variable is no longer accessible,
Once saved to the textbox you will need to use

myform.fieldname.value

Do from your original question
<% 
    DIM PPMVal 
    
    PPMNumber = myform.PPMNumber.value
 
    If PPMNumber < rs.fields("MinInspection")then  
        PPMVal = rs.Fields("MinInspection") 
    else  
        PPMVal = rs.Fields("MaxInspection") 
    end if 
%>

Open in new window

jlcannonAuthor Commented:
rg20. still nada comming up I mean its frustrating because there is a number in <input type="Text" size="5" name="PPMNumber" value=<%=rs.fields("Off-Line Inspection Period")%>> but then if you try to use that number for anything it does not work. right after the tectbox for PPMNumber I put the if statement and whne i look at the page i get
Microsoft VBScript runtime error '800a01a8'
Object required: ''
/energysystc/electricalppm.asp, line 1481
but if I comment out the line
PPMNumber = myform.PPMNumber.value
the error goes away but it does not do anything.
rg20Commented:
As mentioned above, if you have the line
PPMNumber = myform.PPMNumber.value
before
<input type=text name=PPMNumber>
then the error is obvious the object does not exist yet.

but you are one step closer.
Move your VBScript function to the end of your code.

If you need it for some of the calcuations before the field is displayed
for example
<input type=text name=test1 value=myform.test2.value*2>
<input type=text name=test2 value = "3">

You have an obvious problem here.

This value comes from an Excel database per say
So when you query the database, store a local variable with the value, then do your calculations, load the page, then get the value from excel again if needed.
Otherwise store it in a session variable so you have it all the time
masterpassCommented:
Does this help ?
<td width="80%" class="tablesmall"><input type="Text" size="5" name="PPMNumber" value='<%=rs.fields("Off-Line Inspection Period") %>'>
<input type="Text" size="5" name="PPMValue" value='<%=PPMVal %>'></td>

Open in new window

jlcannonAuthor Commented:
masterpass, that had no effect. it appears the issue is the fact the the value of PPMNumber is <%=rs.fields("Off-Line Inspection Period") %> which is a number but for some reason it will not see it that way. I mean it displays a number on the screen but I guess I cant use that number and put it to a variable. I mean i tried
DIM PPMNum
PPMNum = PPMNumber, that didnt work
then I tried PPMNum = myform.PPMNumber, that didnt work and now gave me an error of
Microsoft VBScript runtime error '800a01a8'

Object required: ''

/energysystc/electricalppm.asp, line 1481
so then I tried PPMNum = myform.PPMNumber.value, that didnt work and gave me the same error as above. I am doing this after there is a value in the text box PPMNumber so I cant figure it out.
jlcannonAuthor Commented:
I used a combination of the answers here so awarded to the combos I used. I also had to session the results and request.querystring them and it began working. Thank you all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.