Thursday, 19 April 2012
Wednesday, 18 April 2012
Saturday, 14 April 2012
Wednesday, 11 April 2012
C# :Count the total number of lines in RichTextBox
All you have to use is RichTextBox.GetLineFromCharIndex method.
You will find more detailed explanation here:
GetLineFromCharIndex[^]
Here is complete example of counting total number of lines in RTB
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.
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.
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
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.
Result :
Good luck
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;// Typeheader('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 thumbnailimagejpeg($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.
"I could find matching ram in museum".
It inspired me, because i've got valuable museum item LoL.
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.
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.
Tuesday, 20 December 2011
Car racing Game: Source code Step by Step - 0
I mentioned about developing car racing game earlier. So now i think i will supply the source code of it. Since it ain't small program, i'll make it several parts.
Here, i start with the main function, and next time i will add all necessary classes and its methods.
So, main function comes as follows
Here, i start with the main function, and next time i will add all necessary classes and its methods.
So, main function comes as follows
Wednesday, 7 December 2011
C#: System data types
C# Shorthand | System Type | Range | Meaning in life |
| sbyte | System.Sbyte | -128 to 127 | Signed 8-bit number |
| byte | System.byte | 0 to 255 | Unsigned 8-bit number |
| short | System.Int16 | -32.768 to 32.767 | Signed 16-bit number |
| ushort | System.UInt16 | 0 to 65.535 | Unsigned 16-bit number |
| int | System.Int32 | -2.147.483.648 to 2.147.483.647 | Signed 32-bit number |
| uint | System.UInt32 | 0 to 4,294,967,295 | Unsigned 32-bit number |
| long | System.Int64 | –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | Signed 64-bit number |
| ulong | System.UInt64 | 0 to 18,446,744,073,709,551,615 | Unsigned 64-bit number |
| char | System.Char | U0000 to Uffff | A single 16-bit Unicode character |
| float | System.Single | 1.5x10-45 to 3.4x1038 | 32-bit floating point number |
| double | System.Double | 5.0x10-324 to 1.7x10308 | 64-bit floating point number |
| bool | System.Boolean | true or false | Represents truth or falsity |
| decimal | System.Decimal | 100 to 1028 | A 96-bit signed number |
| string | System.String | Limited by system memory | Represents a set of Unicode characters |
| object | System.Object | Any type can be stored in an object variable | The base class of all types in the .NET universe |
Saturday, 3 December 2011
Friday, 2 December 2011
log2( x ): Binary Logarithm
In the math.h of Turbo C, binary logarithm ( log2( ) ) doesn't exists. When we are working with tree, we need to calculate depth of the tree, as well as the number of nodes in that depth.
The number of nodes in ith depth can be calculated using : 2i . formula
the max number of node in ith depth : n = 2i - 1 (complete tree).
You can use these formula to find the number of nodes in particular depth.
On the other hand, you may need to find the depth you are currently in.
There is a very easy way to do that. This is using binary logarithm to find the current depth.
If i made mistakes let me know
Good luck
The number of nodes in ith depth can be calculated using : 2i . formula
the max number of node in ith depth : n = 2i - 1 (complete tree).
You can use these formula to find the number of nodes in particular depth.
On the other hand, you may need to find the depth you are currently in.
There is a very easy way to do that. This is using binary logarithm to find the current depth.
... #include <math.h> double log2(double x) { return log(x) / log(2); }
If i made mistakes let me know
Good luck
Wednesday, 30 November 2011
Tuesday, 29 November 2011
Binary Search
Very useful searching algorithm, in every step the number of data, which is going to be sorted will cut into half (fig 1). But keep it in your mind that it works on only sorted data.
Let N be the number of data then,
in worst case the comparison will be done log2(N) + 1 times. And in case of linear searching, the number of comparison would be N.
For example: if we are going to search a number among a million others, in the worst case scenario, the number of comparison would never be exceeded 20. But in case of linear searching algorithm, the number of comparison would be 1.000.000
Source code :
Let N be the number of data then,
in worst case the comparison will be done log2(N) + 1 times. And in case of linear searching, the number of comparison would be N.
For example: if we are going to search a number among a million others, in the worst case scenario, the number of comparison would never be exceeded 20. But in case of linear searching algorithm, the number of comparison would be 1.000.000
Source code :
Saturday, 26 November 2011
Tuesday, 10 May 2011
PHP : Login Page
Here is simple guide to create login page. About design, you can create one as you like using html. This is simple design that i created to demonstrate how login page works. You can use just two text-boxes and submit button, that is all.
Make sure that your text-boxes and submit button are inside the "Form" which uses method field and action field as shown below.
<Form name="Form1" method="post" action="login.php"> ...When you hit login or submit button, all data which are inside this form will be thrown to login.php.
And they won't appear in address bar. Because method is post.
Saturday, 23 April 2011
C/C++ : Quick Sort
Here is the source code of quick sort. This algorithm also knowns as most efficient search algorithm.
I don't know why but it doesn't work appropriately. It works on 100 data but more than that it crushes.
If you find bug let me know, thank you.
I've used Hoare-partition
I don't know why but it doesn't work appropriately. It works on 100 data but more than that it crushes.
If you find bug let me know, thank you.
I've used Hoare-partition
Here is the code.
int partition( int a[ ], int low, int high )
{
int piwot, right, left;
left = low + 1 ;
right = high ;
piwot = a[ low ];
while(1)
{
while( a[ right ] > piwot ) right--;
while( a[ left ] < piwot &&a left < high ) left++;
if ( left < right )
swap( a, left, right );
else{
swap( a, low, right );
return right;
}
}
}
void quickSort( int a[ ], int low, int high)
{
int part;
if( low < high )
{
part = partition( a, low, high );
quickSort( a, low, part -1 );
quickSort( a, part +1, high );
}
}
Tuesday, 19 April 2011
C# : Detecting cursor position in RichTextBox
When i was working on RichTextBox the main thing that i had to handle was counting lines and detecting cursor position. Now lets see how to get these things done. Let me tell you about how to detect cursor position.
You need to use:
RichTextBox.SelectionStart and RichTextBox.GetLineFromCharIndex()
But make sure you use instance method of RichTextBox class as show
here :GetLineFromCharIndex[^] and GetLineFromCharIndex[^]
You will find detailed explanation here:
DllImportAttribute[^]
You need to use:
RichTextBox.SelectionStart and RichTextBox.GetLineFromCharIndex()
But make sure you use instance method of RichTextBox class as show
here :GetLineFromCharIndex[^] and GetLineFromCharIndex[^]
private static int EM_LINEINDEX = 0xbb;
int index, line, col;
[DllImport("user32.dll")]
extern static int SendMessage(IntPtr hwnd, int message, int wparam, int lparam); [DllImport("user32.dll")]This line of code shouldn't be written in any method or functions.You will find detailed explanation here:
DllImportAttribute[^]
Subscribe to:
Posts (Atom)










