|
The easiest way is to use "output parameters".
The cleaner way might be to define a class with two parameters, then return an instance of that class from your method.
|
|
|
|
|
Discussion: Would you use static member variables in the class? Why or why not?
|
|
|
|
|
Hi,
I've got a problem with reading in an xml file into a listbox
This is the code:
XmlDocument xmlDoc = new XmlDocument();
XmlTextReader xtr = new XmlTextReader(path);
xtr.WhitespaceHandling = WhitespaceHandling.None;
xmlDoc.Load(path);
while (xtr.Read())
{
if (xtr.Name.Equals("test") && xtr.NodeType == XmlNodeType.Element)
{
this.listBox.Items.Add( xtr.ReadElementString("test").ToString());
}
Thread.Sleep(10);
}
This is the xml files content:
<?xml version="1.0" encoding="UTF-8"?>
<Testing>
<test>1111111</test>
<test>2222222</test>
<test>1111111</test>
<test>3333333</test>
<test>1111111</test>
</Testing>
The problem is, it skips the "222222" and "333333" by not adding them into the listbox.
The rest of the xml file does get loaded in the listbox.
So this is what i get:
1111111
1111111
1111111
In stead of:
1111111
2222222
1111111
3333333
1111111
Can somebody point to me what i am doing wrong?
Thanks in advance!
|
|
|
|
|
If you read the documentation for ReadElementString[^] you will see that it also moves the position in the XML file on. So for each iteration you are moving the position within the file twice.
Yustme wrote: Thread.Sleep(10);
What is this for? It serves no purpose other than to slow down your application. Is that what you really want?
|
|
|
|
|
Hi,
The sleep thread is to avoid that my pc is going to hang. There are over 2000 rows to read into the list box.
Thanks for pointing that out to me. I didn't know it moves 2 positions within the file.
|
|
|
|
|
Yustme wrote: The sleep thread is to avoid that my pc is going to hang. There are over 2000 rows to read into the list box.
That makes no sense what so ever. If you put the thread to sleep for 10 milliseconds 2000 times you are waiting 200 seconds (just over 3 minutes) to load in all the data.
|
|
|
|
|
According to the documentation the ReadElementString method positions the reader on the node following the EndElement node; in you case on the next "test" StartElement node. Afterwards you call Read inside the while statement which advances the reader to the next node and thereby your code only recognizes every second "test" element. I'm not that used to the XmlTextReader, so you have to experiment a bit which method gives you the desired result.
By the way calling ToString on the result of ReadElementString is redundant as it already returns a string.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
Can you tell me what method you used for these kind of operations?
Thanks in advance!
|
|
|
|
|
As said I'm not used to the XmlTextReader but after a quick glance at the documentation I would say that the ReadString method sounds quite promissing.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi,
That did the trick.
Thanks!
|
|
|
|
|
Hi Frens,
I am trying to provide the same kind of search facility which has been given in this link...
http://office.microsoft.com/en-us/default.aspx
But I am not sure how to do this....can u pls help me out..
Thanks in advance...
Vishal
|
|
|
|
|
Which bit are you looking for? The watermark? The UI? Actually searching for something?
Your post is too vague. You need to provide more information before people can answer it.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi all,
I found a code to convert a Image to byte array and back.
the image gets converted to byte array succesfully..
but when i try to convert the bytearray back to Image it gives and error saying
"Parameter is not Valid"
The code is as below:
MemoryStream ms = new MemoryStream(br); // br is the byte array
pictureBox2.Image = Image.FromStream(ms);****Error at this line...
Can anyone tell me how to solve this or some other way to it?
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
I'd expect that means your byte array doesn't contain all the information required to build an image. A byte array of pixel values is not what is needed here.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for quick reply
The problem is it works for some time and then the error occurs...
i have displayed a messagebox. the messagebox is displayed 4-5 times and then the error occurs.
The main purpose of the application is i am capturing images from a camera and sending it over network.
So when i receive it back and try to convert it from a byte array to an image the error occurs.
Can u suggest any better way for this?
or what should be done if the byte array doesn't contains all the information?
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
If it's not all there, there's not much you can do. If it works sometimes, then I guess perhaps sometimes the info is lost, assuming it's being created correctly in the first place.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You aren't saying how you converted it to a byte array to begin with. If the byte array only contains the bitmap's pixel data, it's not going to work. You have to save the full bitmap data, including the header information. You can do this by using Bitmap.Save(), passing in a MemoryStream that points to the byte array.
If you want to create a bitmap from raw pixel data (without a header), you must give GDI+/System.Drawing the information it needs in order to interpret the pixel data. You can create an empty bitmap of the right size and format, and copy the data into it using Bitmap.LockBits() and Buffer.Copy(), or you can create a bitmap that directly uses the byte array as its pixel storage - see my EditableBitmap class[^] for an example.
|
|
|
|
|
i have used the Save method of the image to save that to a memory stream and then used the ToArray method of the memory stream to convert the image to byte array
actually the image is captured from a cam and displayed in a picturebox,
so i cannot use the above mentioned method, coz that will lock the image, is wht i think.
is there any other way to do that?
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Hi,
Ok now this is just weird. i used this line of code everyday and worked fine and suddenly this morning just threw an error in my face
<br />
DateTime dt = Convert.ToDateTime(cpCreateDate.SelectedDate.ToString("dd/MM/yyyy"));<br />
ok the cpCreateDate control is a datetime picker and the value is for example
"09/01/2007 12:00:00 AM"
all i want to do is format it to only the date meaning removing the time to save this to a sql database.
the problem is that as soon as it converts the string back to a datetime value it keeps on adding the time back again and i get this error when trying to write the value to the database:
"The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value.
The statement has been terminated."
the column in the sql database table is a smalldatetime data type and changing that to normal datetime doesnt resolve this.
please help
thanks
|
|
|
|
|
Wouldn't this be easier ?
DateTime dt = new DateTime(cpCreateDate.SelectedDate.Year, cpCreateDate.SelectedDate.Month, cpCreateDate.SelectedDate.Day) ?
A lot less expensive than string to date conversions.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
//you can use substring method like this:
cpCreateDate.SelectedDate.ToString("dd/MM/yyyy").Substring(0,10)
|
|
|
|
|
I think you are trying to strip time because you think that small date time is only date field (lots of users think that, i don't know why, i guess there is something like that in Access), but that is not true. This data field just shortens range of valid values while keeping the time. Valid dates for a SMALLDATETIME column can range from January 1, 1900 to June 6, 2079.
If I'm wrong, and that is not what error is about than you can simply strip time with:
cpCreateDate.SelectedDate.Date;
|
|
|
|
|
You can also poke your eyes out with a screwdriver, but it doesnt mean its a good idea.
hint: what happens to your code when my date format is long date ie/09 January 2007
|
|
|
|
|
Hi all,
I'm coding a sql server job monitor usnig sql-dmo and c#.
I need help on how to use JobFilter interface.
Here is a sample of my code:
JobFilter _jf = null;
_jf.Category = "SAGAII";
QueryResults _qr = _srv.JobServer.EnumJobs(_jf);
The code results in an error.
Please help!
Thanks in advance
|
|
|
|
|
Hi all,
I have a problem manipulating form contrls in user thread or our made threads.
In VS 2003 this code was running fine that is on a button click we make a new thread , pass it the function to call and start it but in VS 2005 it is making problem and giving a "CROSS THREAD OPERATION EXCEPTION". I dont knw why. Is there a way to call the threaded function and manipulate MULTIPLE form controls.
Thanks in adv
Reply soon
private void button1_Click(object sender, System.EventArgs e)
{
Thread newthrd = new Thread(new ThreadStart(Increment_ProgressBar));
newthrd.Start();
}
private void Increment_ProgressBar()
{
for(int count=0;count<101;count++)
{
progressBar1.Value = count;
Thread.Sleep(100);
}
}
Bye
|
|
|
|