Promote Your Blog

Saturday, December 22, 2012

How to Put Text Watermark in LaTex


\usepackage {draftwatermark}

Package Options

  • \usepackage [firstpage] {draftwatermark}
  • \usepackage [nostamp] {draftwatermark}

Commands to Modify Watermark Properties

  • \SetWatermarkText {Confidential} % default is DRAFT

  • \SetWatermarkText {\textsc{Confidential}} % For changing text style

  • \SetWatermarkLightness {0.5} % any real number

  • \SetWatermarkScale{4} % Default is 1.2

  • \SetWatermarkFontSize {2cm} % Max is 5 cm

  • \SetWatermarkAngle {30} % Default is 45 deg

  • \SetWatermarkColor [rgb] {0.7,0,0} % Color spec

  • \SetWatermarkColor [red] % package color is required with usenames option

  • \SetWatermarkColor [gray] {0.5} % gray level


1. \SetWatermarkColor is not working in my texlive installation, although its given in official documentation of   draftwatermark package. Somebody suggested to update LaTex installation as colored watermark came in Jan, 2012

2. Notice that Commands begin with capital S like \Set and Watermark is a single word with only W in capital but m small

3. It works for textual watermark. For image watermarks, wait for my next post on same.

Computer Science to Impress Your Valentine in 2013

Here's a trick to impress your Valentine. Just type in this maths equation in the Google searchbar:

"sqrt(cos(x))*cos(300x)+sqrt(abs(x))-0.7)*(4-x*x)^0.01, sqrt(6-x^2), -sqrt(6-x^2) from -4.5 to 4.5"

 and wait for the magic to unfold. 

Wednesday, November 28, 2012

How to Write an Application Using Letter Class of Latex

\signature{Your Name\\ \hspace*{1cm}Your Designation}

%address{Street \\ City \\ Country}
\date{} %to avoid printing date on top
\begin{letter}{To, \vspace*{0.5cm}\\ The Person, \\ Company, \\ Address, \\ City-PIN \\ \vspace*{1cm} \textbf{Subject: My Application Subject:}}
\opening{Respected Sir or Madam,}
\item Your Contents in list or paragraph form
\hspace*{4cm} Thanking You,
\closing{Yours Sincerely,}
\vspace*{-1cm} Dated: \today
%\ps{P.S. Here goes your ps.}


  1. Red colored text to be replaced with your particulars
  2. Comment green text if you don't want current date to be inserted
  3. Modify this template to suit your style

Thursday, July 5, 2012

Microsoft's Approach to Application Lifecycle Management

Although, Microsoft is a late entrant into Application Lifecycle Management (ALM) products but according to Gartner's report, Microsoft is now leading ahead all its competitors.

Following figure shows how different products (MS Project, Visual Studio, Sharepoint, Office etc.) are integrated through Team Foundation Server (TFS) to deliver support for full ALM covering Project Management, Requirements Management, Version Control, Test Case Management, Build Automation, and Reporting.

The salient features of Visual Studio versions shown in above figure are given in figure below:

Friday, May 11, 2012

How to Make Fancy Page Headers and Footers in Latex

To make your reports/books have fancy pages, follow these simple steps:

1. Before \begin{document}, declare this package to be used:

2. All pages do not have fancy style (like Acknowledgment & Table of Contents pages}. So, before those pages, write

3. For pages, where fancy headers & footers are required, declare this intent by writing:

4. Clear default settings for header & footer by

5. Here is a LaTex code sample for fancy header & footer
\lhead {"My Doc Name"}

\lfoot{"My Project"}
\cfoot{"--Ver No.--"}

l,c,r indicates left, centre, right of head or foot as the case be

6. You can also use,


E-->Even Page No.
O-->Odd Page No.

More to come about fancy pages in next post....

Friday, March 23, 2012

How To Continue Numbering in Enumerate From Previous List?

To pause and resume, enumerate using following (taken from a website and works wonderfully)



\item first;

\item second;

This is a paragraph.

\item third;

\item and so on...

Remember, \newcounter{tempcounter} goes before \begin{document}

How To Change Page Orientation From Portrait To Landscape

Default page style is Portrait in LaTex. You can change it to Landscape using:



After \end{landscape}, page orientation will again be default one i.e. Portrait

How To Change Default Style For Enumerate and Itemize

Default style can for enumerate can be changed using
\renewcommand{label}{style} command

where 'label' may be any of the following:

  1. \labelenumi: first level
  2. \labelenumii: second level
  3. \labelenumiii: third level
  4. \labelenumiv: fourth level
style may be any combination of characters and numbers. The item number for each list may be printed using by using any of the following (from first depth to fourth depth):

  1. enumi
  2. enumii
  3. enumiii
  4. enumiv
These numbers may be styled with the following macros:

  1. \alph{number}: lowercase letters
  2. \Alph{number}: uppercase letters
  3. \arabic{number}: numbers
  4. \roman{number}: lowercase roman numerals
  5. \Roman{number}: uppercase roman numerals

Try following:

\renewcommand{\labelenumi}{\arabic{enumi}. }
\renewcommand{\labelenumii}{\labelenumi\alph{enumii}) }
\renewcommand{\labelenumiii}{\labelenumii\roman{enumiii}: }

This would be added to the top of the document, before \begin{document}.

From TexBlog


\begin{enumerate}[I]%for capital roman numbers.



\begin{enumerate}[(a)]%for small alpha-characters within brackets.



For changing style for itemize, try these:
  • \renewcommand{\labelitemi}{$\bullet$}
  • \renewcommand{\labelitemii}{$\cdot$}
  • \renewcommand{\labelitemiii}{$\diamond$}


Friday, March 2, 2012

How To Send Email using

Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("your gmail id", "your email password")
SmtpServer.Port = 587
SmtpServer.Host = ""
mail = New MailMessage()
mail.From = New MailAddress("your gmail id same as above")
mail.To.Add("recipient email id")
mail.Subject = subject
mail.Body = "Dear User, " & Environment.NewLine & Environment.NewLine & eb & Environment.NewLine & Environment.NewLine & "Regards," & Environment.NewLine & "HowToCodeIt"
MsgBox("Notification emailed successfully")
Catch ex As Exception
End Try

Note that SMTP details are for GMAIL. If you want to send email from some other provider say Yahoo or Rediff then google internet for their SMTP Port and Host details and do approp. replacement in the above code...

Also, as you can see that body is read from windows controls..same can be done for subject and email address of recipient etc.

Database Operations (CRUD) Using OleDB in

In this post, you will learn how to use OleDb to:

  • Connect to data source
  • Add records to database
  • Modify an existing record
  • Read the desired record
  • Read all records
  • Delete a particular record
  • Delete all records from database

Imports System.Data.OleDb

Dim conString As String

Dim con As OleDbConnection

Dim dr As OleDbDataReader


conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=w:\newdata.mdb"

con = New OleDbConnection(conString)



Dim strSql As String


strSql = "insert into books values('" & tbBook.Text & "','" & tbAuthor.Text & "')"

Dim cmd As OleDbCommand = New OleDbCommand(strSql, con)

Dim icount As Integer = cmd.ExecuteNonQuery

If icount > 0 Then

MsgBox(tbBook.Text & " book added to your library")



MsgBox(tbBook.Text & " cannot be added to your library")

End If

Catch ex1 As Exception


End Try


Dim strSql As String


strSql = "update books set author = '" & tbAuthor.Text & "' where book = '" & tbBook.Text & "'"

Dim cmd As OleDbCommand = New OleDbCommand(strSql, con)

Dim icount As Integer = cmd.ExecuteNonQuery

If icount > 0 Then

MsgBox(tbBook.Text & " author updated")



MsgBox(tbBook.Text & " author cannot be updated")

End If

Catch ex1 As Exception


End Try


Dim selItem As String

Dim strSql As String

For i = 0 To lstBooks.Items.Count - 1

If lstBooks.GetSelected(i) Then

selItem = lstBooks.GetItemText(lstBooks.Items(i))

End If


strSql = "delete from books where book='" & selItem & "'"

Dim cmd As OleDbCommand = New OleDbCommand(strSql, con)

Dim icount As Integer = cmd.ExecuteNonQuery

If icount > 0 Then

MsgBox(selItem & " deleted sucessfully")



MsgBox(selItem & " cannot be deleted")

End If


Dim strSql As String

strSql = "delete * from books"

Dim cmd As OleDbCommand = New OleDbCommand(strSql, con)

Dim icount As Integer = cmd.ExecuteNonQuery

If icount > 0 Then

MsgBox("All books deleted successfully")



MsgBox("All books cannot be deleted")

End If


Private Sub DB2List(ByRef lb As ListBox)

Dim strSql As String = "select * from books"

Dim dadapter As OleDbDataAdapter

dadapter = New OleDbDataAdapter()

dadapter.SelectCommand = New OleDbCommand(strSql, con)

Dim dset As DataSet = New DataSet()

dadapter.Fill(dset, "Books")

lb.DataSource = dset

