JHC3 – Programming Notes

August 17, 2007

VBScript: SIMPLE FileSystemObject

Filed under: ASP.NET — navaan @ 11:33 am
<%
	set fso = Server.CreateObject("Scripting.FileSystemObject")
	configFile = Server.MapPath("/") & "\test.log"
	set theFile = fso.OpenTextFile(configFile, 1) '1=Read, 2=Write, 8=Append

	do until theFile.AtEndOfStream or x = 10
		Response.Write(theFile.ReadLine & "<br />")
		x = x + 1
	loop

	theFile.close
%>

JavaScript: Notes from 010411

Filed under: ASP.NET — navaan @ 11:05 am

Always start with;

<script language="javascript">
  <!--
	//code here
  -->
</script>

<script language="javascript">

  //Popup Message
  window.alert("Message Here");

  //Click OK or Cancel Message Box
  window.confirm("OK or Cancel Message Here");

  //Prompt User for Input
  window.prompt("Input Vars");

//Creates a Function called calc
function calc(i) {
  //Sets x to what the user types in
  var x=window.prompt("Enter Number");

  //Shows what the User Just Typed In
  window.alert("You Entered: " + x);

  //Prints to the Screen (VBScript = Response.Write)
  document.write(i);
  }

  calc("Test Message");

</script>

Call a function when the page loads;

  //In the BODY tag enter the function like so
  <body onload="calc();">

Old Tattered Notes…

Filed under: ASP, JavaScript, PHP, SQL — navaan @ 10:35 am

I’m going to be entering a bunch of old notes I had laying around. ASP, VBScript, JavaScript and maybe some other stuff.

Also, I have decided to learn PHP. It’s like ASP/VBScript because they are both scripting languages (Spaghetti code! Wee!) but a lot more powerful. As far as working as a web developer the main choices I’ve seen are, ASP, ASP.NET, and PHP. ASP is getting to be a rarety as ASP.NET is wanted more and more. PHP, however, is starting to show up more and more also.

June 6, 2007

Encoding from Database to RSS Compat.

Filed under: ASP.NET — navaan @ 3:23 pm

I stored HTML into a database for describing upcoming shows/events, but RSS doesn’t like HTML tags. So here’s my solution;

001 <?xml version="1.0" encoding="UTF-8"?>
002 <rss version="2.0">
003 	<channel>
004 		<title>Grandstand Sales, Inc.</title>
005 		<link>http://www.GrandstandSales.com/</link>
006 		<description>Grandstand Sales, Inc.</description>
007 		<language>en-us</language>
008 		<pubDate>Wed, 06 Jun 2007 12:14:00 EST</pubDate>
009 		<lastBuildDate>Wed, 06 Jun 2007 12:14:00 EST</lastBuildDate>
010 		<docs>http://www.GrandstandSales.com/GS/feed.aspx</docs>
011		<generator>GrandstandSalesGen</generator>
012 		<managingEditor>jcook@kimbersinc.com</managingEditor>
013 		<webMaster>jcook@kimbersinc.com</webMaster>
014
015 		<asp:repeater id="Repeater1" runat="server" datasourceid="AccessDataSource1">
016 			<ItemTemplate>
017 				<item>
018 				<title><%# Repl(Eval("ActName"))%> <%# Repl(Eval("ActGuest"))%></title>
019 				<link>http://www.grandstandsales.com/gs/Detail.aspx?id=<%#Eval("ID") %></link>
020 				<description>
021 					<%#Repl(Eval("ActStart"))%> -
022 					<%#Repl(Eval("ActDesc"))%>
023 				</description>
024 				<pubDate><%#dformat(Eval("dts"))%></pubDate>
025 				<guid>http://www.grandstandsales.com/gs/Detail.aspx?id=<%#Eval("ID") %></guid>
026 				</item>
027 			</ItemTemplate>
028 		</asp:repeater>
029
030 	</channel>
031 </rss>
032
033 <asp:accessdatasource id="AccessDataSource1" runat="server" datafile="~/App_Data/grandstand.mdb"
034 selectcommand="SELECT * FROM [Acts] WHERE ([OrderID] <> ?) ORDER BY [OrderID]">
035 	<SelectParameters>
036 		<asp:Parameter Type="Int32" DefaultValue="0" Name="OrderID"></asp:Parameter>
037 	</SelectParameters>
038 </asp:accessdatasource>
039
040 <script runat="server">
041 	Function Repl(ByVal str)
042 		Dim s As String = str
043 		s = Replace(s, "&nbsp;", " ")
044 		s = Server.HtmlEncode(s)
045 		Return (s)
046 	End Function
047
048 	Function dformat(ByVal rawDate)
049 		Dim rfc As String = ""
050 		Dim dt As String = rawDate '6/9/2007 5:30:00 PM
051
052 		Dim A, B, C, D, E, F, G, H As String
053 		'(A)Wed, (B)09 (C)Jun (D)2007 (E)20:(F)30:(G)00 (H)GMT
054
055 		Dim arrDT As Array = Split(dt, " ") Dim oDate As Date = arrDT(0) '6/9/2007
056 		Dim oTime As DateTime = arrDT(1) + " " + arrDT(2) '5:30:00 PM
057
058 		A = oDate.DayOfWeek  'Wed
059 			Select Case A
060 				Case 1
061 					A = "Mon"
062 				Case 2
063 					A = "Tue"
064 				Case 3
065 					A = "Wed"
066 				Case 4
067 					A = "Thu"
068 				Case 5
069 					A = "Fri"
070 				Case 6
071 					A = "Sat"
072 				Case 7
073 					A = "Sun"
074 			End Select
075 		B = oDate.Day '09 (day)
076 			If B < 10 Then
077 				B = "0" + B
078 			End If
079 		C = oDate.Month 'Jun (month)
080 			Select Case C
081 				Case 1
082 					C = "Jan"
083 				Case 2
084 					C = "Feb"
085 				Case 3
086 					C = "Mar"
087 				Case 4
088 					C = "Apr"
089 				Case 5
090 					C = "May"
091 				Case 6
092 					C = "Jun"
093 				Case 7
094 					C = "Jul"
095 				Case 8
096 					C = "Aug"
097 				Case 9
098 					C = "Sep"
099 				Case 10
100 					C = "Oct"
101 				Case 11
102 					C = "Nov"
103 				Case 12
104 					C = "Dec"
105 			End Select
106 		D = oDate.Year '2007 (year)
107 		E = oTime.Hour + 4 '20 (hour)
108 		F = oTime.Minute '30 (minute)
109 		G = "00" '00 (second)
110 		H = "GMT" 'GMT (zone)
111
112 		rfc = A + ", " + B + " " + C + " " + D + " " + E + ":" + F + ":" + G + " " + H
113
114 		Return (rfc)
115 	End Function
116
117 </script>

