Code Snippets Links Programming

Hello World

As a computer software programmer, one must have learned and use these two words “Hello World”. It is unsaid theory to write a hello world program to start learning a programming language. You can read the “greatness” of hello world at

Or get a Hello world program for your programming language from this collection of Hello world

Code Snippets Javascript Programming

LightBox Vs VideoBox Vs Custom Code

Recently I was given a task to make LightBox and VideoBox work on same page, where we have Images and Video to show. However, Videobox is inspired by Lightbox as per developer, they are not compatible with each other. The reason I found is that they share few variable and hence they are breaking each other’s code. Now since we need functionality to be done, I have give to find a quick alternative solution..When my company said quick solution they mean a solution in next 1 hr.

Let us check what we can do..Lightbox, read image tag with a tag and show image based on those, and this is what Videobox do, it read for “rel=vidbox” in anchor tag, and then it detect the type of video source to display the item in bigger div. What I do is I modify it to recognize images as well, i.e. if we put rel=”vidbox” in anchor tag for your images, (something we do in lightbox) my modified VideoBox code will read and check for extension jpg, jpeg, gif,png and if found i write “custom code” in variable this.other to show img tag instead of SWFObject or other.

Now VideoBox is no more a video only box, and it can handle Images for me as well :).

Download modified VideoBox Code

Code Snippets SQL

Creating SQL Table from another table

Often we need to take quick backup of database with data before we can make changes in table. for this I create the image of table within same database, as it is the fastest method. It is one of the reason why one need to create image a table.. or copy one table from another.

It can be achieved in all RDBMS

Here is SQL for MS SQL

select * into newTable from OldTable

However, their is another command (it works for me on mysql)

create table newtable as (select * from oldtable)

Best of luck with backup and server transfers.

Code Snippets Programming SQL

Setting/Resetting Auto increment value in MSSQL 2005

Once you create a table and what to reset autoincrement value of a table to your desire number, you need to set some system table values, which are not available for direct editing. To perform this you need to do following:


This statement simply show all table in your select table with auto increment value. Once this gives you good information, you can run following command to change value

DBCC CHECKIDENT(‘mytable’,RESEED,[new numeric value])

If this runs perfect give something like this:

Checking identity information: current identity value ’14’, current column value ’30’.DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Otherwise it give an error. (In above message 14 and 30 will be replaced with your values.

MSDN Link for more details :

Code Snippets Javascript Links

Calculating distance

With increasing use of Map service such as google, yahoo and MSN one often need to calculate distance between two location. This can be done many ways I suppose. However, to calculate the short distance we can perform calculation based on longitude and latitude values of those two location.

 However, it is simply a math formula you need to learn but you should now the coordinates of location as well. Here is one beautiful article and Javascript method do to that

This script explain all its working and from where it is drived. Such a nice place to learn something new :).

Code Snippets Flash

How to remove all child movieClip through AS 2.0 Code

To remove all child from a given movie clip simple loop through its all object and remove the type of object you want. Following code does the same for related_mc.sp_related name movie clip:

for (obj in related_mc.sp_related){
// root.mc1[obj] instanceof MovieClip same as typeof(_root.mc1[obj])==”movieclip”
       if (typeof(related_mc.sp_related[obj])==”movieclip”){

this loop through all child of related_mc.sp_related and remove the instance if its of the type “movieclip”.

.NET C#.NET Code Snippets Programming VB.NET/VB

Printing Text Document in .NET 2.0

Some time reporting tools are too heavy to use with a small application. Something similar happens with me, I need to print a Single page text information for this I cannot use any Heavy reporting software although this information is fetched from XML/Database. So I opt to use in built .NET feature and having following for you to use now.

 First Add a PrintDialog box on your Windows Application that gives printing capability.

Now Include a Object with its events in your code

Private WithEvents doctoprint As New Printing.PrintDocument

Once we have these basic Set up now, we can simply copy paste given two function on page to Print document define in FILE_PATH constant

Private Sub PrintDocument()
PrintText.AllowSomePages = False
PrintText.AllowSelection = False
 PrintText.ShowHelp = False
 PrintText.Document = doctoprint

 Dim result As DialogResult = PrintText.ShowDialog

 If result = Windows.Forms.DialogResult.OK Then
 streamToPrint = New StreamReader(FILE_PATH)
 doctoprint.DocumentName = "Title to Show on 'Now printing dialog'"
 Catch ex As Exception
 MsgBox("Unable to print")
 End Try
 End If
 End Sub

 Private Sub doctoprint_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles doctoprint.PrintPage

'change this line tochange default font for printing.
 Dim printFont As New System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Regular)

 Dim linesPerPage As Single = 0
 Dim yPos As Single = 0
 Dim count As Integer = 0
 Dim leftMargin As Single = e.MarginBounds.Left
 Dim topMargin As Single = e.MarginBounds.Top
 Dim line As String = Nothing

 ' Calculate the number of lines per page.
 linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)

 ' Print each line of the file.
 While count < linesPerPage
 line = streamToPrint.ReadLine()
 If line Is Nothing Then
 Exit While
 End If
 yPos = topMargin + count * printFont.GetHeight(e.Graphics)
 e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
 count += 1
 End While

 ' If more lines exist, print another page.
 If Not (line Is Nothing) Then
 e.HasMorePages = True
 e.HasMorePages = False
 End If
 End Sub

Now, simply call your PrintDocument() function to start printing of FILE_PATH using your Print Button or menu option.