|
Since you've posted so many problems regarding excel I guess you should read this article
http://support.microsoft.com/kb/302084[^]
It has everything you need to know!!
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Hello,
I'm trying to navigate from the middle of the xml page back to the top(to the parent node).
So I can perform another search looking for matches to my random number,
while (xmlReader.Read())
{
xmlReader.MoveToElement();
TempNo = xmlReader.Value;
if (tempNo == Convert.ToString(userID))
{
UserID = RadNo.Next(10, 99);
}
}
The above is my code, hope this help.
Sorry if this is a simple question, I'm totally new to xml and c#
just learning it really...
-JC
|
|
|
|
|
XMLReader is forward only. Use XMLDocument class instead and use XPath to do your search.
|
|
|
|
|
hello i have been looking for this code for a long time
its about how to execute a program like excel or word or any .exe file
from c#
for example i want to make a button that runs winword when its pressed
and thx
|
|
|
|
|
Process.Start, but you need the path to Word, OR you can pass in the path to a word doc, and if Word is present, it will open. If not, it will throw an exception.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
here is a simple application I wrote :
there is a combobox on my form which lets user to select a program.
in this case i just added 3 programs to it : (mediaplayer, freecell, MinesWeeper)
also you can add the command line arguments to your process.
by clicking the run button the fallowing code will run.
private void runbtn_Click(object sender, System.EventArgs e)
{
Process myProcess = new Process();
int selectedIndex = comboBox1.SelectedIndex;
switch (selectedIndex)
{
case 0:
myProcess.StartInfo.FileName = "C:/Program Files/Windows Media Player/wmplayer.exe";
break;
case 1:
myProcess.StartInfo.FileName = "c:/windows/system32/winmine.exe";
break;
case 2:
myProcess.StartInfo.FileName = "c:/windows/system32/freecell.exe";
break;
default:
myProcess.StartInfo.FileName = "C:/Program Files/Windows Media Player/wmplayer.exe";
break;
}
myProcess.Start();
}
sometimes 0 can be 1
modified on Sunday, June 15, 2008 10:26 AM
|
|
|
|
|
Problem Description:
i need to develop an C# app with offical toolkit of Basler linear CCD ,including two dll files.
however, when i call the function "pxd_renderDIB(...)" in the dlls,there is red shifting about the Image in picturebox,meanwhile, the saved Image in disk is normal.
by the way ,the source of Image is RAW image delivered from CCD to the buffer alloced in memory.
how to correct red shift in picturebox?Thanks.
|
|
|
|
|
Sounds like the API is broken, the way you're using it is broken, or the image is broken. I don't think we can hope to help with any of those things, unless someone here has used that SDK. Your best bet is to ask on a forum of people who have the SDK you're using, so they know how to help you.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I use WritePrinter - work, but ReadPrinter return empty
[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true,CallingConvention = CallingConvention.StdCall)]
public static extern long ReadPrinter(IntPtr hPrinter, StringBuilder data, int buf, out int pcRead);
public static int ReadFromPrinter(string szPrinterName, string szString)
{
Int32 dwError = 0, dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
StringBuilder sb = new StringBuilder();
DOCINFOA di = new DOCINFOA();
bool bSuccess = false;
di.pDocName = "My C#.NET RAW Document";
di.pDataType = "RAW";
if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
if (StartDocPrinter(hPrinter, 1, di))
{
if (StartPagePrinter(hPrinter))
{
IntPtr pBytes;
Int32 dwCount;
System.Text.Encoding ascii = System.Text.Encoding.GetEncoding(866);
byte[] myStringInASCII = ascii.GetBytes(szString);
szString = ascii.GetString(myStringInASCII);
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
Marshal.FreeCoTaskMem(pBytes);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
long out1 = ReadPrinter(hPrinter, sb, 6, out dwWritten);
ClosePrinter(hPrinter);
}
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return 1;
}
Where error?
thanks
|
|
|
|
|
Hi
I have developed an SSIS package in Business Intelligence Development studio.
It Works in BI and returns result.
When I attempt to execute the package programmatically from a .net Windows
Form application the follow DtsError is returned:
"The product level is insufficient for component \"Fuzzy Lookup\" (497).\r\n"
Can anyone Help me?
Thanks and regards
Sri
|
|
|
|
|
I've gotten used to writing static classes. Today I was thinking of making one of my classes static, but couldn't because I also need to be able to derive from it. So I wanted to find a way of making it derivable but non-instantiatable.
Hmmm... I suppose I could give it a private constructor... oh, yeah, that's what we had to do waaaay back in .net 1
Well I just tried it, and found that the base class' constructor has to be (at least) protected (of course).
So I'm thinking of having it protected, but throw an Exception if it's ever called.
Clarification: I want to be able to derive, but the base class and all derivations must be singletons.
Does anyone else have a way of doing this?
Update: I just tried marking the base class' constructor as Obsolete; that also hinders derivation.
modified on Saturday, June 14, 2008 11:33 AM
|
|
|
|
|
If you make methods 'protected static' (or public static), you can derrive the method, and call it statically.
If you mark the class that it's declared in abstract it will be non-instiatable.
Cheers,
|
|
|
|
|
Right, the fields and methods will be static.
But I think if I make it abstract I still need to make sure that derived classes are also non-instantiatable.
|
|
|
|
|
Hmm I see your point.
I've never found myself in a position where I need to do what your describing, so I can't really help.
I'm sure there is someone in this forum, who knows inheritance like the back of their hand, that can help you though.
Cheers,
|
|
|
|
|
And why cant they have private constructors?
A better solution would be to do something like this:
<font color="Blue">public</font> <font color="Blue">abstract</font> <font color="Blue">class</font> <font color="Teal">MyBase</font>
<font color="DarkBlue">{</font>
<font color="Blue">public</font> <font color="Blue">static</font> <font color="Blue">object</font> FactorMethods<font color="DarkBlue">(</font><font color="DarkBlue">)</font>
<font color="DarkBlue">.</font><font color="DarkBlue">.</font><font color="DarkBlue">.</font>
<font color="DarkGreen">
<font color="Teal">MyBase</font><font color="DarkBlue">(</font><font color="DarkBlue">)</font> <font color="DarkBlue">{</font><font color="DarkBlue">}</font>
<font color="Blue">abstract</font> <font color="Blue">void</font> Bar<font color="DarkBlue">(</font><font color="DarkBlue">)</font>
<font color="DarkBlue">.</font><font color="DarkBlue">.</font><font color="DarkBlue">.</font>
<font color="DarkGreen">
<font color="DarkGreen">
<font color="Blue">class</font> Foo <font color="DarkBlue">:</font> <font color="Teal">MyBase</font>
<font color="DarkBlue">{</font>
<font color="Blue">override</font> <font color="Blue">void</font> Bar<font color="DarkBlue">()</font>
<font color="DarkBlue">}</font>
<font color="Blue">class</font> <font color="Teal">Oof</font> <font color="DarkBlue">:</font> <font color="Teal">MyBase</font>
<font color="DarkBlue">{</font>
<font color="Blue">override</font> <font color="Blue">void</font> Bar<font color="DarkBlue">(</font><font color="DarkBlue">)</font>
<font color="DarkBlue">}</font>
<font color="DarkBlue">}</font>
|
|
|
|
|
I need to derive outside the class and allow others to derive as well.
And the derived classes shouldn't be instantiateable either.
|
|
|
|
|
I don't think there's an (easy or good) way to do what you're asking. My initial impression is that you're going completely the wrong way about this. My first question is "why?" and second is have you thought about using something like a singleton object? You'll have greater control over what you can do with the class that way.
I still don't get why you'd need to do this though.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Ed.Poore wrote: singleton
Right, and usually static classes are used for that (in C#), but statics also can't be derived from. I need to be able to derive, but each derived type also needs to be a singleton. Just using abstract won't accomplish that either.
Ed.Poore wrote: I still don't get why you'd need to do this though.
So derived types can add or override methods.
This is all working with non-singleton classes currently, but because there's no need to allow multiple copies, it makes sense to disallow them.
Static generic classes are kinda like this. And indeed this involves generics, but in some cases I want to "override" a method when I use a particular generic parameter.
|
|
|
|
|
PIEBALDconsult wrote: usually static classes are used for that (in C#),
Are you sure? The method I've come across is having a "normal" class but with a private constructor. There's then a single static reference to an instance of that class. Such as this article[^].
Does that make it any easier? I don't see anyway of making a class non-instatiable though, you might be able to do it with some mad reflection & stack calls but my concern is, is it worth the effort?
If there are only a few developers on it, just add some documentation and say the behaviour is undefined. If there are more (e.g. part of a library) then just document it.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Ed.Poore wrote: Are you sure?
With .net 2 and later, yes, but it also depends on how lazy you want the singleton to be, I usually don't need much laziness.
Ed.Poore wrote: with a private constructor
But in order to derive, the constructor must be at least protected because the derived class needs access to it (at least in the current framework). That would allow the derived class to be a non-singleton, which I don't want to allow.
Ed.Poore wrote: part of a library
Right, and I'm likely going to write an article on the class.
|
|
|
|
|
Just a thought: is this possible in C++? If it's not then I'm guessing it's going to be "impossible" to do in C#. Would you be able to provide more details as to the implementation surrounding this, i.e. how you intend to use it, so I can get a better idea of what you're trying to accomplish? I still think there's probably a better design method but can't be sure until I know more.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
Ed.Poore wrote: is this possible in C++?
As if I'd know. I only dabbled in C++, I've spent most of my career (so far) in C, I only started doing C# because the only OpenVMS jobs I saw used COBOL.
Ed.Poore wrote: more details
Yeah, I'll work up a little example of what I have so far.
|
|
|
|
|
PIEBALDconsult wrote: Yeah, I'll work up a little example of what I have so far.
Yeah that'll help quite a bit.
PIEBALDconsult wrote: As if I'd know.
Well I'd probably know less, again only dabbling. Mainly C# but a bit of VB6 and quite a lot of C depending on the projects.
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|
|
I can't think of any simpler examples so I'll just describe what I'm doing.
I'm writing a generic pool. Each item in the pool gets wrapped and added to a HashSet. The class is therefore a factory of these items as well. So, because it's a factory and there shouldn't be more than one pool of a given type in the appdomain, making the class a singleton seems appropriate.
public class GenericPool<T>
where T : class , new()
{
private sealed class GenericPoolItem : IGenericPoolItem<T>
{
private T item = new T() ;
}
private static readonly System.Collections.Generic.HashSet<GenericPoolItem> items =
new System.Collections.Generic.HashSet<GenericPoolItem>() ;
private static readonly System.Collections.Generic.List<GenericPoolItem> freelist =
new System.Collections.Generic.List<GenericPoolItem>() ;
public static IGenericPoolItem<T>
Reserve
{
get
{
GenericPoolItem result = null ;
lock ( items )
{
if ( freelist.Count == 0 )
{
result = new GenericPoolItem() ;
items.Add ( result ) ;
}
else
{
result = freelist [ 0 ] ;
freelist.RemoveAt ( 0 ) ;
}
}
result.Reserve() ;
return ( result ) ;
}
}
}
There is also an interface to expose only two members of the wrapper; Value and Free.
To use the class(es), one need only call Reserve, use the wrapped item, and then Free the wrapped item.
IGenericPoolItem<Widget> item = GenericPool<Widget>.Reserve ;
item.Free() ;
(I'll likely rename Reserve or change it to a method; it looks wrong as it is.)
For that I could use a static class, but as mentioned, I want to be able to derive.
Why? Well, one of the particular types I want to pool is StringBuilder (I still have yet to determine whether or not there's any performance benefit of that).
In the above snippet, Widget could be StringBuilder and it will work just fine except I would need to clear the StringBuilder each time I Reserve it. If I derive, I can override (kinda sorta) Reserve to perform the clearing.
public class StringBuilderPool : PIEBALD.Types.GenericPool<System.Text.StringBuilder>
{
public new static PIEBALD.Types.IGenericPoolItem<System.Text.StringBuilder>
Reserve
{
get
{
PIEBALD.Types.IGenericPoolItem<System.Text.StringBuilder> result =
PIEBALD.Types.GenericPool<System.Text.StringBuilder>.Reserve ;
result.Value.Length = 0 ;
return ( result ) ;
}
}
}
The classes work as I want. But in order to derive, the base class can't have a private constructor (which is usual for a singleton), the deriving class needs access to the base class' constructor, so I make it protected. But a deriving class could make its constructor public, undoing my efforts.
My solution is to have the constructor throw an exception:
protected GenericPool
(
)
{
throw ( new System.InvalidOperationException
( "Instantiating GenericPool is forbidden." ) ) ;
}
but I would prefer a compile-time error or something less heavy-handed.
I could, of course, just let people instantiate it, but the instances would be fairly useless without instance members... always remembering that probably no one else will use this anyway.
|
|
|
|
|
PIEBALDconsult wrote: always remembering that probably no one else will use this anyway.
In that instance I think you're probably overcomplicating things
How about moving the Reserve method to the GenericPoolItem , or rather provide the common stuff inside the container class and then provide the option to perform additional operations. For example if you do something like the following:
public static IGenericPoolItem<T> Reserve<T>()
{
if (T is ICustomReserve)
{
((ICustomReserve)default(T)).Reserve();
}
} Thus if you want to provide additional reserving you create a "wrapper" item and provide the implementation from there. Note the code would probably need rethinking but perhaps it provides some food for thought?
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
|
|
|
|