Reply
Completely trivial question?
Old 04-15-2004, 05:20 PM Completely trivial question?
Junior Talker

Posts: 3
Trades: 0
Hi there, I've just started using ASP with VBscript and have come up with what seems like a completely simple problem - yet i am unable to solve it.

When I type the following in and store it as xv.asp, I believe I should get a web page where I can increase or decrease the value of x between 0 and 10. Yet, when I run it, and press either 'increase' or 'decrease' it jumps straight to 10 and stays there. I guess the problem is with the last 'If...Then' but can't see it.

HTML Code:
<html>
<head></head>
<body>
<%
Dim x, r, little, big
little=1
big=10
r=Request.Form("xval")

If (Not Isnumeric(r)) Then 
   x=5
   Else
   x=r
End If

If x <= little Then 
   x=little
ElseIf x >= big Then 
   x=big
End If

Response.Write("x = " & x & "  r = " & r)
%>


<br>
<form action="xv.asp" method=post>
<input name="xval" value="<%=x-1%>" type="hidden"><input type="submit" value="Decrease x"></form>

<form action="xv.asp" method=post>
<input name="xval" value="<%=x+1%>" type="hidden"><input type="submit" value="Increase x"></form>

<form action="xv.asp" method=post>
<input name="xval" value="boo" type="hidden"><input type="submit" value="Reset x"></form>

</body>
</html>
Any suggestions? I have consulted 3 ASP/VBScript books already and can't see where i'm going wrong. It seems to work if i change the 'little' and 'big' and hardcode the values 1 and 10 in instead, but that isn't practical on my site.

Sorry for being so dumb; but i did manage to do the rest of the site ok, including setting up database access through ASP.

Thanks.
BrianW is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 04-16-2004, 07:48 AM
Junior Talker

Posts: 3
Trades: 0
would it have something to with Cint cos you want to add a number to x? or is that what isnumeric is? sorry new to asp as well.
meex is offline
Reply With Quote
View Public Profile
 
Old 04-17-2004, 03:44 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Your last "if" statement, when your checking boundries. Your comparing the variables "little" and "big" to "x". Little and big are integers because you assigned them number values. "x" is a character, everything that comes from a form is a character dataype.

What you need to do is convert the "x" variable to an integer when comparing it with the little and big variables. You can do that with the cint() function as so:
Code:
If cint(x) <= little Then 
   x=little
ElseIf cint(x) >= big Then 
   x=big
End If
I hope that helps you and that I havn't confused you too much
Anacrusis is offline
Reply With Quote
View Public Profile Visit Anacrusis's homepage!
 
Old 04-17-2004, 04:25 PM
Junior Talker

Posts: 3
Trades: 0
Thank you. Excellent, perfectly understandable answer! It works now.

Thanks again.
BrianW is offline
Reply With Quote
View Public Profile
 
Old 04-19-2004, 01:14 PM
D.Viddy's Avatar
Average Talker

Posts: 24
Location: Soldotna, Alaska
Trades: 0
Can you show me the fully functional code. Are you telling me the above code works?
__________________
-Dylan Vester
D.Viddy is offline
Reply With Quote
View Public Profile Visit D.Viddy's homepage!
 
Old 04-19-2004, 10:19 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Yes, the code that BrianW posted does work, with the changes to the last "if" statement that I posted. It's not the best way to accomplish what he wants, but it gets him there.
Anacrusis is offline
Reply With Quote
View Public Profile Visit Anacrusis's homepage!
 
Old 04-20-2004, 06:07 AM
Junior Talker

Posts: 3
Trades: 0
Yes, as Anacrusis says, it works with the changes he says.

I was going to ask if there is a better way...please do enlighten me! I'd prefer to stick with POST as the method.
BrianW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Completely trivial question?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.23918 seconds with 13 queries