Wednesday, 11 April 2012

C# :Count the total number of lines in RichTextBox

All you have to use is RichTextBox.GetLineFromCharIndex method.

int lineNumber = richTextBox1.GetLineFromCharIndex(richTextBox1.TextLength) + 1;
MessageBox.Show(lineNumber.ToString());
This 2 lines of code will give you number of lines in RichTextBox

You will find more detailed explanation here:
GetLineFromCharIndex[^]

Here is complete example of counting total number of lines in RTB

Saturday, 7 April 2012

C#: Read from excel file

I used .NET 2.0 framework. Reading from excel file is depends on excel's version, not entirely but it will affect your source code little bit.

Here is little tip about reading excel file.
string mFileName; // file name which you will read from.
System.Data.OleDb.OleDbConnection connection;
string mSheetName; // excel file consists of many sheets / pages.
System.Data.OleDb.OleDbDataAdapter dtAdapter;
Reading from excel file is as same as reading from database, so that you will need connection string which helps you to connect your program to excel sheets, as well as dataAdapter which will retrieve data from excel sheet.

This function accepts 2 arguments which are describe excel file's name, and it's version.
If you are using excel 2007 then send true as a second argument, or else send false when you call this function.

C#: Read from command Prompt

I've been trying to read from Command prompt using c#. My application supposed to read lines from cmd whatever it shows. My Purpose was developing code editor and using external compiler.
 You need to use  System.Diagnostics.Process(System.Diagnostics.ProcessStartInfo).

System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("file.exe", "command");
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.StandardOutputEncoding = //change if you need, you might need it
startInfo.StandardErrorEncoding = //change if you need, you might need it
//...

Using this example, file.exe could be any executable file and command, it should be related to exe file. In this example, file.exe is "cmd.exe" and "command" is "RUNCOB"

PHP: How To Create Thumbnail image.

Someone may wonder that when we have Photoshop, why do we bother to create thumbnail images using Php? Well answer is quite easy, whenever you upload photos to your web site to attract your readers or someone, every time you will have to cut or crop or do something on your photos by manually. Is not it annoying?
Once you completed your few lines of code you will no longer suffer from editing photos.
Here is your source code.

// Path of photo.
$img_name="Gear2nd.sized.jpg";
//In this case thumbnail image size will be twice smaller than its original.
//based on original photo's size this size can be changed.
$thm_size=2;
// Type
header('Content-type: image/jpeg');
// Generating Thumbnail's size.
list($width, $height)=getimagesize($img_name);
$new_width=$width / $thm_size;
$new_height =$height / $thm_size;
// Generating thumbnail image
$thm_img=imagecreatetruecolor($new_width, $new_height);
$img=imagecreatefromjpeg($img_name);
imagecopyresampled($thm_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// show off the thumbnail
imagejpeg($thm_img, null,100);

Result :
Good luck

Wednesday, 29 February 2012

In museum.

I wanted to upgrade ram of my laptop so much. So i went to several shops and service centers and i got same answers, which was
"I could find matching ram in museum".
It inspired me, because i've got valuable museum item LoL.



After, i wanted to change my cell phone's battery and i went to Nokia shop, and i was questioned if i have permission to carry a weapon (nokia 3310)?
i found it very funny.

Monday, 30 January 2012

Car racing Game: Source code Step by Step - 2

OK, here is the last step of the game. You can copy this code and arrange these 3 steps as follows.
step - 1
step - 2
step - 0
I mean, 1st copy the step - 1 into some CPP file and then step - 2 and lastly step - 0.
Hope you'll enjoy the game.

Monday, 26 December 2011

Car racing Game: Source code Step by Step - 1

I know that looking at plain code is not desirable, so just keep this code with you and wait for few days. The game, car racing, will be completed in few days. Just as i said, it is pain in the ass looking at the code that doesn't have an explanation but if you pay attention and need any help, i would gladly support you in any way.
I'm ready to explain every single line if you require. But first complete the game, and execute the game.
First thing is first.
So here code comes.