• 0

[ASP] Greater than?


Question

well, this one is really bugging me:

<% Dim width
width = Request.QueryString("w")
If width = "" Then
Response.Write("0d If
If width >< "512" Then
Response.Write("512se
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
https://www.neowin.net/forum/topic/602671-asp-greater-than/
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
  • 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("0d If
If width &gt; 512 Then
Response.Write("512se
Response.Write(width)
End If %&gt;

  • 0
  snuke said:
well, this one is really bugging me:

&lt;% Dim width
width = Request.QueryString("w")
If Request.QueryString("w") = "" Then
Response.Write("0d If
If Request.QueryString("w") &gt;&lt; "512" Then
Response.Write("512se
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?

  • 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 :)

  lunamonkey said:
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 :)

  • 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
  • 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...

  • 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

  • 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

  • 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.

  • 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("usernamef 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("urlMM_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;

  • 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.

  • 0

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

&lt;% username = Request.Form("usernamessword = Request.Form("passwordgt;
&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

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

    • No registered users viewing this page.
  • Posts

    • Clearly a lot of gamers. And I'm sorry but you are wrong, my 7800x3d (single ccd) offers huge benefits to me as a AAA 1440p gamer. And it's pretty dumb to crap on 1080p gamers as they make up like 90+% of steam gamers. But no, the x3d does not just offer benefits to esport gamers (one of the stupidest things I've seen in a while AND THATS SAYING SOMETHING.) Abd when I built my rig with my 7800x3d, I paired it with a RX7900xt and couldn't be happier.
    • Um, someone needs to tell this author the 7800x3d is a single ccd and shouldn't be affected. If this only effects the dual ccd, 7800x3d owners need not worry
    • Popular File Explorer alternative Files gets signature check, improved dual-pane, and more by Taras Buria A new update has arrived for File Preview, a feature-packed file manager for Windows 10 and 11. Version 3.9.14 introduces a useful new feature for file properties, dual-pane improvements, the ability to resize columns in the Columns View, and more. Starting with the Properties dialog, it now features a "Signatures" tab where you can view digital signatures associated with the file and their properties, such as version, issuer, expiry date, and more. You can also click the "Details" button to open Windows' native dialog. The dual-pane feature has been tweaked for a more intuitive experience. The "Add pane" command is now "Split pane." There is a new quick action for toggling dual-pane mode on or off, and settings now have a dedicated section for dual-pane mode. Finally, columns in the Columns View are now resizable, and search results now have a header with your current query. In addition to releasing the update, developers said the following regarding performance complaints from users: Files Preview is available in the Microsoft Store. You can purchase it there to support developers. Alternatively, you can get the app for free from the official website, and if you want to help developers with contributions or ideas, check out their Discord and GitHub.
    • So the iPhone only has a leading position in a few markets around the world: US, UK, UAE, couple of other smaller ones. As a result of the far more mixed eco-system Whatsapp is a lot more popular outside of the US than I think a lot of American's may realise. It's pretty much the messaging standard in the UK
  • Recent Achievements

    • First Post
      Soeaker4thedead earned a badge
      First Post
    • First Post
      kryptickid earned a badge
      First Post
    • First Post
      Nemesis-IV earned a badge
      First Post
    • First Post
      Aidan Helfrich earned a badge
      First Post
    • Collaborator
      bullgod69 earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      760
    2. 2
      ATLien_0
      187
    3. 3
      +FloatingFatMan
      151
    4. 4
      Xenon
      117
    5. 5
      wakjak
      113
  • Tell a friend

    Love Neowin? Tell a friend!