|
Muhammad Zeeshan wrote: I have come to CP after searching Google
That's great, that you looked somewhere first.
Muhammad Zeeshan wrote: ur answer is not helpful in any way
Actually, it's very helpful. Pointing out to you that we have an ASP.NET forum ( which you still haven't found, I just answered this in the web dev forum ), means that
a - you don't clutter our forums with off topic questions, and
b - you ask in a place where people who can help you, will look.
Which just means you get an answer faster. Sorry if you don't think that will help you at all.
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 )
|
|
|
|
|
oh yes thks sorry for being rude. new to CP now definitly will find right forums to put questions thanks for ur kind help.
|
|
|
|
|
Glad to help
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 )
|
|
|
|
|
Hi
I recieve this exception:
"Only one usage of each socket address (protocol/network address/port) is normally permitted"
I should get several files from an ftp server. I implemented it by sockets so: create the datasocket, recieve the file and then close data socket. But the next time I do this for another file(create data socket with Endpoint (the same local address/another port)), i recieve this exception message when Binding the socket. Can anyone tell me why? And the way to solve that?
(the code, if necessary)
public void download(string remFileName, string locFileName)
{
if (!logined)
{
login();
}
setBinaryMode(true);
Console.WriteLine("Downloading file " + remFileName + " from " + remoteHost + "/" + remotePath);
if (locFileName.Equals(""))
{
locFileName = remFileName;
}
if (!File.Exists(locFileName))
{
Stream st = File.Create(locFileName);
st.Close();
}
FileStream output = new FileStream(locFileName, FileMode.Open);
createDataSocket(true);
if (dataSocket != null)
{
throw new SocketException();
}
sendCommand("RETR " + remFileName);
if (!(retValue == 150 || retValue == 125))
{
throw new IOException(reply.Substring(4));
}
dataSocket = listeningSocket.Accept();
listeningSocket.Close();
listeningSocket = null;
if (dataSocket == null)
{
throw new Exception("Winsock error: " +
Convert.ToString(System.Runtime.InteropServices.Marshal.GetLastWin32Error()));
}
while (true)
{
bytes = dataSocket.Receive(buffer, buffer.Length, 0);
output.Write(buffer, 0, bytes);
if (bytes <= 0)
{
break;
}
}
output.Close();
if (dataSocket.Connected)
{
dataSocket.Close();
dataSocket = null;
}
Console.WriteLine("");
readReply();
if (!(retValue == 226 || retValue == 250))
{
throw new IOException(reply.Substring(4));
}
}
public void createDataSocket(bool flag)
{
try
{
listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
catch (Exception e)
{
ftpLog(e.Message);
throw new IOException(e.Message);
}
string localAddress = clientSocket.LocalEndPoint.ToString();
int ix = localAddress.IndexOf(':');
if (ix < 0)
throw new Exception("local IP ERROR");
string localIP = localAddress.Substring(0, ix);
IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(localIP), localDataPort);
try
{
<big>listeningSocket.Bind(localEP);</big>
listeningSocket.Listen(1);
}
catch (SocketException se)
{
ftpLog(se.Message);
throw new IOException(se.Message);
}
localIP = localIP.Replace('.', ',');
string portCMD = string.Format("PORT {0},{1},{2}", localIP, localDataPort / 256, localDataPort % 256);
localDataPort++;
sendCommand(portCMD);
if(retValue!=200)
throw new IOException(reply.Substring(4));
}
|
|
|
|
|
Hi Guys. I have been busy with an Application that writes data to Excel. Now, I have successfully written the application and now I need to make some changes/enhancements. Problem is that I am unsure on how to do the following: Below a snippet of the data in Excel.
Discl Level Level 1 Level 2
1 378600
2 350000
2 28600
1 50000
2 50000
I have a disclosure Level which is the 1's and 2's on the left.
I have to somehow calculate all the Level2 totals and ensure that they balance to the Level1 balance. If there is an imblance then I need to write this into an adjacent cell to level2 on the same line as the level1. I'm not sure how to do that. I have now been searching a number of websites for a few days now and can't find anything that explains how to do this.
The other problem is that I don't know where the level 1 and level2 starts so I need to somehow be able to determine this as well.
If anybody can help with this I would greatly appreciate this or if you have a website that explains this please please let me know.
Cheers
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
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.
|
|
|
|