58 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for tinstaafl

Basically this scheme uses variable offsets, but it generates the bytes on the fly. They aren't truly random, but there aren't any obvious patterns and the output passes all the NIST tests. Since a simple password can be used to do the de/encryption it is much easier to hand off …

Member Avatar for JamesCherrill
2
328
Member Avatar for ddanbe

Well, there was a thread about a frequency function and a bell curve in Excel. [url]http://www.daniweb.com/forums/thread295203.html[/url] So here it is how about to do the NORMDIST function in Excel in C#.

Member Avatar for dlhockey12
0
3K
Member Avatar for tinstaafl

There are times when you need to make sure your counter starts at an odd or even number. Even is pretty simple - `counter = counter + modulus(counter)`. If counter is even it stays, if it's odd it gets incremented by 1. Odd is a bit more complicated - `counter …

Member Avatar for holisticgroup19
3
4K
Member Avatar for ddanbe

Sometimes you have long processes and you even want display them up to the millisecond. Here is a way to do it.

0
1K
Member Avatar for ddanbe

[OH noo, please not that again!](https://www.youtube.com/watch?v=DvShTJKuy2w) Yeah, primes sigh. But they play a minor role here as a perfect victim to explain some other things. Would not advise to use the algorithm here to calculate them in real life. There are languages like Python, F#, Haskell etc. who have list …

Member Avatar for ddanbe
0
375
Member Avatar for Lusiphur

As it seems to come up often enough I figured I'd throw together a quick snippet outlining basic methods for data manipulation in SQL Server using C#. In all examples the coder will need to substitute their own connection string details and variables. I utilised parameters for 3 of the …

Member Avatar for sarvesh_3
2
21K
Member Avatar for ddanbe

This is easy! But I admit, it can be rather confusing at first if you also take the old style MenuItem stuff into account. I hope my code is as clear as possible. If not please let me know. To test it, just start a forms application and paste it …

2
6K
Member Avatar for ddanbe

One of the most, if not THE most, beautiful formulas in math, is from Euler: ![Euler_e_pi_i.png](/attachments/large/1/b32f45540a27b3efc328d14c60ee286c.png "align-center") It combines in it a relation between the number **e**, the number **Pi** and the complex number **i**, plus the basic math symbols 1, +, = and zero. Is that not amazing? More …

Member Avatar for JOSheaIV
1
613
Member Avatar for tinstaafl

This is a very simple login form. I set it up so that the form won't close until it's cancelled or a valid username and password are entered. I chained the check for the username and the check for the password, so that if the username doesn't pass the password …

Member Avatar for tinstaafl
0
7K
Member Avatar for TrustyTony

I did code for challenge that I saw posted for C# by deceptikon: http://www.daniweb.com/software-development/csharp/threads/479304/coding-challenge-string-to-date Here it is. Of course normally the code would be without prints and put in function, but this is enough for now for me. There could also be normalization from '/' separated form not producing ambiguous …

1
267
Member Avatar for sknake

Here is a sample code snippet of logging in a user against a user table in an MSSQL database with password encryption. Scott Knake

Member Avatar for pritaeas
10
7K
Member Avatar for ddanbe

Don’t know if this is ever been done before, or even if it is a good way to do it. I’ll just await your comments if any. What I mostly found on the web is that if you want to define a polynomial you need to have an array containing …

0
445
Member Avatar for ashishkumar008

[B]1.[/B] Right click on your project name in solution explorer. [B]2.[/B] Point the cursor on [COLOR="Green"]Add[/COLOR] then choose [COLOR="Green"]Existing Item...[/COLOR] [B]3.[/B] Now go to the Location of your sound file and select that sound file. [B]4.[/B] Now select your sound file in solution explorer then Right click on it choose …

Member Avatar for JOSheaIV
3
5K
Member Avatar for ddanbe

Yes, I know Fibonacci(=sun of a good man) again. Most famous for his series, but who among you all, know that he was the man who introduced to the Western world, the Arabic numeral system(including zero) in 1202 A.D.? The Italian merchands of those days adored it. It was far …

Member Avatar for Triryche
2
574
Member Avatar for ddanbe

The luxuries we now have in the amount of pixels on a screen to draw some amazing graphs with, were lacking in the early days of computing. Most of the time you had to resort to rude printed output. It wasn’t that bad always. Sometimes it was and still is …

Member Avatar for ddanbe
1
3K
Member Avatar for riahc3
Member Avatar for vegaseat

This short piece of code shows you how to display text in color in a C# windows console program. The corresponding WIN32 API functions are in the kernel32.dll and are imported and declared external. The only other problem is to assign variable types that accommodate the types listed in the …

Member Avatar for KrayZVIII
0
1K
Member Avatar for vinayphadke

Hello Guys, I was performing text file reading and writting operations and the job looked very simple as usual, yet it has not been solved successfully. We have got a simple text file **final.txt** which contains data like this:- **05/18/2012 02:12:66 8HRY hjhruehr737243 YES NO u34gewryge 698** i.e each value …

Member Avatar for gnath
0
264
Member Avatar for sandeepparekh9

Ever Thought if it was possible to not WebBrower control and use the Firefox Browser in your c# window Application...?? Yes ,, It is possible using GeckoFx wrapper class for C#.net and vb also. You will need the Followings: 1. [URL="http://code.google.com/p/geckofx/downloads/list"]GeckoFx Wrapper[/URL] 2. [URL="http://mirrors.directorymix.com/mozilla/xulrunner/releases/1.9.1.2/runtimes/"]Xul Runner[/URL] (Download the zip file from …

Member Avatar for newlonator
0
923
Member Avatar for ddanbe

While surfing the web I got to this site: [url]http://en.wikipedia.org/wiki/Fourier_series[/url] “Hey, I why not write something like this in C#!” The rather scary looking formulas did not withhold me to start coding (see below Fig. 1 and Fig. 2) The formula from Fig. 2 is hidden under one of the …

Member Avatar for skatamatic
0
3K
Member Avatar for ddanbe

When you want to draw something on a form you need a Graphics object. But a Graphics constructor isn’t public and if that is not enough the Graphics class is also sealed! This means you can’t create a Graphics object via the new keyword nor can you derive from the …

Member Avatar for skatamatic
0
4K
Member Avatar for vegaseat

Is it Mother Date and Father Time? Any way, getting all the different date and time displays working can be imperturbably perplexing at times. You take a look at it in this Windows Console Application.

Member Avatar for Tsawm
0
959
Member Avatar for Mahen
Member Avatar for ddanbe

What polar coordinates are is explained [url=http://en.wikipedia.org/wiki/Polar_coordinate_system]here[/url]. I wanted to draw some polar functions myself, so I changed my [url=http://www.daniweb.com/software-development/csharp/code/217204]plotting class [/url] a bit and added a polar struct to a new project.. Just posted code for the Plot class and the polar point structure here. You can find an …

2
1K
Member Avatar for ddanbe

I saw a thread lately on this site to rotate an integer. Seemed like a fun project to do. There are probably more efficient solutions out there but this is mine, and indeed it was fun! It is mostly a demo on how you could use the less known shift …

Member Avatar for kel634
0
2K
Member Avatar for ddanbe

I find C# very well suited for doing math and all sorts of calculations, so here is an example. Just start a Console application and fill in the code. Have fun! The code also shows a use of delegates and some Console functions. If you don't know what the Newton-Raphson …

0
3K
Member Avatar for zinnqu

Using the Load and Unload events of the Forms add these subs to handle a simple fade in and out effect. This is not limited to just one form. The subroutine definition can be added to any global class allowing the use on any form or sub-form. This is the …

Member Avatar for CsharpChico
1
2K
Member Avatar for Xcelled194

One of the things that always irked me about C# is its lack of an InputBox function. In VB, You can simply do [CODE=VBNET]response = InputBox("Enter your name")[/CODE] Unfortunately, there is no C# equivalent. Sure, you can call the VB one, but doesn't that kind of defeat the purpose of …

2
1K
Member Avatar for vegaseat

I am afraid, I am starting to like C#, despite the somewhat bloated .Net Framework requirements. Mister Bill's Microsoft is very supportive though. The language has a nice flow compared to GUI programming in C++. Here we are looking at a standard ListBox, add some items, sort them and select …

Member Avatar for anucom
0
707
Member Avatar for PsychoCoder

The End.