|
Hi Luc,
Thank you very much for the comprehensive response. Here's the next issue (I did not like the ToString() calls either). Changing:
Byte.Parse(Octets[0].ToString()) to
(Byte)Octets[0] reults in Compiler Error:Error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
More awkwardness: changing from Parse() and ToString() to
(Int32)Octets[0] / 40 results in Runtime Error:An unhandled exception of type 'System.InvalidCastException' occurred in OIDFetch.exe
Additional information: Specified cast is not valid.
This is frustrating. I can understand abstracting away bit operations due to code portability. But when did operations on numbers stop being number-centric?
The situation reminds me of Java. Trying to read a file results in so many casts to so many readers, you lose the readability (semantics) of what you are trying to accomplish: FileReaders to ByteReaders to StreamReaders... I never went back to Java after college.
Jeff
|
|
|
|
|
Hi Jeff,
I agree one should avoid casts most of the time.
In what I explained, there basically was only one, and that one is due to the fact
that ArrayList stores objects, not known types, so when retrieving an ArrayList element,
you must cast it again to its real type. (The new List<byte> alternative solves that!)
I cannot figure out what is causing your compile error CS0201; I would need a larger
code snippet (yours is less than one statement, there is no semicolon, no curly bracket).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Jeff, some casting is going on here because you're using old stuff, ArrayList. Use List<byte> for the octets, and you won't need any casting.
|
|
|
|
|
Hi Judah,
Thanks. I found it in System.Collections.Generic.List<byte>. Time for another rewrite (copy and paste is my friend).
Jeff
|
|
|
|
|
Jeffrey Walton wrote: Changing:
Byte.Parse(Octets[0].ToString())
to
(Byte)Octets[0]
reults in Compiler Error:
Error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Then you obviously changed something more in that statement. If you only changed that, it would compile just fine.
Jeffrey Walton wrote: changing from Parse() and ToString() to
(Int32)Octets[0] / 40
results in Runtime Error:
An unhandled exception of type 'System.InvalidCastException' occurred in OIDFetch.exe
Additional information: Specified cast is not valid.
When you are unboxing a boxed value, you have to use the exact data type of the boxed value. Once you have unboxed it to get the byte value, you can cast it to an int if you like.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi Luc,
I hope it's not bad form to spawn a response for each question... I think it keeps dialogue exchange manageable.
I am not sure what type it is you originally put into the ArrayList, I will assume the item type is byte.
I used ArrayList due to a recomendation on the C# usenet group. I despise the concept of ArrayList of Objects for numbers (integers, shorts longs, etc)... I don't like the casting. I understand one may have an array of type Employee, where this makes sense.
For a 32 bit integer or 8 bit byte, this is offensive to me. What I want is a vector of bytes - no casting, perform math on the elements, etc. If C# wants to call it a collection, that is fine. But don't take away semantics of primitive operations such as v[2] = v[0] * v[1].
Luc Pattyn wrote: Furthermore, you could use a generic collection (available since .NET 2.0), in this case
a List<byte> instead of an ArrayList, although the difference would be minor here.
I'd like to try use this... Where does one find it? I did not see it in System.Collection. I imagine it is elsewhere? I am using VS 2005. I have .Net 1.1 and 2.0 Configuration Wizards, so I imagine the runtimes are installed.
Jeff
|
|
|
|
|
Hi Luc,
Found it in System.Collections.Generic.List<byte>.
Jeff
|
|
|
|
|
Hi Jeff,
"collection" (lower-case!) is the general term for an object holding a lot of objects that
can be enumerated somehow; so arrays, ArrayLists, Lists, Dictionaries, all are collections.
Array, ArrayList containing numbers, and List<some_numeric_type> v all would support
v[2] = v[0] * v[1] .
Jeffrey Walton wrote: I used ArrayList due to a recomendation on the C# usenet group.
Either that recommendation dates back from the .NET 1.x times, or it is suboptimal.
Basically List<T> is an ArrayList that only allows you to add objects of type T, and
automatically returns a type T when you access its items.
Starting with VS2005 (=.NET 2.0) a new Win app automatically gets a
"using System.Collections.Generic" and no longer a "using System.Collections".
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Jeffrey Walton wrote: b &= unchecked(Convert.ToByte(~0x80)); // Problem Here
The 0x80 literal is an int value. When you use the bitwise completent operator (~) on it, it will switch all bits in the int value, which results in the value -0x7FFFFF7F. This is clearly way too large to fit in a byte.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi Guffa,
Guffa wrote: The 0x80 literal is an int value.
It's a shame C# has a penchant for the Int conversion, even when I specify otherwise. For example, the following:
Byte b = 0x80;
b = ~b; results in a Compiler Error:Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) Humorous... When I attempt to cast, it complains also. The problems would go away if the compiler would listen to the human operator and simply compliment the Byte value b .
Jeff
|
|
|
|
|
Hi All,
I believe this is the cause of my grief. Microsoft documentation states:
The ~ operator performs a bitwise complement operation on its operand, which has the effect of reversing each bit. [1] This is very misleading: it does not compliment an operand - it compliments an Int . The programmer is left to clean up the mess created by the compiler.
Jeff
[1] ~ Operator (C# Reference)[^]
|
|
|
|
|
Hi all,
What is a better design in visual studio.
To create separate datasets for each database table or
one dataset with all tables on the dataset.
Lets say the database has 30 tables.
Just want to know your opinions!
Regards
Cecil
|
|
|
|
|
cecildt wrote: What is a better design in visual studio.
Visual Studio is the IDE. You can do all this stuff in notepad if you want. It has nothing to do with Visual Studio.
cecildt wrote: To create separate datasets for each database table or
one dataset with all tables on the dataset.
Or don't use datasets at all. I don't use them much. I see no need for them. I query the database and everything gets mapped into my business objects.
|
|
|
|
|
I know Visual Studio is the IDE.
Just want to know how people are using the DataSets.
Thanks for your responds.
O, use Notepad++ not notepad!
|
|
|
|
|
cecildt wrote: Just want to know how people are using the DataSets.
I don't. I use business objects. Most serious advice on the subject recommends not using DataSets because of their being a bit overkill and their lack of type safety.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
cecildt wrote: use Notepad++ not notepad!
I was just saying that any two-bit text editor can be used.
cecildt wrote: Just want to know how people are using the DataSets.
As Pete said, they shouldn't be using them in serious applications. For quick throw away or hobby applications they have their uses.
|
|
|
|
|
I've only started using datasets, so I'm no expert, but I favour one dataset per functional area. For example, I have one dataset for invoicing, with procucts, documents, and customers tables, where the customers table only has the customer data required for invoicing.
Calling all South African developers! Your participation in this local dev community will be mutually beneficial, to you and us.
|
|
|
|
|
Hi, I would like to know that how i can find any source for writing ReportViewer properties in my ReportForm.cs such as page setup,setting margins,printing and ...
D.Riazi
|
|
|
|
|
driaziran wrote: Hi, I would like to know that how i can find any source for writing ReportViewer properties in my ReportForm.cs such as page setup,setting margins,printing and ...
Why aren't you asking this question in the thread you created 3 slots down? What do you feel is wrong with that thread? What is wrong with the response you recieved already? Have you done any research yourself yet? Where are you stuck in your attempt to do this yourself?
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Hi, thanks for your response.but i don't want to creat any Report with Crystal Report.
I want to use Object Reporting with ReportViewer tool in C#.
D.Riazi
|
|
|
|
|
This[^] article was in the Top 10 hits in a google search for ReportViewer example[^]
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
This[^] article was in the Top 10 hits in a google search for ReportViewer example[^]. See if that article, or any of those links gives you a good starting point.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Hi,
I’m loading XML into a DataSet using the following…
// Create a new Customer DataSet.
CustomerDS = new DataSet();
// Get a handle to the Customer.xml file.
CustomerFileHandle = new FileStream(CUSTOMERXMLFILEPATH, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
// Read the Customer XML file into the DataSet.
CustomerDS.ReadXml(new XmlTextReader(CustomerFileHandle));
This loads the information into the DataSet and it can all be viewed on my Form.
After making changes to my data, I then want to update the XML file. To do this I’m using the following code…
XmlTextWriter CustXmlWriter = new XmlTextWriter(CustomerFileHandle, System.Text.Encoding.Unicode);
// Write to the file with the WriteXml method.
CustomerDS.WriteXml(CustXmlWriter, XmlWriteMode.IgnoreSchema);
CustXmlWriter.Close();
// Close the Customer XML File.
CustomerFileHandle.Close();
This is not producing valid XML. All data (the xml) is being repeated at the end of the file with a NULL character in between each character.
Any help on this would be much appreciated.
Thanks in advance.
|
|
|
|
|
I am not sure why that isn't working. However, why don't you try taking a different taking a different route to your solution? Something like this:
CustomerDS = new DataSet();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(XML_FILE);
xmlDocument.Save(XML_FILE);
Just a thought
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
How is it that I get my XML file into my DataSet?
|
|
|
|