Showing posts with label ASP. Show all posts
Showing posts with label ASP. Show all posts

July 10, 2008

ASP Email

I have never had such a hard time finding the correct way to create an online form that email the contents. Apparently there are several way to do email, but at least on the server that I have access to non of them work. Apparently there was/is a old way of doing email objects with CDONTS, however Microsoft has replaced that with CDOSYS, sadly most of the guides online to doing email forms with asp use the older CDONTS way, which on the server I have access to does absolutely nothing...

SO after looking through many guides I finally found a correct (in the fact that it works) way of doing ASP based email.


Set oCdoMail = Server.CreateObject("CDO.Message")
Set oCdoConf = Server.CreateObject("CDO.Configuration")

sConfURL = "http://schemas.microsoft.com/cdo/configuration/"

with oCdoConf
.Fields.Item(sConfURL & "sendusing") = 2
.Fields.Item(sConfURL & "smtpserver") = "localhost"
.Fields.Item(sConfURL & "smtpserverport") = 25
.Fields.Update
end with

with oCdoMail
.From = "your server"
.To = "email to send to"
.Subject = "Subject line"
.HTMLBody = "Body of email"
.Configuration = oCdoConf
.Send
end with

Set oCdoConf = Nothing
Set oCdoMail = Nothing


I do warn you that this works for me, and should... (and I take should lightly) work for you, however I feel that it is worth warning on that fact that depending on how your server is set up, who knows how ASP will function.

July 8, 2008

Multi Line ASP

I had been searching for a way to use multi line strings in ASP, because having it run for two pages across is just bad programing style, and so it string = string & new content over and over. Of course I finally found the solution, and once again ASP is like Fortran 95 in the fact that you can use &_ to continue onto another line, as reference you just use & in fortran. It still confuses me why Microsoft thought it would be a wonderful idea to ignore almost every other major programing language and not end lines in semicolons. But then again they always tend to create their own eccentric standards as they go, a luxury of having such a huge control of the market I assume.

June 21, 2008

ASP Stock Ticker

Another little ASP script that I had to whip up was a stock ticker. I had searched around for a free javascript version, however they where either way to complicated and ad ridden to use, or they just did not work. So like most situation call for I just gave up on that idea and whipped up my own version.

It is very simple, it just pulls the CVS data on the stock from yahoo finance and prints out a table row, that way I can use single calls in a table row, and just make a new row and call for each different stock. Also I have an up and down arrow image, but you can make your own. This should be a good starter for people looking for a simple stock ticker. I am using an asp include to call the whole page for code simplification, but you can just drop the code in a page and it will work.


<%
function getQuote(name,location)
strURL = location
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "GET",strUrl, false
objXMLHTTP.send
ProcessUrl = objXMLHTTP.ResponseText
Set objXMLHTTP = Nothing
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

dim quote
quote = Array()

' Split the string at the comma characters and add each field to a ListBox
quote = Split(ProcessUrl, ",")

if quote(4) >= 0 then
Response.Write "<td>" & name & "</td><td><img src='images/up.gif'></td><td><font color='green'>" & quote(1) & "</font></td><td><font color='green'>" & quote(4) & "</font></td>"
else
Response.Write "<td>" & name & "</td><td><img src='images/down.gif'></td><td><font color='red'>" & quote(1) & "</font></td><td><font color='red'>" & quote(4) & "</font></td>"
end if
end function
%>

<center>
<h3>Stock Ticker</h3>
<table width="190" border="0" cellspacing="1" cellpadding="1">
<tr>
<% getQuote "Dow", "http://download.finance.yahoo.com/d/quotes.csv?s=%5EDJI&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
<tr>
<% getQuote "Nasdaq", "http://download.finance.yahoo.com/d/quotes.csv?s=%5EIXIC&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
<tr>
<% getQuote "S&P 500", "http://download.finance.yahoo.com/d/quotes.csv?s=%5EGSPC&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
<tr>
<% getQuote "10Yr Bond(%)", "http://download.finance.yahoo.com/d/quotes.csv?s=%5ETNX&f=sl1d1t1c1ohgv&e=.csv" %>
</tr>
</table>
</center>

June 10, 2008

50 Posts & ASP

Wow it has been over a half year since I started this blog!

For my internship I have been working an an updated site for Prescott Brokerages Services, and after getting the layout pretty much finished I I needed a very simple login page for agents, easy for me except for the fact that I can not use PHP, their web hosting company Webfodder uses Microsoft Server and only supports ASP. So just like last summer with learning PHP this time I am learning ASP. Luckily like most programing languages, it is close enough to PHP that I am having no problems picking it up. It may be just me but ASP reminds me of Fortran mixed with PHP.

It only took a few minutes to whip up a simple login script


<%
'// Check login if used, otherwise ignore
if request.form("pass")="password" then
'// Redirect to another page if correct
Response.Redirect "other_page.html"
end if
%>


This i pulling from a form on the home page, luckily it only need to be deterrent for legal reasons and not a full secure page, otherwise I would never hard code it.