Line 001: This HAS to be on the First Line

Lines 015 to 028: I used a simple Repeater Control for the Item tags

Line 024: Calls the dformat Function (Lines 048 – 117)

Line 033: The WHERE clause simply hides the inactive/past events

Line 018, 021, 022: Call the Repl Function (Lines 041 -046)

Line 044: Encodes the Description to fix problems with Ampersands and Double Quotes

Line 048: This Function takes an Access DateTime Format and spits out an RFC-822 happy Format assuming an Eastern Time Zone (Line 109)

April 9, 2007

Programmatic OLEDB Conn/Cmd/Loop

Filed under: ASP > ASP.NET, ASP.NET — navaan @ 3:34 pm
Dim sqlGet As String = "SELECT * FROM [Table] ORDER BY [col1] DESC"
Dim conn As New Data.OleDb.OleDbConnection
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ToString

Dim cmd As New Data.OleDb.OleDbCommand(sqlGet, conn)

conn.Open()
Dim rsRecordSet = cmd.ExecuteReader()

Do While (rsRecordSet.Read())
Label1.Text = FormatCurrency(rsRecordSet("Total"), 2)
Loop

conn.Close()

February 9, 2007

.NET Cheat Sheets

Filed under: ASP.NET — navaan @ 9:17 am

Pretty useful. http://john-sheehan.com/blog/index.php/net-cheat-sheets/

January 30, 2007

Movenext

Filed under: ASP > ASP.NET, ASP.NET — navaan @ 3:20 pm

ASP » Do…Loop Through a RecordSet

 Do Until rs.eof
  'do something
  'rs("col1")
 rs.MoveNext
 Loop

ASP.NET » Do…Loop Through a RecordSet

 Do While (rs.Read())
  'do something
  'rs.Item("col1")
 Loop

ASP.NET » MoveNext Equivalent

 rs.Read()
  'do something
  'rs.Item("col1")
 rs.Read()
  'do something with the next record
  'rs.Item("col1")

ASP.NET » Repeater Within HTML

<Repeater id="rp1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
 'do something
 <%# Bind("date") %>
</ItemTemplate>
</Repeater>

January 18, 2007

ConfigurationManager.AppSettings(“i”)

Filed under: ASP > ASP.NET, ASP.NET — navaan @ 3:16 pm

ASP » Application("varName")
ASP.NET » ConfigurationManager.AppSettings("varName")

Add to web.config:
 	<configuration>
 	<appSettings>
 	<add key="varName" value="100" />
 	</appSettings>
 	</configuration>

January 17, 2007

Repeater

Filed under: ASP > ASP.NET, ASP.NET — navaan @ 9:58 pm

Repeater, the new Do Until rs.eof

<Repeater DataSourceID="SqlDataSource1" runat="server">
<HeaderTemplate></HeaderTemplate> 	'Start Table
<FooterTemplate></FooterTemplate> 	'End Table
<ItemTemplate></ItemTemplate> 	'Build Table Body #Eval("column_Name")
</Repeater>

Replaces the Spaghetti Do…Loop Code.

Simple AJAX demo…

Filed under: ASP.NET — navaan @ 11:48 am

Here’s a simple AJAX demonstration… Very simple.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
 	  <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"> 	... 	</asp:GridView>
 	</ContentTemplate>
<Triggers>
 	  <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="SelectedIndexChanged" />
 	</Triggers>
</asp:UpdatePanel>
Older Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.