Windows Phone Developers

Friday, January 16, 2009

No overload for method 'get_Range' takes '1' arguments

No overload for method 'get_Range' takes '1' arguments is error encountered by VB programmers trying to code in C#.

Excel.Workbook oWB = oXL.Workbooks.Open(sXLFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing,missing );

// processing

Excel.Worksheet oWS = (Excel.Worksheet)oWB.Worksheets[1];

oWS.get_Range("A1").Value2 = "No";

This occurs when get_Range method is supplied with only one argument. Instead use any of the following:

oWS.get_Range("A1","A1").Value2 = "No";

or

Object missing = System.Type.Missing;

oWS.get_Range("A1",missing ).Value2 = "No";




Error Dialog
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Non-invocable member 'Microsoft.Office.Interop.Excel._Workbook.Worksheets' cannot be used like a method.

Non-invocable member 'Microsoft.Office.Interop.Excel._Workbook.Worksheets' cannot be used like a method is a common error for a VB programmer working on C# projects. The error is solved when the round brackets are replaced with square ones

Excel.Worksheet oWS = (Excel.Worksheet)oWB.Worksheets(1);

To

Excel.Worksheet oWS = (Excel.Worksheet)oWB.Worksheets[1];


Error Message
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. An explicit conversion exists (are you missing a cast?)

Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. An explicit conversion exists (are you missing a cast?) throws up when there is no Explicit casting - (Excel.Worksheet)

Excel.Worksheet oWS =oWB.Worksheets[1];

To

Excel.Worksheet oWS = (Excel.Worksheet)oWB.Worksheets[1];


Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Saturday, January 10, 2009

How to use Multithreading in C# Console Application

C# Multithreading Example – Continuous Alert

A query from our good blog friend SnakyJake led me to code a small multithreading stuff. The following example will torment the user with beeps till he/she inputs some value.

First let us create a small class that will handle the beeps

public class ClassBeep

{

private volatile bool EnoughBeeping;

public void StartBeeping()

{

while (!EnoughBeeping)

{

Console.Beep();

}

}

public void StopBeeping()

{

EnoughBeeping = true;

}

}

ClassBeep has two public methods, one to start beeping (and continuing) with it and another to stop the beep.

We also have a volatile variable EnoughBeeping which sets/resets the Beeps

This is quite simple. Isn’t it.

The next step is to code the main function to get the user input.

Wait a minute … here are the directives

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

The last one “System.Threading” is the one we have added to the default directives.

Let us create an object for our Beep class

ClassBeep CBeep = new ClassBeep();

and create a thread and attach the function to it

Thread CBeepThread = new Thread(CBeep.StartBeeping);

We can now start the additional thread (worker thread)

CBeepThread.Start();

while (!CBeepThread.IsAlive) ;

Beep starts …

Now we can provide some instructions to the main thread

Thread.Sleep(1);

Console.WriteLine("Please enter the name");

string sText = Console.ReadLine();

int iLen = 0;

iLen = sText.Length;

while (iLen == 0)

{

sText = Console.ReadLine();

iLen = sText.Length;

}

The above loop will be executed till the user inputs a value.

Once the execution comes out of the loop, let us stop the beep and join the worker thread with the main one

CBeep.StopBeeping();

CBeepThread.Join();

Here is the full code of the main module

static void Main(string[] args)

{

ClassBeep CBeep = new ClassBeep();

Thread CBeepThread = new Thread(CBeep.StartBeeping);

CBeepThread.Start();

while (!CBeepThread.IsAlive) ;

Thread.Sleep(1);

Console.WriteLine("Please enter the name");

string sText = Console.ReadLine();

int iLen = 0;

iLen = sText.Length;

while (iLen == 0)

{

sText = Console.ReadLine();

iLen = sText.Length;

}

CBeep.StopBeeping();

CBeepThread.Join();

Console.WriteLine("Welcome {0}", sText);

}

Try it out. You can try overload of Beep Function to make your user have soothing and rhyming beeps as background.

Hope you get things done through beepsJ

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Beep in C# Windows forms

Alert user with beep sound for invalid entries using C#

Many times when we alert the user with some messages but the user doesn’t heed immediately. A combination of sound and popup should be more helpful. The following example would alert the user if he/she hasn’t input the required field

private void buttonOK_Click(object sender, EventArgs e)

{

if (txtExcelFile.Text.Length == 0)

{

System.Console.Beep();

MessageBox.Show ("Select the file and continue...");

}

}



Windows User Form

For a Rhyming Beep peep at http://dotnetdud.blogspot.com/2009/01/how-to-create-rhyming-beeps-in-c.html Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

How to create Rhyming Beeps in C#

How to compose a tune using C#

Beep method is a simple instrument to create some wonderful tunes. I love music, but haven’t practiced or played. Hence I will stop posting the overloaded Beep function that can be ‘tuned’ for your use

Overloaded Console.Beep method takes two arguments

Console.Beep(int32 frequency, int32 duration)

Here is a way to do it

private static void RhymingBeeps()

{

int duration = 1000;

for (int i = 1500; i <= 2000; i = i +50)

{

Console.Beep(i, duration);

duration = duration / 2;

if (duration <>

{

duration = 1000;

}

}

}

Agreed! It is not that Rhyming. But post you are welcomed to post the rhyming ones here

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

Wednesday, January 7, 2009

Check if a String has Value using IsNullOrEmpty method

Check if a String has Value using IsNullOrEmpty method

IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is nullNothingnullptra null reference (Nothing in Visual Basic) or its value is Empty.

Unlike the usual way to check twice (once for null and next for empty string), this method does it in a single check

private void CheckValue()

{

String s1 = null ;

String s2 = "";

if (String.IsNullOrEmpty(s1) == true)

{

MessageBox.Show("String does not hold any text");

}

}

This method actually checks if the Value is null or if the length of the string is Zero.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon