Variables in a (Do while) statement.

Results 1 to 2 of 2

Thread: Variables in a (Do while) statement.

  1. #1
    Don Lefik Guest

    Default Variables in a (Do while) statement.

    I&#039m trying to use a variable in a do while statement but I&#039m having trouble grasping the concept.<BR><BR>Here&#039s what I&#039m doing.<BR><BR>I have a database call that selects a recordset of users that have accessed the site.<BR><BR>SQL=Select * FROM weblog order by logdate DESC<BR>Set RList = Conn.Execute(SQL)<BR><BR>I then use the following to show only the last 10.<BR><BR>&#060;%<BR> Dim LdateVar<BR> LdateVar=0<BR> <BR> do while (LdateVar &#060; 10 and not RList.EOF)<BR><BR> %&#062;<BR><BR>I put a TABLE here to show my records here.<BR><BR>&#060;%<BR> RList.MoveNext<BR> LdateVar=LdateVar+1<BR> Loop<BR> %&#062;<BR><BR>This works fine. I now want to let the user choose how many records to display. In effect they will be able to change the 10 to any number up to EOF.<BR><BR>I added a form to allow the input of the number like this.<BR><BR>&#060;FORM ACTION="back to this page.asp" METHOD="post"&#062;<BR>Show me the last &#060;INPUT TYPE="text" NAME="count" SIZE="3"&#062; logins.<BR>&#060;INPUT TYPE="submit" NAME="logins" VALUE="showme"&#062;<BR>&#060;/FORM&#062;<BR><BR>I then tried using the following:<BR><BR>do while (LdateVar &#060; request("count")and not RList.EOF)<BR><BR>This did not work! &#060;%=request("count")%&#062; shows the number I chose but the DO WHILE always shows all the records.<BR><BR>What should I be doing here?<BR><BR>Thanking you in advance <BR>Don Lefik<BR><BR><BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Comparing vs. values from forms...

    All values that come back from Request.Form or Request.QueryString are strings.<BR><BR>When you do <BR><BR>DO WHILE var &#060; Request("whatever")<BR><BR>you are probably actually doing a STRING comparison, instead of a numeric one, thanks to the rules of "promotion" in VBScript.<BR><BR>Try simply doing<BR><BR>DO WHILE var &#060; CInt(Request("whatever"))<BR><BR>to force it to an integer value.<BR><BR>Also, for completeness and safety, make sure you have a space after the expression and before the "and" (which you do not in the code you showed us).<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts