Categories

Subscribe via Email

Enter your email address to subscribe and receive notifications of new content by email.

Check A Date Is Valid

This example displays a form on a page . The user then enters a date , if the date is invalid then a message will be displayed on the screen . Examples of valid dates are as follows

12-12-09

12/12/09
<form method =”post” action=”<%= Request.ServerVariables(“SCRIPT_NAME”) %>”>
<input type =”text” name=”date”><br>
<input type=”submit”>
</form>
<%

Dim strDate , blnValid , dteDate
If Request.ServerVariables(“CONTENT_LENGTH”) <>0 Then
strDate = Trim(Request.Form(“date”))
‘check and see if the user entry is a date
If isDate(strDate) Then
dteDate = CDate(strDate)
‘set variable to true
blnValid = True
Else
‘display invalid date message
Response.Write “You entered an invalid date”
End If
‘displayvalid date message
If blnValid = True Then
Response.Write “The date you entered was ” & dteDate
End If
End If
%>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

Text Counter

Now create a folder called counters or you can call it something else if you want just remember and change the code above . Now create a text file called counter1.txt and enter whatever you wish to start the count at.

<%@ Language=VBScript %>
<%
Dim fso
Set fso = Server.CreateObject(“Scripting.FileSystemObject”)
//this is the path to your counter1.txt file
counter = Server.MapPath(“/counters”) & “\counter1.txt”
//open the text file
Set InStream = fso.OpenTextFile(counter , 1, False)
oldCount = Trim(InStream.ReadLine)
//increment the oldcount by 1 and store in newcount
newCount = oldCount + 1
Set OutStream = fso.CreateTextFile(counter, True)
//copy newcount to the text file
OutStream.WriteLine(newCount)
%>

Now you would place the folllowing where you want the counter to appear on your site

<%= newCount%>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

Saving a CSV file to a database

Create a database in access called stock.mdb .

Now create a table like in the image in figure 1 and save this as stock

stock database

stock database

Now ensure that the last price , change , open price , daily high , daily low fields all have the field size set as Double , this is because the data is fractional and if you use the default Field size for a Number data type in Access this will give you a Long Integer and you will lose some of the data.

<!– #include file =”adovbs.inc”–>
<%

‘declare variables for the database
Dim objConn , objRS
‘create instance of the Connection object
Set objConn = Server.CreateObject(“ADODB.Connection”)
‘open our stock database
objConn.Open “DBQ=” & Server.MapPath(“stock.mdb”) & “;Driver={Microsoft Access Driver (*.mdb)}”
‘create instance of the recordset object
Set objRS = Server.CreateObject(“ADODB.Recordset”)
‘our SQL statement
strSQL = “SELECT * FROM stock”
‘open the database
objRS.Open strSQL, objConn , adOpenStatic , adLockOptimistic
‘declare our variables for the file handling
Dim objFSO , strURL , objFile
‘create an instance of the file system object
Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)
‘this is the csv file downloaded from yahoo
strURL = Server.MapPath(“quotes.csv”)
‘open the file
Set objFile = objFSO.OpenTextFile(strURL)
‘while we are not at the end of the file
Do While Not objFile.AtEndOfStream
‘store the contents of the file in strText
strText = objFile.readLine
‘split the strText
arrText = split(strText, “,”, 9)
‘add our new records
objRS.AddNew
objRS(“symbol”) = arrText(0)
objRS(“last price”) = arrText(1)
objRS(“date”) = arrText(2)
objRS(“time”) = arrText(3)
objRS(“change”) = arrText(4)
objRS(“open price”) = arrText(5)
objRS(“daily high”) = arrText(6)
objRS(“daily low”) = arrText(7)
objRS(“volume”) = arrText(8)
‘update the database
objRS.Update
Loop
‘close and destroy objects
objRS.Close
objFile.Close
Set objRS = nothing
Set objConn = nothing
Set objFile = Nothing
Set objFSO = Nothing
%>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare