Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone please look at this code any suggestions are apprectiated

Status
Not open for further replies.

WhiteZiggy

Programmer
Jan 22, 2003
85
US
Hello all. I am pretty new to ASP so this is my first crack at it. I have some code I wrote, could anyone give me their comments/suggestions ..

<HTML>
<BODY>
<%
'Variable Declarations
Dim SQL ' Used for building SQL strings to open recordsets
Dim CONN ' Connection Object
Dim rsInvoices ' Invoices recordset
Dim rsInvoiceLineItems ' Invoice Line items recordset
Dim InvoiceTotal ' Used to calculate Invoice Total Amount
'Create/Initialize Database Objects
Set CONN = Server.CreateObject(&quot;ADODB.connection&quot;)
CONN.Open &quot;Driver={SQL Server};Server=DBServer01;Database=Billing; Trusted_Connection=yes;&quot;
Set rsInvoices = Server.CreateObject(&quot;ADODB.Recordset&quot;)
'Write Customer number header
Response.Write &quot;Invoices for Customer Number &quot; & Request.QueryString(&quot;CustomerID&quot;) & &quot;<BR>&quot;
'Retrieve invoice records for the selected date range.
SQL =&quot;SELECT * FROM Invoices WHERE (CustomerID = &quot; & Request.QueryString(&quot;CustomerID&quot;) & &quot;)
ORDER BY InvoiceDate&quot;
rsInvoices.Open SQL,CONN
WHILE NOT rsInvoices.EOF
'Calculate Invoice Total
SQL = &quot;Select * from InvoiceLineItems WHERE InvoiceNumber=&quot; & rs(&quot;InvoiceNumber&quot;)
Set rsInvoiceLineItems = CONN.Execute(SQL)
InvoiceTotal = 0
WHILE NOT rsInvoiceLineItems.EOF
InvoiceTotal = InvoiceTotal + rsInvoiceLineItems(&quot;UnitPrice&quot;) *
rsInvoiceLineItems(&quot;Quantity&quot;)
rsInvoiceLineItems.MoveNext
WEND
'Display Invoice Information
Response.write &quot;Invoice Number: &quot; & RS(&quot;InvoiceNumber&quot;) & &quot;<BR>&quot;
Response.write &quot;Payment Terms: &quot; & GetPmtTerms(Request.QueryString(&quot;CustomerID&quot;)) & &quot;<BR>&quot;
Response.write &quot;Invoice Date: &quot; & RS(&quot;InvoiceNumber&quot;) & &quot;<BR>&quot;
Response.write &quot;Invoice Total: &quot; & InvoiceTotal & &quot;<HR>&quot;
WEND
%>
</BODY>
</HTML>
<%
Function GetPmtTerms(CustomerID)
Dim CustomerRS 'Customer Table Recordset
Dim SQL ‘For building Query string
'Get record for customer
Set CustomerRS = server.CreateObject(&quot;ADODB.recordset&quot;)
SQL = &quot;SELECT PaymentTerms FROM Customers WHERE CustomerID=&quot; & CustomerID
Set CustomerRS = CONN.execute(SQL)
'Handle CustomerID not found condition
IF Customer (RS.EOF AND CustomerRS.BOF) THEN
GetPmtTerms = &quot;Unknown&quot;
ELSE
GetPmtTerms = CustomerRS(&quot;PaymentTerms&quot;)
END IF
CustomerRS.Close
CONN.Close
End Function
%>
Expected Sample Output

Invoices for Customer number 5

Invoice Number: 1
Payment Terms: Net-30
Invoice Date: 12/12/2002
Invoice Total: $500.00
---------------------------
Invoice Number: 2
Payment Terms: Net-30
Invoice Date: 12/22/2002
Invoice Total: $50.00
Invoice Number: 3
---------------------------

Thanks in advance..WZ
 
at first glance I would say to keep everything witht he same methods. you first populate your recordset with a open method but then use two executes. the execute is quicker anyways but all in all I would use all of one thing to make for ease of reading and debugging. place your function after declarations in the beginning of the script as well wiht a option explicit. i might format the loop a bit differently but looks fine for your first script. any erros arise?

one other thing. use some tabs.
WHILE NOT rsInvoiceLineItems.EOF
InvoiceTotal = InvoiceTotal + rsInvoiceLineItems (&quot;UnitPrice&quot;) *
rsInvoiceLineItems(&quot;Quantity&quot;)
rsInvoiceLineItems.MoveNext
WEND
'Display Invoice Information
Response.write &quot;Invoice Number: &quot; & RS(&quot;InvoiceNumber&quot;) & &quot;<BR>&quot;
Response.write &quot;Payment Terms: &quot; & GetPmtTerms(Request.QueryString(&quot;CustomerID&quot;)) & &quot;<BR>&quot;
Response.write &quot;Invoice Date: &quot; & RS(&quot;InvoiceNumber&quot;) & &quot;<BR>&quot;
Response.write &quot;Invoice Total: &quot; & InvoiceTotal & &quot;<HR>&quot;
WEND _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top