lb.DisplayMember = "Books.Book"

End Sub


Private Sub RetrievConditional(ByVal bk As String)

Dim strSql As String = "select * from books where book = '" & bk & "'"

Dim cmd As OleDbCommand = New OleDbCommand(strSql, con)

dr = cmd.ExecuteReader

While dr.Read()

tbBook.Text = dr(0)

tbAuthor.Text = dr(1)

End While

End Sub

Code is self explanatory...

How To Display Selected Picture in

In this post, you will learn, how to:

  • Use OpenFileDialog to choose Jpeg files only
  • How to display selected jpg image

OpenFileDialog2.InitialDirectory = Directory.GetCurrentDirectory

OpenFileDialog2.Title = "Select a File"

OpenFileDialog2.FileName = ""

OpenFileDialog2.Filter = "Jpeg Files (*.jpg)|*.jpg"

OpenFileDialog2.FilterIndex = 1

If OpenFileDialog2.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then

PictureBox1.Image = Image.FromFile(OpenFileDialog2.FileName)


MsgBox(“You Approp. Msg”)

End If

How To Use Environment Variables In

To set environment variable, right click my computer > Properties > Advanced > Environment Variables

Dim envVar As String = Environment.GetEnvironmentVariable("One of set environment variable")

How To Use .NET Charting Control

.NET provides a wonderful control for charting plots. Here are basic steps:

  • Drag and drop CHART control from toolbox to your application form/dialog etc.
  • Position it appropriately
  • There can be multiple plots (CHART AREAS) on a Chart
  • Add SERIES to Collection and assign each series to appropriate CHART AREAS
  • Choose type of plot - Line, Bar,....
  • Set Legends
  • Set Titles
  • Label Axis
  • IsValueIndexed must be set to TRUE for X-Axis

Don't worry!!! A detailed tutorial is on the way that will teach you how to do all these steps..illustrating through actual snapshots.

Then, there are some operations on chart that you do programmatically. Some of these operations are:

Imports System.Drawing.Printing

Imports System.IO

Imports System.Windows.Forms.DataVisualization.Charting




Clearing Points in a Chart Series

Chart1.Series("Name given to series at design time").Points.Clear()

Setting width from Series line

Chart1.Series("Name given to series at design time ").BorderWidth =

Adding Points to a Series

Chart1.Series("Name given to series at design time ").Points.AddXY(x, y)

Saving Output As Image

Chart1.SaveImage(“meaningful filename”, ChartImageFormat.Jpeg)

How To Count Number of Records In A .csv File

You are right!!! Just put a counter inside the while loop reading .csv file row by row i.e.

Dim ir As Integer = 0

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fn)

MyReader.TextFieldType = FileIO.FieldType.Delimited


Dim currentRow As String()

While Not MyReader.EndOfData


currentRow = MyReader.ReadFields()

ir = ir + 1

Catch ex As Microsoft.VisualBasic.


MsgBox("Line " & ex.Message &

"is not valid and will be skipped.")

End Try

End While

End Using

How To Read A .csv File

Suppose I have .csv (Comma Separated values) file and I need to read certain columns of this file and plot them (related post: using .NET Chart Control). So, here is the code to read .csv files:

Imports System.IO.FileInfo

Imports System.IO

Dim x As Double, y1 As Double, y2 As Double

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(fn) 'fn =.csv File name

MyReader.TextFieldType = FileIO.FieldType.Delimited


Dim currentRow As String()

Dim i As Integer

Dim j As Integer

j = 0

x = 0.0

While Not MyReader.EndOfData


currentRow = MyReader.ReadFields()

Dim currentField As String

If j <> 0 Then ‘Skipping Header Row

i = 0

For Each currentField In currentRow

If i = 0 Then ‘First column

x = currentField

ElseIf i = 4 Then ‘Fifth column

y1 = currentField

ElseIf i = 5 Then

y2 = currentField

End If

i = i + 1


‘Do the operation on retrieved values. E.g. plotting them using .Chart Control (see relevant post)

x = x + 1

End If

j = j + 1

Catch ex As Microsoft.VisualBasic.


MsgBox("Line " & ex.Message &

"is not valid and will be skipped.")

End Try

End While

End Using

How To Add Selected Items In A ListBox To A ListViewBox

In ListViewBox, each item can have different color and also ListViewBox can display columnar data.

Let us see code to:

  • Access selected items in ListBox
  • Set content & color of item to be added in ListViewBox
  • Clear items, Add items and set display properties of a ListViewBox

Dim sc() As Color = {Color.Blue, Color.Green, Color.Orange, Color.Black, Color.Red, Color.Chocolate, Color.DarkMagenta, Color.DarkKhaki, Color.Crimson, Color.HotPink, Color.Firebrick, Color.Goldenrod, Color.ForestGreen, Color.IndianRed, Color.DarkSalmon}

Form1.ListView1.View = View.Details

Dim ic As Integer = 0


For Each it In lstDirList.SelectedItems

Dim x As New ListViewItem

x.Text = it.ToString

x.ForeColor = sc(ic)


ic = ic + 1


How To Read Files With Given Extension In All Directories In Given Path

To read all the files with ".csv" extension in all the directories under a folder selected through FileBrowseDialog, the following code will work:

Imports System.IO.FileInfo

Imports System.IO

Dim Dir As String

Dim fni As FileInfo


For Each Dir In System.IO.Directory.GetDirectories(folderDlg.SelectedPath)

For Each fi In System.IO.Directory.GetFiles(Dir)

fni = My.Computer.FileSystem.GetFileInfo(fi)

If fni.Extension = ".csv" Then


End If



You should also note how to:

  • Get names of all directories in a path
  • Names of all files in these directories iteratively
  • Information about a file
  • Comparison of file extension with desired one
  • How to clear data items from a list box and how to add items to listbox

How To Use FolderBrowseDialog in

Sometimes, your VB app need to get a selected folder for further operations. Say, a folder where to install your app. In this case and many alike situations, you can make use of FolderBrowseDialog.
Following code snippet shows how to use FolderBrowseDialog:

Imports System.Windows.Forms

Imports System.IO

Dim folderDlg As New FolderBrowserDialog

folderDlg.ShowNewFolderButton = False

folderDlg.SelectedPath = "C:\My Path"

If (folderDlg.ShowDialog() = DialogResult.OK) Then


End If

Saturday, January 28, 2012

How To Add Data To Tables in MS Access Database Using ADODB and Visual Basic

We have already created database in my post How To Create MS Access Database Using ADOX and Visual Basic and learnt how to add table to database in post How To Add Tables to MS Access Database Using ADOX and Visual Basic. Now its time to add data to the added table in created database. Here is the code to do this using ADODB:

Imports ADODB

Const adOpenStatic = 3
Const adLockOptimistic = 3

Dim objConn As ADODB.Connection
Dim objRS
Dim strDBName, strTable As String
strDBName = "MyLibrary.mdb"
strTable = "Books"
objConn = CreateObject("ADODB.Connection")
objRS = CreateObject("ADODB.Recordset")
objConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & strDBName)
objRS.Open("SELECT * FROM " & strTable,
objConn, adOpenStatic, adLockOptimistic)

objRS("Book") = tbBook.Text
objRS("Author") = tbAuthor.Text


objRS = Nothing
objConn = Nothing
MsgBox("Data Added Successfully")

Book and Author names are read from the GUI. Note that connection and recordset are closed before setting to Nothing

Getting confused first ADOX and then ADODB...Let me add more to confusion by adding more terms like ADO, ADO.NET, DAO, RDO, OLEDB, ODBC...

To sort out this confusion, read post on Microsoft Data Access Components at blog on Computer Science Notes.

How To Add Tables To An MS Access Database Using ADOX and Visual Basic

Let us add table to database created in my post How To Create MS Access Database Using ADOX and Visual Basic

Dim ADOXcatalog As New ADOX.Catalog
Dim ADOXtable As New ADOX.Table
Dim ADOXindex As New ADOX.Index

On Error GoTo errhandler
ADOXcatalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "MyLibrary.mdb")

On Error Resume Next

ADOXcatalog.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& "MyLibrary.mdb"

'name table, append fields to table
ADOXtable.Name = "Books"

'ADOXtable.Columns.Append("ID", ADOX.DataTypeEnum.adInteger)
ADOXtable.Columns.Append("Book", ADOX.DataTypeEnum.adVarWChar, 200)
ADOXtable.Columns.Append("Author", ADOX.DataTypeEnum.adVarWChar, 30)

'append tables to database

'internal index on two fields
'ADOXindex.Name = "TwoColumnsIndex" 'name of index


If Err.Number = -2147217897 Then
MsgBox("Database already exists")
ElseIf Err.Number <> 0 Then
MsgBox("Err " & Err.Description & "; operation not complete")
End If
ADOXtable = Nothing
ADOXindex = Nothing
ADOXcatalog = Nothing

Since database already exists, error handler will be invoked and this message will be prompted. Cleaning is very important by setting to Nothing