Monday, April 7, 2008
Thursday, July 26, 2007
Once, Again
A lesson I learnt long ago, at the initial stages of working in this job as Software Engineer... & I forgot how to do it AGAIN.
To remove the border for hyperlinked image, use the border property:
< href = "whateveryourlinkis" border = "0">
As for the underline in the hyperlinked text and the default blue colour, use CSS to be rid of it:
a:link
{
text-decoration: none;
/*this can be any other colour you want, not necessarily black*/
color: #000000;
}
Monday, July 16, 2007
Google Analytics
Google Analytics
Module for adding Google Analytics to a Joomla site
How to install & configure the Joomla Google Analytics module
Wednesday, July 4, 2007
Adobe Flex Builder 3 Beta Release (Code Name Moxie)
It's cool.
Flex Developer Center
Friday, June 29, 2007
Wednesday, June 27, 2007
Wednesday, June 20, 2007
Friday, June 15, 2007
Tuesday, June 12, 2007
Trees... Trees... & MORE Trees...
The Basics of a TreeView
You'll be familiar with the look and feel of a treeview from the Windows Explorer. Its name of course refers to a regular tree, that has one trunk and many branches and where each branch can have smaller branches. The stem is the treeview object itself, the "branches" are called nodes. The main difference between a branch and a node is that the thickness of a node doesn't need to decrease; on the contrary: the 'ends' can easily be the thickest part of the whole: that is contain the most items.
In principle the number of items and childnodes is unlimited (read: a number you will not easily reach
Populating the treeview during runtime is very easy: just go to the Collection property and press the "..." button. You can play around with the possibilities. To populate during runtime:
Code:
'Method 1: straightforward adding of nodes
With Me.TreeView1.Nodes
'add text
.Add("AddByText")
'since with..end with is used: read TreeView1.Nodes.Add ....
'every add method returns the newly created node. You can use
'this concept set the result to a variable or to directly add
'a childnode:
.Add("AddByText2").Nodes.Add("ChildOfAddByText")
'this, you can take as far as you want
.Add("AddByText3").Nodes.Add("ChildOfAddByText").Nodes.Add("Another child")
'--
N = .Add("AddByText, Attach To Variable")
N.Nodes.Add("Child one")
N.Nodes.Add("Child two")
' --
With .Add("AddByText Use WithTo Add ChildNodes").Nodes
.Add("Child 1")
.Add("Child 2")
.Add("Child 3").Nodes.Add("Subchild 1")
End With
End With
'for clarity, from here on, the treeview1 name will be added.
'In everyday use, you'll probably find the use of with..end with
'a lot easier (I know I do..)
'Method 2: adding by node
'Like virtually every .Net method you can directly assign an object:
Me.TreeView1.Nodes.Add(New TreeNode("AddByNode"))
'check out the overloading possibilities of using New()
'Another advantage of this method is that you can add a complete branch.
'(N is already declared as TreeNode above)
N = New TreeNode("MainNodeToAdd")
N.Nodes.Add("Child 1")
N.Nodes.Add("Child 2")
'you can for instance add this newly created node to all main branches:
Dim enumNode As TreeNode
For Each enumNode In TreeView1.Nodes
enumNode.Nodes.Add(N.Clone) '<- the clone() method is needed
Next
'Adding will always add the the node at the end of the collection.
'Of course you can also insert at a specified location:
Me.TreeView1.Nodes.Insert(2, New TreeNode("I am inserted at the 3th position"))
'removing is done much in the same way:
N = TreeView1.Nodes.Add("I need to be removed").Nodes.Add("and all children too")
TreeView1.Nodes.Remove(N)
'to clear all branches of any node you can use clear()
N.Nodes.Add("This child you will not see")
N.Nodes.Clear()
'if you use Clear on the treeview nodes itself, you
' would once again have an empty treeview
'once an item has been added, it is part of the item collection in nodes
'this means you can access it by its index
TreeView1.Nodes(0).Text = "I have index 0"
'the behaviour of the treenode can be controlled completely in code.
'you can make it expand
TreeView1.Nodes(0).Expand()
'and retract again
TreeView1.Nodes(0).Collapse()
This is just the basic functionality. There are a lot more properties on a treeview. Some are inherited, some are specific to the treeview object. The sample above should give enough information to create your own treeview. Have fun
To finish: an example
Code:
'this example will fill a treeview with the hours of the day.
'the hours will be divided in 15 minute blocks and the blocks
'will be divided in minutes
Sub Example()
Dim N As New TreeNode(), I As Integer, J As Integer
'create a 15 minute block
For I = 0 To 3
With N.Nodes.Add((I * 15).ToString & "-" & ((I + 1) * 15 - 1).ToString)
'add the minutes
For J = 0 To 14
.Nodes.Add((J + I * 15).ToString)
Next
End With
Next
'add the hours and immediately add the blocks to the hours as well
Dim NodeToAdd As TreeNode
For I = 1 To 24
NodeToAdd = N.Clone
NodeToAdd.Text = I.ToString
TreeView1.Nodes.Add(NodeToAdd)
Next
End Sub
'the sub when a time has been chosen
Private Sub ItemChosen(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
Dim N As TreeNode = CType(sender, Windows.Forms.TreeView).SelectedNode
If N.GetNodeCount(False) = 0 Then 'it is 'last' in the line
Dim S As String = N.Text
If S.Length = 1 Then S = S.Insert(0, "0")
S = N.Parent.Parent.Text & ":" & S
MessageBox.Show("You have selected: " & S)
End If
End Sub
Monday, June 11, 2007
Thursday, June 7, 2007
Shorties
Use F7 key for bringing up the code window in VB.NET 2005. F5 for running/testing/debugging the program.
#Region "Name of Region" for categorising your blocks of code into separate expandable & collapsible nodes.
Use For Each loops to run through lists or classes or dictionaries & the like.
Whenever a particular section of code keeps getting reused a considerable number of times, it warrants making it into a separate subprocedure or function of its own.
Put short comment lines into parts of conditional blocks of code where nothing is done/executed. This is for future purposes, to prevent you thinking it's an error of sorts & waste time tweaking the code unnecessarily.
Thursday, May 31, 2007
VB.NET: The Number Of Days Between Dates
'Retrieve the earliest & latest date recorded in info.csv to get the range of days covered
Sub GetNumberOfDays()
Dim begDate As DateTime
Dim endDate As DateTime
Dim numRows As Integer
Dim timeDiff As TimeSpan
Dim numDays As Integer
Try
begDate = CDate(dgvReport.Rows(0).Cells(0).Value)
numRows = dgvReport.RowCount
endDate = CDate(dgvReport.Rows(numRows - 2).Cells(0).Value)
timeDiff = endDate.Date - begDate.Date
numDays = timeDiff.Days
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
MessageBox.Show(CStr(numDays))
End Sub
My tribute to TechRepublic for passing on the tip. Thanks Irina Medvinskaya!
Tuesday, May 29, 2007
How to set up a static IP address on a Windows XP computer
Source: PortForward.com
It is very important to setup a static ip address, if you are going to use port forwarding. When you have port forwarding setup, your router forwards ports to an ip address that you specify. This will probably work when you initially set it up, but after restarting your computer it may get a different ip address. When this happens the ports will no longer be forwarded to your computer's ip address. So the port forwarding configuration will not work.
What is an ip address?
IP addresses are four sets of numbers separated by periods that allow computers to identify each other. Every computer has at least one ip address, and two computers should never have the same ip address. If they do, neither of them will be able to connect to the internet. There is a lot of information at the following link. You don't need all of it. But if you want to know more about how networks work, you'll find it there. For more information on ip addresses, subnets, and gateways go here
Dynamic vs Static IPs
Most routers assign dynamic IP addresses by default. They do this because dynamic ip address networks require no configuration. The end user can simply plug their computer in, and their network will work. When ip addresses are assigned dynamically, the router is the one that assigns them. Every time a computer reboots it asks the router for an ip address. The router then hands it an ip address that has not already been handed out to another computer. This is important to note. When you set your computer to a static ip address, the router does not know that a computer is using that ip address. So the very same ip address may be handed to another computer later, and that will prevent both computers from connecting to the internet. So when you asign a static IP addresses, it's important to assign an IP address that will not be handed out to other computers by the dynamic IP address server. The dynamic IP address server is generally refered to as the dhcp server.
If you have a printer, before you begin print out this page!
Step 1:
Open up the start menu, and click Run. You should now see the following window.
Step 2:
Type cmd in the Open: box, and click Okay. The will bring up a black command prompt window.
Step 3:
The command prompt may look different on your screen, but it doesn't really matter. Type ipconfig /all in that window, and then press the enter key. This will display a lot of information. If it scrolls off the top you may need to enlarge the window.
Step 4:
I want you to write down some of the information in this window. Take down the IP address, Subnet Mask, Default Gateway, and Name Servers. Make sure to note which is which. We are going to use this information a little bit later.
The name server entries are a bit complicated. Name Server is just another name for DNS(domain name server) server. Some router's act as a proxy between the actual name servers and your computer. You will know when this is the case, because the Default Gateway will list the same ip address as the Name Servers entry. We need to have the correct Name Server IP addresses. If we do not, you will not be able to browse the web. There are a couple ways to get these. The first way is to log into your router's web interface, and look at your router's status page. On that page you should see an entry for DNS Servers, or Name Servers. Write down the ip adresses of your Name Servers. Another way to get the correct Name Servers to use, is to give your ISP a call. They should know the ip addresses of your Name Servers right off. If they ask you why you need them, you can tell them you are trying to setup a static IP address on your computer. If they try to sell you a static external ip address, don't buy it. That's an entirely different thing that what you are trying to setup.
Type exit in this window, then press the enter key to close it.
Step 5:
Once again open the start menu. This time click Control Panel.
Step 6:
Double click Network Connections.
Step 7:
You may have several network connections in this window. I want you to right click on the one you use to connect to the internet. Then click properties.
If you are unsure of which one that is, right click it and then click disable. Open a new copy of your web browser? Did it open a webpage? If you can not, then you've found your internet connection. Close that browser window. Go ahead and right click the network connection again and then click enable. Once again open up a new web browser. You should see a webpage. Close the browser window. Right click on the network connection and click properties at the bottom.
Step 8:
You should now have the above window on your screen. Click the properties button to open up the properties window of this internet connection.
Step 9:
Click Internet Protocol(TCP/IP) and then the Properties button. You will now see the following screen.
Step 10:
Before you make any changes, write down the settings that you see on this page. If something goes wrong you can always change the settings back to what they were! You should see a dot in the Obtain an IP address automatically box. If you do not, your connection is already setup for a static ip. Just close all these windows and you are done.
I realize this guide is fairly difficult to understand, so I've added a new section here that will help you determine exactly what ip address to set your computer to.
Put the subnet mask we previously found in the subnet mask section. The default gateway should go into the Default gateway box. Enter the dns servers we prevoiusly found into the two DNS Server boxes. Click okay all the way out of this menu.
If you find that you can not pull up webpages, the problem is most likely the dns numbers you entered. Give your ISP a call, and they will be able to tell you which dns servers to use. This is a question they answer all of the time. They will be able to tell you what you should use right away.
That's it you should be done! If you can't connect to the internet go back and change your configuration back to what it originally was.
Monday, May 28, 2007
VB.NET: Data Grid View & Reading From CSV File
Public Class frmReport
Private Sub btnGenerateReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerateReport.Click
'Datagridview dgvReport settings
Me.Controls.Add(dgvReport)
dgvReport.ColumnCount = 5
With dgvReport.ColumnHeadersDefaultCellStyle
.ForeColor = Color.White
.Font = New Font(dgvReport.Font, FontStyle.Bold)
End With
With dgvReport
.Name = "dgvReport"
.Location = New Point(8, 8)
.Size = New Size(500, 250)
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
'Define top column names in dgvReport
.Columns(0).Name = "Date-Time"
.Columns(1).Name = "Action"
.Columns(2).Name = "Area"
.Columns(3).Name = "Section"
.Columns(4).Name = "Link"
.Columns(4).DefaultCellStyle.Font = _
New Font(Me.dgvReport.DefaultCellStyle.Font, FontStyle.Italic)
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.Dock = DockStyle.Fill
End With
'Open file info.csv & read
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser _
("C:\Susanna's Work Stuff\Projects\DiGi\DiGi MDL\2007_05_28\reports\reports\bin\info.csv")
'Specify that reading from a comma-delimited file
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
With Me.dgvReport.Rows
.Add(currentRow) 'Add new row to dgvReport
End With
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
End Sub
End Class
Got the chunk off 2 different MSDN pages. Thankfully it worked, after a bit of tweaking! Phew! All in a day's work...
Friday, May 25, 2007
Using Data Readers, SQL Server
http://www.java2s.com/Code/VB/Database-ADO.net/SqlDataReader.htm
Need to find out:
- what ORM is
- difference between SqlDataReader & SqlDataAdapter in VB.NET
VB.NET: Web Methods, Sessions, Database Operations
<webmethod(enablesession:=true,Description="Post feedback on session id, start time, end time")> _
Public Function PostFeedback() As String
Dim sID As String = HttpContext.Current.Session.SessionID
Dim connString As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings.Item(connStringID).ConnectionString
Dim myConn As SqlConnection = New SqlConnection(connString)
Dim insertCommand, selectCommand, updateCommand As SqlCommand
Dim myReader As SqlDataReader
Dim end_time As DateTime
Const delay As Single = 10
Dim msg As String = "none"
myConn.Open()
'check whether there are any existing session ids in feedback table that matches current session id
selectCommand = New SqlCommand("select feedback_session_id, feedback_end_time from feedback where feedback_session_id = '" & sID & "'", myConn)
myReader = selectCommand.ExecuteReader()
If myReader.HasRows = True Then
myReader.Read()
If myReader("feedback_end_time").Equals(DBNull.Value) Then
myReader.Close()
msg = "1"
'insert end time into feedback_end_time where the feedback_end_time field is empty
updateCommand = New SqlCommand("update feedback set feedback_end_time = " & Now() & "where feedback_session_id = '" & sID & "')", myConn)
updateCommand.ExecuteNonQuery()
Else
msg = "2"
end_time = myReader("feedback_end_time")
myReader.Close()
If (DateTime.Now - end_time).TotalMinutes < delay Then
'if difference between start time & end time less than 10 mins then update feedback_end_time
updateCommand = New SqlCommand("update feedback set feedback_end_time = " & Now() & "where feedback_session_id = '" & sID & "')", myConn)
updateCommand.ExecuteNonQuery()
Else
'if more than 10 mins, insert new row into feedback table with session id & start time
insertCommand = New SqlCommand("insert into feedback(feedback_session_id, feedback_start_time) values('" & sID & "', '" & Now() & "')", myConn)
insertCommand.ExecuteNonQuery()
End If
End If
Else
msg = "3"
myReader.Close()
'insert new row into feedback table with session id & start time
insertCommand = New SqlCommand("insert into feedback(feedback_session_id, feedback_start_time) values('" & sID & "','" & Now() & "')", myConn)
insertCommand.ExecuteNonQuery()
End If
myConn.Close()
Return msg '"Inserted " & sID.ToString
End Function
Wednesday, May 23, 2007
Database Interaction In ADO.NET
http://www.programmersheaven.com/2/Les_VBNET_13_p2
SQL Command Execution Methods:
| ExecuteNonQuery | Executes an SQL statement on the connected data source. You can use it for DDL statements, action queries (e.g., INSERT, UPDATE, and DELETE operations), and ad hoc queries. This method returns the number of rows affected but doesn't return output parameters or result sets. |
| ExecuteReader | Executes an SQL SELECT statement on the data source and returns a fast forward-only result. |
| ExecuteScalar | Executes a stored procedure or an SQL statement that returns a single scalar value. It returns the first row of the result set's first column to the calling application and ignores any other returned values. |
| ExecuteXMLReader | Executes a FOR XML SELECT statement that returns an XML data stream from the data source. The ExecuteXMLReader method is compatible only with SQL Server 2000 and later releases. |
Source: MSDN