• 0

[ASP] Greater than?


Question

well, this one is really bugging me:

<% Dim width
width = Request.QueryString("w")
If width = "" Then
Response.Write("0")
End If
If width >< "512" Then
Response.Write("512")
Else
Response.Write(width)
End If %>

what i want is, that if the variable w's value is more than 512, than the written value should be 512. eg, if the incoming value if 1000, than the written value should be 512. someone tell me what the sign is used for ASP VB for greater than and less than functions. here is the thing this is supposed to act like

help please! :D

Edited by snuke
Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0

<% Dim width

width = Request.QueryString("w")

if isnumeric(width) and width <> "" then

width = cInt(width)

else

width = 0

end if

If width = 0 Then

Response.Write("0")

End If

If width > 512 Then

Response.Write("512")

Else

Response.Write(width)

End If %>

edit : made it a little better.

> : greater

< : less than

>= : greater or equal to

<= : less than or equal to

<> : not equal to

Edited by lunamonkey
Link to comment
Share on other sites

  • 0

well, i just cant take that can i? explain those functions please?

EDIT: btw, here is what i did, and its a viola!!!

&lt;% Dim width
width = Request.QueryString("w")
If width = "" Then
Response.Write("0")
End If
If width &gt; 512 Then
Response.Write("512")
Else
Response.Write(width)
End If %&gt;

Link to comment
Share on other sites

  • 0
well, this one is really bugging me:

&lt;% Dim width
width = Request.QueryString("w")
If Request.QueryString("w") = "" Then
Response.Write("0")
End If
If Request.QueryString("w") &gt;&lt; "512" Then
Response.Write("512")
Else
Response.Write(width)
End If %&gt;

what i want is, that if the variable w's value is more than 512, than the written value should be 512. eg, if the incoming value if 1000, than the written value should be 512. someone tell me what the sign is used for ASP VB for greater than and less than functions. here is the thing this is supposed to act like

help please! :D

by using <> I think you are saying 'not equal to'

I am finding it hard to understand what you are trying to do though. Also you have assigned the querystring to width so why dont you use this in your if statements instead of keep getting querystring?

Link to comment
Share on other sites

  • 0

did you check out the page i linked? that would tell you more about what im trying to do. besides, its done. i emitted the " and used the simple > i first thought of, but which didnt work. thanks to everyone :)

check ma edit ^

rofl, i aint that nab.. besides i wrote that code. anyway, this is what i wanted you to explain, cause ive never seen these:

isnumeric(width) and width <> "" then

width = cInt

the ones in bold, please :)

Link to comment
Share on other sites

  • 0

btw, luna, checked your site, you might wanna tell me the code for replacing stuff (eg, :) with the image?)

Link to comment
Share on other sites

  • 0

Hey,

isNumeric() : returns a boolean (true/false) results

isNumeric(10) will return true

isNumeric("bob") will return false

cInt() : returns an integer of the inputted parameter. Will break if the contents is a string. Which is why you should test things before passing them into functions.

example

cInt(request.querystring("passnumber"))

: will return an integer Type of the value of the "passnumber" querystring.

This is important so that you compare things that are the same "type". You can't compare "10" with 10 for example, as one is a string.

The image replacement, much like neowins..it picks up on keywords in the text, and replaces them for a HTML snippet.

for example

dim HtmlString
HtmlString = "hello. :p "

HtmlString = HtmlString.replace(":p","&lt;img src=""pokey.gif"" /&gt;")

response.write(HtmlString)

that will hopefully write out the correct HTML for the smily.

Edited by lunamonkey
Link to comment
Share on other sites

  • 0

If in doubt, get the Windows Script 5.6 helpfile (requires validation [why Microsoft? WHY?]). It covers VBScript and JScript, some objects, and the forgotten but still useful Script Components.

Previous versions didn't document the Escape and Unescape VBScript functions (amongst others)...

Edit: Googling "script56.chm" might get around the validation annoyance...

Link to comment
Share on other sites

  • 0

about the image replacement thing, how do i implement it... lets say im using an access db for posts on a page, with repeat region doing the results for me... now how do i catch the :p and :) etc and change them with images

Link to comment
Share on other sites

  • 0

ummm.. luna, tried your msn, but you werent online.. i used this pretty cool/neat/clean script for logging in/out and it stored the username in a cookie, and my page checked for the cookie else it gave up the signin form... what i need help for now is: a script as neat as i had earlier :p take the username/password from my form > takes it to the other page, verifys, and stores a cookie, and goes back to the page it came from. and another signout page, that removes the cookie, once the page is loaded, and take the user back to the page it came from. ummm.. can you help? :p

Link to comment
Share on other sites

  • 0

Signout page would be pretty easy.

