Search This Blog

Monday, September 28, 2015

Choose Visual Basic Example

VB.NET Functions > Choose

Returns a member of the list passed in Choice().
It is based on the value of Index. The first member of the list is selected when Index is 1.

Example

Dim choice = Choose(2, "val1", "val2", "val2") // "val2"





Thursday, September 24, 2015

Appends text to a file C#

C# > Files > File Class > AppendText

Appends text to an existing file or create a new file if the specified file does not exist.

Example

using(System.IO.StreamWriter sw = System.IO.File.AppendText(@"c:\log.txt"))
{
      sw.WriteLine("logline");
}





Tuesday, September 15, 2015

Convert to double TimeSpan C#

C# > System > TimeSpan Structure

TimeSpan represents a time structure.

Examples

1. Convert to double
   
  TimeSpan ts = TimeSpan.FromMinutes(12.45);

  double time = ts.TotalMinutes;





Friday, August 14, 2015

SOUNDEX SQL Server Example

SQL Server > Built-in Functions > SOUNDEX

SOUNDEX converts an alphanumeric string to a four-character code that is based on how the string sounds when spoken. 

Example


SELECT SOUNDEX ('Jan'), SOUNDEX ('Jane');

Result:
(No column name) (No column name)
J500                 J500






TRY_CAST SQL Server Example

SQL Server > Built-in Functions > TRY_CAST

Try to cast a value to the specified data type. 
If the cast not succeeds returns null.

Example


SELECT
    CASE WHEN TRY_CAST('1' AS float) IS NULL
    THEN 'Cast failed'
    ELSE 'Cast succeeded'
END AS Result;

Result
Cast succeeded

SELECT
    CASE WHEN TRY_CAST('xx' AS float) IS NULL
    THEN 'Cast failed'
    ELSE 'Cast succeeded'

END AS Result;

Result
Cast failed





Monday, August 10, 2015

Pow C# Example

C#  > System > Math class > Pow

Pow  number raise a  number to the specified power.

Example:

double pow = Math.Pow(2, 8); // 256




Tuesday, August 4, 2015

Scroll to selected index DataGridView

C# > DataGridViewFirstDisplayedScrollingRowIndex 

Setting this property raises scroll event to match selected index.


Example


dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;