|
jchalfant wrote: I can't modulo a double by an int, thus forcing me to convert to int
just convert the int to a double then...
I am not sure I understand the problem. (4/4)%2 = 1 is correct. What are you trying to do?
|
|
|
|
|
While C# can handle double % double, ADO.Net expressions can't. I've tried that, no love. Doing so produces a MessageBox at runtime saying
Cannot perform 'Mod' operation on System.Double and System.Double.
What I'm trying to do is get around the lack of bitwise operation support in ADO.Net expressions. In doing so I was hoping to be able to easily bind some control properties to boolean values in a datatable whose values are determined by an expression (somecolumn/somenumber)%2=1. Unfortunately I don't think this is possible.
Oh, and the title, is an oops. What I meant was 3/4%2.
|
|
|
|
|
jchalfant wrote: What I meant was 3/4%2.
That makes sense.
Maybe you can return the boolean values directly in your result set or however you retrieve them.
|
|
|
|
|
That's one of my conclusions.
But what I think I'll do instead is manually add the column to the datarow and evaluate the value based on other column values. I'm not pressed for time on this project, so I've got time to play around and do different things.
|
|
|
|
|
Perhaps you should explain what it is that you are trying to accomplish, rather than asking about why the workaround that you think might be the solution doesn't work as expected...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Your words of encouragement enlighten me...
To summize what I've already said:
Bitwise operation on the DataColumn Expression property to be used with boolean properties on databound controls.
At any rate, I've determined that it ain't gonna happen through the dataset designer. Any sentiments of wanting to assist are much appreciated.
|
|
|
|
|
Hi,
Not sure why SomeColumn would be a double to start with.
assuming your SomeColumn actually holds an integer value, FIRST convert it to int,
then start processing its bits.
Probably a simple if (intValueOfSomeColumn & 4 != 0) ... does exactly what you want...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I wish it were so simple. Datacolumn.Expression, any expression in an activex data object actually, doesn't support bitwise operators.
So, that's no big deal x/y%2 should work. Right? Nope.
ADO.net objects return a double to the engine before computing the modulus. So int/int%2 turns into double%2, which isn't supported. Convert won't work because it performs a Round instead of a cast.
In the end, what I wound up settling on was computing the boolean values as bit fields when I retrieve the data from the database.
|
|
|
|
|
Hi,
Seems to me one of us is not understanding what the other meant.
Either you start with a TYPE double that holds an integer VALUE, then my advice is to
convert it to a TYPE int; that will succeed without problems (unless you exceed the
int's range).
Or your TYPE double holds a non-integer VALUE, and then you will not be able to explain to
me what the meaning of most of its bits is; your question does not make sense in this case.
Did you at all try what I suggested?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi,
I wrote a simple code to read a binary file.
It just shows contents of a file as hexadecimal digits.
<br />
using System;<br />
using System.IO;<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
FileInfo fi = new FileInfo(args[0]);<br />
BinaryReader br = new BinaryReader(fi.OpenRead());<br />
int offset = 0;<br />
while (br.PeekChar() != -1)
{<br />
if (offset++ % 16 == 0)<br />
Console.Write("\n{0:x8}:", offset);<br />
Console.Write("{0,4:x2}", br.ReadByte());<br />
}<br />
Console.WriteLine();<br />
br.Close();<br />
}<br />
}<br />
And an exception is thrown at PeekChar() method showing messages as follows:
<br />
Unhandled exception: System.ArgumentException: Cannot include the encoded character because of insufficient buffer<br />
Encoding 'Unicode (UTF-8)' (fallback) 'System.Text.DecoderReplacementFallback'.<br />
Argumane name: chars<br />
Location: System.Text.Encoding.ThrowCharsOverflow()<br />
Location: System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothingDecoded)<br />
Location: System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)<br />
Location: System.Text.DecoderNLS.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, Boolean flush)<br />
Location: System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, Boolean flush)<br />
Location: System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)<br />
Location: System.IO.BinaryReader.InternalReadOneChar()<br />
Location: System.IO.BinaryReader.Read()<br />
Location: System.IO.BinaryReader.PeekChar()<br />
Location: Program.Main(String[] args) File D:\CSharp\ConsoleApp\Program.cs:Line 11<br />
I'd like to know what's wrong with my code and what is the right way.
I'm using VS 2005 & .NET framework 2.0.50727
Thanks in advance.
|
|
|
|
|
The file you're reading has unicode characters. Set the encoding to Encoding.Unicode
FileInfo fi = new FileInfo(args[0]);
BinaryReader br = new BinaryReader(fi.OpenRead(), Encoding.Unicode);
int offset = 0;
while (br.PeekChar() != -1)
{
if (offset++ % 16 == 0)
Console.Write("\n{0:x8}:", offset);
Console.Write("{0,4:x2}", br.ReadByte());
}
Console.WriteLine();
br.Close();
Eslam Afifi
|
|
|
|
|
I’ve developed an application that uses a third party ActiveX control for a long time. Now when I run the application on Windows Vista I got the following exception:
at System.Windows.Froms.UnsafeMethods.IOleObject.SetClientsite(IOleClientSite pClientsite)
at System.Windows.Forms.AxHost.SlowActivate()
at System.Windows.Forms.AxHostTransitionUpTo(Int32 state)
at System.Windows.Forms.AxHostCreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at System.Windows.Forms.CortonaControl.InitializeComponent()
...
Any idea what’s wrong with Vista?
_____________________________
...and justice for all
APe
|
|
|
|
|
d00_ape wrote: Any idea what’s wrong with Vista?
d00_ape wrote: uses a third party ActiveX control for a long time
Not Vista, get an updated ActiveX control.
|
|
|
|
|
Errm. Why do you think it's a problem with Vista? If a nail punctures your tyre do you think that's a faulty tyre? I would guess that the problem has more to do with the control misbehaving - and Vista's a lot stricter than earlier MS OSes.
|
|
|
|
|
Ok nothing is 'wrong' with Vista but apparently my program that have worked on XP for years does not do that on Vista. Maybe it’s a ‘new feature’ that it does not can use old ActiveX.
By the way, I have one Vista computer that my program works on but the other five cups that I have tried it on does not work.
I don’t really know where I should start searching for help…
I have the same question on http://www.codeguru.com/forum/showthread.php?p=1692586#post1692586
_____________________________
...and justice for all
APe
|
|
|
|
|
Pete O'Hanlon wrote: Vista's a lot stricter than earlier MS OSes
Can I in some way make Vista less stricter on my application?
_____________________________
...and justice for all
APe
|
|
|
|
|
Have you tried to set Vista to run this program as if it were an earlier version of the OS?
|
|
|
|
|
Yes, I have tried Run this program as: Windows XP (Service Pack 2) and as administrator, but same result.
_____________________________
...and justice for all
APe
|
|
|
|
|
Have you tried turning off UAC? Perhaps the ActiveX has a problem when virtualization is active...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Now I've tried that but no difference
_____________________________
...and justice for all
APe
|
|
|
|
|
|
Hi,
c#, vs2005.
Im creating xml documents and later validating them using an xsd.
I use the following code to create and append elements then output the xml document to a file:
XmlElement element = xmlDoc.CreateElement(fieldName);
element.InnerText = fieldValue;
parentElemennt.AppendChild(element);
the document is saved to file using xmlDoc.Save(path...)
and validated later using an XmlReader with reader settings.
The problem is that sometimes the fieldValue can be a blank string - looking at the xml file the empty tags get written as:
<element>
</element>
This causes problems with validation where lets say the type is set to a maxLength of 2:
The value '
' is invalid according to its datatype. The actual length is greater than the MaxLength value.
<element></element> works fine if i change it in the xml document manually.
How can I get the xml to be written as <element></element> or <element /> without the carriage return?
Another validation error im getting is where the field type is an Integer but left blank.
The value '
' is invalid according to its datatype The string ' ' is not a valid Integer value.
With this i still get an error if I change the xml to <element></element> and I have added the nillable=true flag in the xsd.
How can I get blank numeric elements to get accepted?
Thanks in advance.
Chas
|
|
|
|
|
Check to see if there is actually anything in fieldValue (i.e. is it an empty string) before setting the innerText. Make sure the string has been trimmed before the test so that you don't get dodgy data issues creeping in.
|
|
|
|
|
<field name="textBox" y="3.175" x="3.17" w="62" h="9">
<ui>
<textBox>
<border>
<css style=""> </css>
</border>
<margin/>
</textBox>
</ui>
<font face="Arial"/>
<margin topInset="1" bottomInset="1" leftInset="1" rightInset="1"/>
<textAlign vAlign="middle"/>
<label reserve="25">
<Font fontFace="Arial" size="8pt" />
<textAlign vAlign="middle"/>
<value>
<text>textbox label</text>
</value>
</label>
</field>
So I am trying to read the values of Font (IF there is a textBox element present) and trying to read the attributes fontFace and size, here is my Xpath:
XPathNodeIterator iterator = nav.Select(@"/field");
try
{
while (iterator.MoveNext())
{
...
XPathNavigator nav2 = iterator.Current.Clone();
if (string.Compare(nav2.Name, "field") == 0)
{
XPathNodeIterator textBoxIterator = nav2.Select("child::*/child::textBox");
if (textBoxIterator.Count > 0)
{
XPathExpression exp = nav2.Compile("child::Font");
XPathNodeIterator it = nav2.Select(exp);
while (it.MoveNext())
{
XPathNavigator nav3 = it.Current.Clone();
string fontFace = nav3.GetAttribute("typeface", nav3.NamespaceURI);
string fontSize = nav3.GetAttribute("size", nav3.NamespaceURI);
}
}
}
}
catch
...
}
Am I doing it the proper way or is it too complicated and can be simplified?
modified on Tuesday, March 4, 2008 10:22 AM
|
|
|
|
|
//field/font@fontFace I believe, and you can put something in [] to specific a condition, such as where there's a sibling node called textbox.
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|