You just need to kill the session variables and the cookie. Usually done by blanking them out, and the cookie you make expire.

SO with the cookie you just re-set it but with a blank value, and with a date in the past. I'm sure you can manipulate your existing sign-in script to do that.

The sessions, just blank them out. They will expire naturally.

Link to comment
Share on other sites

  • 0

ummmm... i got it myself, thanks for all the help. i appreciate it :)

just posting here, so i can check it again, incase i lose it :p

&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%&gt;
&lt;!--#include virtual="/Connections/oblivion.asp" --&gt;
&lt;%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
MM_valUsername = CStr(Request.Form("username"))
If MM_valUsername &lt;&gt; "" Then
  Dim MM_fldUserAuthorization
  Dim MM_redirectLoginSuccess
  Dim MM_redirectLoginFailed
  Dim MM_loginSQL
  Dim MM_rsUser
  Dim MM_rsUser_cmd
  Dim username

  username = Request.Form("username")

  MM_fldUserAuthorization = ""
  MM_redirectLoginSuccess = Request.Form("url")
  MM_redirectLoginFailed = "users/fail.asp"

  MM_loginSQL = "SELECT username, password"
  If MM_fldUserAuthorization &lt;&gt; "" Then MM_loginSQL = MM_loginSQL &amp; "," &amp; MM_fldUserAuthorization
  MM_loginSQL = MM_loginSQL &amp; " FROM users WHERE username = ? AND password = ?"
  Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
  MM_rsUser_cmd.ActiveConnection = MM_oblivion_STRING
  MM_rsUser_cmd.CommandText = MM_loginSQL
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 255, MM_valUsername) ' adVarChar
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 255, Request.Form("password")) ' adVarChar
  MM_rsUser_cmd.Prepared = true
  Set MM_rsUser = MM_rsUser_cmd.Execute

  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
	' username and password match - this is a valid user
	Session("MM_Username") = MM_valUsername
	If (MM_fldUserAuthorization &lt;&gt; "") Then
	  Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
	Else
	  Session("MM_UserAuthorization") = ""
	End If
	if CStr(Request.QueryString("accessdenied")) &lt;&gt; "" And false Then
	  MM_redirectLoginSuccess = Request.QueryString("accessdenied")
	End If
	MM_rsUser.Close
	Response.Cookies("iuser") = username
	Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If
%&gt;

Link to comment
Share on other sites

  • 0

It's well worth explicitly destroying your objects (Set obj = Nothing) for MM_rsUser_cmd and MM_rsUser. The GD in ASP is crap.

It's also well worth ditching Dreamweaver autogen code once you grok how it works and replacing it with cleaner more efficient code:

Note that the variable MM_fldUserAuthorization is initialised to an empty string (vbNullString) and doesn't get changed so there's a pointless line checking it.

MM_valUsername is set to the same thing as username (from the form) so you can ditch username altogether. Also, all form (and querystring) gets are of type string in VBScript (even if the key/value pair doesn't exist) so CStr'ing is unnecessary.

You don't need to get the password from the database as you are supplying it as a condition; you only want to find out if there is a matching record. Arguably, you don't need to get the username either for the same reason; some other fields might have use, like last logged on time for instance.

You can force a session expire by using Session.Abandon() after setting the cookie expiry to sometime last year.

If you use the metadata tag for ADODB constants you can lose the magic numbers (200 for adVarChar etc.) so you don't need to have a comment explaining them:

&lt;!-- metadata name="Microsoft ActiveX Data Objects 2.8 Library: Prefix=ADODB" type="TypeLib" uuid="{00000205-0000-0010-8000-00AA006D2EA4}" version="2.8" --&gt;

Keep that with your data connection stuff and you won't need the good ol' adovbs.inc file that is still used all over the place. Added benefit being you can "include" it multiple times (accidentally of course) without "variable aready defined" errors.

Link to comment
Share on other sites

  • 0

making another application, and used this as the signin code, what do you think?

&lt;% username = Request.Form("username")
password = Request.Form("password") %&gt;
&lt;% Dim user
Dim user_cmd
Dim user_numRows

Set user_cmd = Server.CreateObject ("ADODB.Command")
user_cmd.ActiveConnection = connection_to_SQLDB
user_cmd.CommandText = "SELECT * FROM users_table WHERE username_field = ? and password_field = ?" 
user_cmd.Prepared = true
user_cmd.Parameters.Append user_cmd.CreateParameter("param1", 200, 1, 100, username)
user_cmd.Parameters.Append user_cmd.CreateParameter("param2", 200, 1, 100, password)

Set user = user_cmd.Execute
user_numRows = 0 %&gt;

have to use the form variables a couple times in the script, so defined them in new variables

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.