Answer Questions
mdrelyea C# and Preprocessor macro
hello, i'm a newbie with C# and i'd like to Preprocessor macro like I do with my C compiler how can I do that is it possible example #define STEP1 0x01 #define STEP2 0x02 void Function(int Choice) { switch(Choice) { case STEP1 : break; case STEP2: break; } } You cannot use an #define for that. However, consts will work. const int STEP1 = 0x01; const int STEP2 = 0x02; (the rest is the same) James Curran wrote: You cannot use an #define for that. However, consts will work. const int STEP1 = 0x01; const int STEP2 = 0x02; (the rest is the same) The C# preprocessor simply allow you to perform "conditional compiling". Using consts is much more ...Show All
george maina Dynamically accessing objects on a form
I have 12 buttons placed on a form simplye named as button1, button2, ...,button12. I want to change their properties in a loop. Is there any means of possibilities that I might reach their properties in such manner or somewhat alike in a single loop for (i=1;i<=12;i++) { button+tostring(i).visible=false; } hmmm interesting as I am able to compile and run it fine. I did notice however the 2 brackets () were missed out in the GetType part. The O in typeof was lowered, again its best if you look at the Intellisense and make sure that the case sensitivity/keyword matches foreach(Control curControl in this.Controls) { if (currentControl.GetType () == typeof(Button)) { //current control IS a b ...Show All
Aamir Iqbal Is it possible to invoke a generic static class mthod through reflection.
Hi all, I have the following scenario. I have a generic static class. Is there a way for me to invoke something like that using reflection. For example. I have a static class with a method. MyClass<T>.Show() The item being shown depends on T. Can I invoke such a method using reflection I have the string (MyClass<MyType>) given to me, but I cannot create an instance of that using reflection (since MyClass is a static class). Any help is appreciated. Thanks ahead. David Hi David. You can simply pass the generic type specifier to the typeof() call, then call InvokeMember as normal on the returned type, thusly: using System; using System.Collections ...Show All
John.Doe error CS0029:Cannot implicitly convert type 'int' to 'bool'
while ((System.Convert.ToInt32(strupcolid)!=0)); where is the problem What type is strupcolid Are you sure that's the line that's causing your problem That particular line of code should compile just fine assuming strupcolid is a string. Regards, Donavan Hoepcke >> for (int j=arrcolid.Length-1;j=0;j--) Well, that's easy. j=0 is an assignment, which evaluates to 0 (int) j==0 is a comparison, which evaluate to t/f (bool) James, thks! = and ==, haha, I am too careless to mind the difference. thks again! I don't know what you are doing wrong, but the following code does NOT generate the error for me: static void Main( string [] args) { ...Show All
Phantom_PF Make stand alone exe
I posted this in one of the visual studio 2005 forums and someone suggested I try posting it here. In Visual Studio 2005 is there any way to actually make just a standalone exe file, like in visual studio 6.0 where you just go to Build or Make EXE or something similar All I can find is the publishing section which creates a setup.exe which then "installs" the program and checks for updates etc. I just want to make one exe file that can be run from any PC anywhere that you just double click and away it goes, straight into your program, in visual studio 6.0 this was no problem at all yet I have spent hours searching and am still unable to do this in VS 2005. Thanks it's not really a high priority as Windows is not built ...Show All
NehaRahul using lock statement to synchronise static variable access
Hi, I am using framework 1.1 I have a static volatile bool variable in a class Globals public class Globals { static volatile bool _bDoLiveUpdate; public static bool DoLiveUpdate { get{return _bDoLiveUpdate;} set{_bDoLiveUpdate = value;} } } I have 2 more classes, one of which runs on a separate thread. Both these classes access the property Globals.DoLiveUpdate to perform certain functionality. How can I synchronise access to Globals.DoLiveUpdate by following two classes using lock Please note that the property Globals.DoLiveUpdate and variable _bDoLiveUpdate are both static while the class Globals is not declared static. public Class ClassSameThread { MyFunc() { Globals.DoLiveUpdate = false; // Do Something Globals.DoLiveUpdate = true; ...Show All
Dee-roc Passing parameters in C#
Hello Members, I am trying to call a sql function in C# ,it work fine when I call for SqlCommand cmd = new SqlCommand("SELECT dbo.Calc(1, 18, 4) as totalCost ",cnn); But when I try to so the same with calling parameters it doesn't show the result. e.g SqlCommand cmd = new SqlCommand("SELECT dbo.Calc(Par1,Par2,Par3) as totalCost ",cnn); Any answers Two options: 1.- SqlCommand cmd = new SqlCommand ( "SELECT dbo.Calc(" + par1 + "," + par2 + "," + par3 + ") AS TotalCost" , cnn); 2.- SqlCommand cmd = new SqlCommand ( "SELECT dbo.Calc(@par1, @par2, @par3) AS TotalCost" , cnn); cmd.Parameters.Add( "@pa ...Show All
SCRunner Barcode Scanner
Please help me with code for interfacing to a barcode scanner on a ASP.NET webpage using C#. Regards What are you trying to do A barcode scanner is simply an input device as is a keyboard, or a magnetic stripe reader. A barcode scanner simply reads a barcode, then streams a series of input characters to the computer as input. You need to design your forms to accept data in such a way such that your fields are long enough to handle the length of the barcode(s) being read, and perhaps some code to automatically focus the cursor in an input field when a page is loaded, but other than that, it's just standard web page programming. Tryst - how would you use the Scanning API in a web application I would have thought that t ...Show All
imranmbukhari copying a windows folder structure to sql server
Has any one coded some thing that copies a windows root folder structure to sql server Thanks a lot Where abouts in sharepoint do you want to put it (list, each folder=node,...), and for what purpose Ross The user will enter a folder path, then I will create a master site for my documents, then for each sub folder in the provided path, i will create a site inside my master site. Then each subfolder again will be associated to a document library in the site. Then in the document library I will need to upload all the files of the subfolder. that will be done for each subfolder. So the structure will be like this: provided explorer root folder rootFolder path will be associated to a master site masterSite Each Fo ...Show All
ONEWORKNGRL Calling C# DLL from a Java application (or even another C++ or VB app)
I have a C# DLL that needs to be called from a Java application. I suspect that this can't be done directly, but perhaps through a JNI wrapper to a C++ DLL which in turn calls the C# DLL I am looking for an answer that provides the simplest of examples that I can compile and test. (e.g. a C# class with a simple method that inputs one string and returns another....and those inputs and outputs are passed down and up through the layers). Do we need COM involved in this If so, how You can also test Add-In for VS2003, which generates Java wrappers in managed JNI code (MCpp, C#, J#, VB) and in unmanaged JNI code (C++): http://www.simtel.net/product.php[id]98493[sekid]0[SiteID]simtel.net ...Show All
Peter Doss Calling methods across classes
How can I call methods in my main Form class from another class (that is in the same namespace). Basically I have a method in my main program class that writes to a multiline textarea. I want some functions in another class to be able to call that textarea method in the main program class. Is this possible Yes, but first you need to do 2 things: The calling class needs a reference to your main form You need to expose a method or property on your main form to allow the text to be written Is there any reason you can't put them in your form class, or call them from your form class czell wrote: How can I expose the method Im kinda new to c# When I say "expose a method" I mea ...Show All
T.S.SRIRAM overloading == operator in c# fails checking for null values
Hi, I have developed one class called CProductInfo providing == and != operator features. I have one problem. When I use this class in my program, say CProductInfo product = null; and later, when i check for emptiness, if (product==null) it returns false as if the product instance is not empty. I tried various ways to eliminate this run-time error, but it just does not happen. Also I don't think there is use full tips on net for this. Can someone help Thanks in advance - Constantine <<<< THE BRIEF SOURCE CODE FOR CProductInfo IS BELOW >>>>> using System; using System.Data; using System.Data.SqlClient; using MyDataLibrary; namespace ProductManager2006 { public ...Show All
Rishab Create program to run before windows startup -- Floppy Disk?
Can I create a program to run before windows starts up, like when you insert a floppy disk before startup, you can, say, erase your harddrive Thanks, Not in C# as it requires the .NET Framework which requires Windows. In theory you could strip down a CLR such as Mono or Rotor... however making it that small might take a fair bit of work. ...Show All
J-Pixel Translucent Image
I would like to know how to determine the color of a translucent image when it is on top of another image. To better explain it, for example, let say I have 2 images A and B and B is a translucent image and is on top of A. I would like to know the RGB values of the overlapping area of image B. I know I can use GDI+ to create translucent images and it will do the rest for me. But that's not what I want, I would like to know the way to determine the color. Thanks in advance. You need to Call GetPixel(int x, int y) method on a Bitmap to get the color at a specific X and Y coordinates, See Here: Bitmap myBitmap = new Bitmap("hello.jpg"); Color pixelColor = myBitmap.GetPixel(2, 2); pixe ...Show All
Peter Peter Executing Exe
Ok i added a exe file to my solutions explorer and i wanted to know what code i needed to execute the exe in my form 1 using System.Diagnostics; Process proc = new Process(); proc.StartInfo.FileName = "app.exe"; proc.Start(); For more details search the MSDN for Process class. It should be as simple as: System.Diagnostics. Process process = new System.Diagnostics. Process (); process.StartInfo.FileName = "Full Path to EXE"; process.Start(); You call it like this: RunEmbededExe("unpackedXBOXv2.exe"); You have to copy the unpackedXBOXv2.exe into the bin\Debug folder, next to Theme3.exe! i was reading up on it ...Show All
