Link to home
Start Free TrialLog in
Avatar of tmurray22
tmurray22

asked on

how to add to text to asp display

I have an asp page that dipaly two values , then has a form underneath.
I want to change add some text to my values.

example

currently displays

name
value

I want it to say

welcome "name"
you currently have "value" points in your account


here is my code

<html>
<head>
<title>My First ASP Page</title>
</head>
<body bgcolor="white" text="black">


<%
'Dimension variables
Dim adoCon         'Holds the Database Connection Object
Dim rsGuestbook   'Holds the recordset for the records in the database
Dim strSQL          'Holds the SQL query to query the database  
 
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
 
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=letmein; DBQ=" & Server.MapPath("\SCM\fpdb\ptdb\users.mdb") & ";Persist Security Info=False"

'Create an ADO recordset object
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
 
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT totals.Name, totals.TotalAmount FROM totals;"
 
'Open the recordset with the SQL query
rsGuestbook.Open strSQL, adoCon
 
 
'Loop through the recordset
Do While not rsGuestbook.EOF
           'Write the HTML to display the current record in the recordset
     Response.Write ("<br>")
     Response.Write (rsGuestbook("Name"))
     Response.Write ("<br>")
     Response.Write (rsGuestbook("TotalAmount"))
     Response.Write ("<br>")

     'Move to the next record in the recordset
     rsGuestbook.MoveNext

Loop                                          
 
 

'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
<!-- Begin form code -->
 </p>
 <form name="FrontPage_Form1" method="post" action="add_to_guestbook.asp" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript">
     <p align="center">&nbsp;Selection: <select size="1" name="Selection">
     <option>Team1</option>
     <option>Team2</option>
     <option>Team3</option>
     </select>
     <br>
>>>>> following line splitted for readability of the question - modulo CS Moderator <<<<<<<
     Amount:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <!--webbot bot="Validation" s-data-type="Number" s-number-separators=",.
" i-maximum-length="3" s-validation-constraint="Greater than or equal to" s-validation-value="1"
 s-validation-constraint="Less than or equal to" s-validation-value="500" -->
     <input type="text" name="amount" maxlength="3" size="3">
     <br>
&nbsp;</p>
     <p align="center">
     <input type="submit" name="Submit" value="Submit">
     </p>

</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of BubbaisBest
BubbaisBest

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thefritterfatboy
thefritterfatboy

heh - Bubba is interpreting this how I am interpretting this.
Yes he is and I wish you guys would not waste the ASP processor and remove the () from the Response.Writes.

Response.Write "<br />"
Response.Write "Welcome " & rsGuestbook("Name")
Response.Write "<br />"
Response.Write "you currently have " & rsGuestbook("TotalAmount") & " points in your account."
Response.Write "<br />"

@tmurray--

You should use the Native Jet OLEDB driver instead of the deprecated ODBC one.
http://carlprothman.net/Default.aspx?tabid=87#OLEDBProviderForMicrosoftJet

Use getRows() or getString() instead of recordset looping.
getString()
'String = recordset.GetString(StringFormat, NumRows, ColumnDelimiter, RowDelimiter, NullExpr)
http://www.4guysfromrolla.com/webtech/121598-1.shtml

And, move away from any FrontPage proprietary code.
Use parameterized queries instead of dynamic SQL.
Use CSS for style formatting.

Create this query in your database, and save it as qPoints:
SELECT Name, TotalAmount FROM totals;

(untested - just typed in here)

<%@ Language="VBScript" %>
<%
Option Explicit
Response.Buffer = True

sub SQLConnect()
  set conn = CreateObject("ADODB.Connection")
  connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & db & ";"
  conn.open connstr
end sub

sub SQLDisconnect()
  conn.Close
  set conn = nothing
end sub

sub prt(str)
  Response.Write str & vbCrLf
end sub

sub lprt(str)
  Response.Write str & "<br />" & vbCrLf
end sub

dim conn, connstr, rs, db, str
db = Server.MapPath("/SCM/fpdb/ptdb/users.mdb")
SQLConnect
set rs = Server.CreateObject("ADODB.Recordset")
conn.open qPoints rs
if rs.BOF and rs.EOF then
  rs.Close
  set rs = nothing
  SQLDisconnect
  lprt "No records returned"
  Response.End
else
  str = rs.getString(,,"<br />" & vbCrLf,"<br />" & vbCrLf,"")
  rs.Close
  set rs = nothing
  SQLDisconnect
  prt "<html>"
  prt "<head>"
  prt "<title>My First ASP Page</title>"
  prt "<style type=""text/css"">"
  prt "BODY { background-color: white; color: black }"
  prt "</style>"
  prt "<script>
  prt "function validate(v) {"
  prt "  var re = /^\d{1}$/;"
  prt "  if(re.test(v)) != true {"
  prt "    alert('Only use digits');"
  prt "    return false;"
  prt "    }"
  prt "  if(v <1 || v > 3) {"
  prt "    alert('valid range is Team1 - Team3');"
  prt "    return false;"
  prt "    }"
  prt "  return true;"
  prt "  }"
  prt "</script>"
  prt "</head>"
  prt "<body>"
  prt str
%>
<!-- Begin form code -->
<form name="FrontPage_Form1" method="post" action="add_to_guestbook.asp" onsubmit="return this.Selection.selectedIndex">
<p style="text-align: center; left-margin: 5px">
Selection: <select size="1" name="Selection">
<option value="Team1">Team1</option>
<option value="Team2">Team2</option>
<option value="Team3">Team3</option>
</select><br />

Amount: <input type="text" name="amount" maxlength="3" size="3" /><br />
</p>
<p style="text-align: center"><input type="submit" name="submit" value="Submit" /></p>

</body>
</html>
kiddanger,

I agree that you do not have to put in the () around the Response.Write and I do not use them.  All I was doing was copying the question's code
and updating it to accomplish what tmurray22's understanding of the language.

Bubs
I don't think there's a huge overhead with using parantheses anyway.

In fact - I see a benefit. When I change my ASP to vbscript I just copy and paste my home-made "response" object in there and the response.write still works. (It wouldn't work without parantheses.)

Anyway - every developer has their own ways.
@bubba--

I know.  Perhaps it's preference but I think it is our job to also educate on best practices when it's easy to do so.  IMO, the difference between a good developer and adequate developer is performance,  modularity and security.

@fritter--

You're right that's it's not a big overhead but for each user and each call it adds up.  It's like driving your car with the emergency break slightly engaged.  It'll still go forward but why make it work harder when you don't have to.  Of course, that could just be your way.  (O:=

I'm not sure what 'homemade response object' you're referring to but Response.Write ALWAYS works without parens.

Response.Write only takes one parameter, the string you want to output but Response.Write is actually a call to a subroutine.  You can verify it this way.

Response.Write("one","two")

It returns this:
Microsoft VBScript compilation error '800a0414'

Cannot use parentheses when calling a Sub

/lab/ee/test12.asp, line 1

Response.Write("one","two")
---------------------------^

Response.Write "one","two"

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Response.Write'

/lab/ee/test12.asp, line 1

It's still an error but it shows the correct error.  To verify it, you must use the Call keyword when calling a subroutine with parens and more than one parameter.

Call Response.Write("one","two")

Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Response.Write'

/lab/ee/test12.asp, line 1

Same error.  You can't leave the ( ) off when using the Call keyword or you will get a different error.

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/lab/ee/test12.asp, line 1

Call Response.Write "one","two"
--------------------^

What does this tell us?  Perhaps Eric Lippert can explain it better but parens causes more [needless] processing.  It's minimal but, as I said, it adds up.
http://blogs.msdn.com/ericlippert/archive/2003/09/15/52996.aspx

Your benefit shouldn't be "less effort" vs a performance hit.
>>I'm not sure what 'homemade response object' you're referring to but Response.Write ALWAYS works without parens.
I just add a

dim Response
Set Response = Server.CreateObject("Myobject.ProgID")

and that dll has a Response object that I made to handle .write .cookies etc. (It just stores and outputs the data on command - great for debugging ASP) (Write is also a function - so parantheses are needed)

Eric does not say that using parantheses is a performance problem. His post states that in VBScript if you call a sub with one argument with parantheses it "is a subroutine call with no parens around the arg list, but parens around the first argument". The parantheses in this case cause VBScript to "evaluate a subexpression before the rest of the expression". There is no evaluation to be done (signified by the lack of operator) so VBScript sends the parameter to the subroutine as it is.

If you want proof, try putting an operator in your parantheses:

response.write("hello" = "nothello")
will output:
False

It could very well be a perfomance hit - I'm not arguing that - but until I see proof I'm gonna stick to using parantheses (even though this is obviously incorrect syntax) as it helps to be able to copy and paste ASP into ASP.Net projects without having to go through and modify all the calls to response.write.
You know fritter...

It'll just get into the byVal vs byRef argument and subs vs functions.  There are minute differences and there are performance hits and actually byVal vs byRef is a little more than that as it can give a different result.  There are also small memory differences.  None of these are going to effect anyone on a small scale.  Large applications with many users is where you will see noticeable differences.

Note: Using the () you are passing byVal in Classic ASP and byRef in .NET.  To make them the same, you could consider using Call so they're both byRef.  All developers have different styles and methods and reasons for coding a certain way.  A lot of the bad ones are out of ignorance as one cannot know every "best practice" and a lot of the good ones are out of intelligence, most likely through experience, and some are probably due to stubbornness because that's the way they've always done it and are resistant to change.
You can't pass a string constant as byRef so surely the parantheses ARE necessary to pass as a byVal parameter?

I'd also like to point out that all Microsoft documentation gives examples using the response.write subroutine using parantheses.
fritter...

I already said () pass byVal.  RTFS!

You can do it anyway you want.  You're going to anyway but don't sit there and tell me I'm wrong and make wild claims with nothing to back it up.
ALL is an unknown.  You haven't read ALL MSFT documentation.  Eric said, if it's not to evaluate an expression or it doesn't include the Call keyword, DON'T USE IT!
It doesn't get any clearer than that.

How about some more people saying the same thing?

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=32

If you can't "get it" from this next post, there's no hope for you.  (O:=

http://www.aspfaqs.com/webtech/072800-1.shtml

He [Bill Wilkinson] also explains when passing byVal a copy is made, which does what, wastes processing and memory.  Now, where did we hear that before?
Seems the fairest way to me.
Shouldn't we follow the rules re: two correct answers at the same time?  No offense meant to anyone.
https://www.experts-exchange.com/help.jsp#hi104