|
I would recommend using Int32.TryParse (if you don't want to use Int32.Parse with a try/catch block). That's how I'd do it.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
TryParse is only available in 2.0 (OP didn't specify whether which version they are using).
Since you're only dealing with single characters, the way I'd do it is to use char.IsDigit and char.IsApha to determine if you're dealing an integer or a character, then do the appropriate conversion.
-----
In the land of the blind, the one eyed man is king.
-- modified at 17:01 Friday 19th May, 2006
|
|
|
|
|
The simplest form of the code.
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string PrintXML()
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
return "Success";
}
}
Hello world works ok.
PrintXML fails with an exception of the form:
System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at Service.PrintXML()
Can anyone give me hints on what to do with this?
I've tried using attribute [STAThread] to make the method single threaded but it seems to be getting ignored.
I'm at a loss as to how to instantiate a browser control in a web service. I need to do this so I can send HTML to a printer on the same box as the web service that runs.
thanks!
|
|
|
|
|
Well, AFAIK, IIS doesn't run in single-threaded apartment. You'll have to create another application that can run in single-threaded apartment and make a remoting call to it. For instance, try writing a console app or windows service and have your web method call that. I was wondering if you could create a new AppDomain with a different apartment threading model, but it doesn't look like that's possible.
www.logifusion.com
|
|
|
|
|
That sounds like a workable idea but I dont know how to make a call on an external app from a web service (or from any other windows code for that matter) I'm from linux/java/c and doing these things in windows, I just dont know how yet.
Anyone shed any light on how to make a call out to an external app from a web service?
Thanks!
|
|
|
|
|
|
C# novice - seeking feedback on the proper way to code a break report.
If you had two cvs files and needed to create a break report: (i.e. records in a but not in b, in b but not in a, in a and in b but mis-matched on data, how would you approach it?
I'm planning on loadeing the data into two DataTables, a and b, I've defined within the code, and looping as follows:
foreach (row in a)
find row.key in b
--if not found, copy source row into a-not-b table
--if found, compare
--- if not matching, copy rows and break info into data-break table
--- either way, if found, remove matched row from b table
end foreach
report a-not-b
report b (any remaining rows represent b-not-a)
and data-break
I'm concerned that I don't know the .Net language well enough, and I might be going about this the wrong way. Are there better choices in loading the data that provide 'set-operations' that I can use, to make this process cleaner?
Thanks!
Pauli
|
|
|
|
|
|
hello,
i am attempting to create a program using windows forms. there is a MDIParent form with several children. i have programmatically set the size of the child forms in the constructor, but for some reason they are popping up the wrong size. this is also happening with several controls that i've created. i have no idea why this keeps happening. can anyone help?
thanks!
rc
|
|
|
|
|
IIRC you need to set the FormStartupPosition property to Manual . You need to set both the Location and Size in parent coords.
|
|
|
|
|
Hello
I'm pretty new for the most part to programming in C# and I'm attempting to do something that I haven't been able to locate a solution for. Any help would be appreciated.
I have a text file with data in it that looks kind of like this:
BHG0002304050
BHG9459895944
BHG94859489568
I was able to write a snippet of code that would read that information into a string array so it looked like this:
Array[1] = BHG0002304050
Array[2] = BHG9459895944
Array[3] = BHG94859489568
However, I now want to separate each character within the array into it's own array... so it would look like this:
array1[1] = B
array1[2] = H
array1[3] = G
array1[4] = 0
etc.
I'm not sure I'm doing this the correct way so any help would be appreciated. If you have any suggestions on how to do this a different way then I'm explaining it I'm very open to ideas.
The reason for this is I will be using each of these characters in this datafile into a mathematical formula, each line represents a math formula... so I need to keep each line separate but I need to pull each character from each line if that makes sense.
thanks!
|
|
|
|
|
string[] t = reader.ReadToEnd().Split('\n');
char[][] all = new char[t.Length][];
for (int i = 0; i < t.Length; i++)
{
t[i] = t[i].Trim('\r');
all[i] = t[i].ToCharArray();
}
|
|
|
|
|
Thanks for the quick response.
This example really helped me get it figured it.
-- modified at 15:34 Friday 19th May, 2006
|
|
|
|
|
You can access the chars of each string directly:
Array[1].Chars[0] = B
Array[2].Chars[3] = 9
etc.
Scott
|
|
|
|
|
please help!
i am working in a c# GDI+ application but i got a problem in producing a pure flickering free screen, i am drawing on a panel and am using the following way to double the buffer but no use!
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
{<br />
Graphics g = e.Graphics;<br />
<br />
<br />
Graphics g = this.panel1.CreateGraphics();<br />
offScreenBitmap = new Bitmap(this.panel1.Width,this.panel1.Height);<br />
Graphics g2 = Graphics.FromImage(offScreenBitmap);<br />
Brush b = new SolidBrush(this.panel1.BackColor);<br />
<br />
g2.FillRectangle(b, new Rectangle(this.panel1.Location,this.panel1.Size));<br />
g2.SmoothingMode=SmoothingMode.AntiAlias;<br />
flowChart1.Draw(g2);<br />
<br />
g.DrawImage(offScreenBitmap, new Point(0,0));<br />
g2.Dispose();<br />
b.Dispose();<br />
<br />
}
but i still have flickering screen, where is the problem?
and i am trying the the following code to double the buffer
SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
SetStyle(ControlStyles.DoubleBuffer, true);<br />
SetStyle(ControlStyles.UserPaint, true);<br />
SetStyle(ControlStyles.ResizeRedraw, true);
but dose't work!
reply asap please!!
|
|
|
|
|
See-S wrote: Graphics g = this.panel1.CreateGraphics();
You should not have to Create the graphics. Rather handle the Paint event seperately.
|
|
|
|
|
You aren't using the Graphics object attached to the Panel's off-screen buffer because you're calling CreateGraphics() on the Panel. Use e.Graphics instead.
Josh
|
|
|
|
|
thanks leppie and Josh!
i see, but again it doesn't work.
but now i substituted a pictureBox for the panel and itworks well!
thanx
|
|
|
|
|
There is the thing: I need to create a Vitrual Drive wich is mapped into a file (an XML one).
This file needs to simulate a tree stucture from the disk.
Is there a .Net way to do this?
... Just asking
www.brusella.com.ar[^]
|
|
|
|
|
Gonzalo Brusella wrote: Is there a .Net way to do this?
No.
You can however make a container file, and a viewer for it, but this wont be viewable by Windows itself.
|
|
|
|
|
The only way is with IoCreateDevice and with C++??
Hmmmm... A LONG work waits me....
|
|
|
|
|
Gonzalo Brusella wrote: Hmmmm... A LONG work waits me....
I think so.
A while ago I tried the same, knowing already that it's not possible to do it in .NET, and since I'm not used to "classic" Win32 APIs, I simply gave up.
Anyway if you're going to do it, we'll all appreciate an article on that topic here at CP.
______________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA] and the ScrewTurn Software experiment
|
|
|
|
|
Thanks to everyone who helped with my previous question. I soon realized, however, that what I really need to do is to be able to cast the type, such as:
- This code is hypothetical, as to not complicate things further, but the real object in the program I am working on is a crystal report, but I want the viewer to work with any crystal report without having to hard code the viewer each time I create a new report. But if someone was able to answer this question, I could take it from there.
object SomeFunction ()<br />
{<br />
return UnknownObject;<br />
}
Now, while I dont know exactly what type UnknownObject is, I am sure no matter what it has a method called, lets say, ClearNum() - ya, kind of stupid, but Im trying to keep it simple to try to avoid getting an overcomplicated answer.
So lets say I want to ClearNum() on the object regardless of what type of object it is.
How can I accomplish the following:
void OnFormClose ()<br />
{<br />
object o = SomeFunction();<br />
((o.GetType())o).ClearNum();
}
Thanks if anyone knows the answer It would help me be a much better programmer.
|
|
|
|
|
If the UnknownObject always has ClearNum() then it is likely that all objects returned by the SomeFunction might implement some interface or derive from a common base class. If so, you can catch the return value as that type and go from there. Else, use reflection to call ClearNum via a dynamic method invocation.
Josh
|
|
|
|
|
Thanks so much, It never occurred to me that I could use methods from the common base class once a new class was derived from it - that was a big help!
|
|
|
|