|
I declared this:
public enum HowFullIsGlass<br />
{<br />
HalfEmpty,<br />
HalfFull<br />
}
and then tried to execute this statement block
HowFullIsGlass hfig ;<br />
if (hfig == null)<br />
{<br />
Console.WriteLine("Null value");<br />
}
I get this error
Warning 1 The result of the expression is always 'false' since a value of type 'WindowsApplication7.HowFullIsGlass' is never equal to 'null' of type 'WindowsApplication7.HowFullIsGlass?' C:\Users\russell.jones\Documents\Visual Studio 2005\Projects\WindowsApplication7\WindowsApplication7\Form1.cs 26 17 WindowsApplication7
I would be tempted to declare this
public enum HowFullIsGlass<br />
{<br />
Dunno,<br />
HalfEmpty,<br />
HalfFull<br />
}
and declare it as HowFullIsGlass hfig = HowFullIsGlass.Dunno;
then you don't need the null check you can check for Dunno
<br />
<br />
HTH<br />
<br />
Russ
|
|
|
|
|
salon,
Just add a value of "Null" to your enum and pass that.
Regards,
Gareth.
|
|
|
|
|
Enums are value types and therefor can never be null.
If you mean that the user provides a string and you try to parse it to get an enum value then I suggest you use System.String.IsNullOrEmpty and act accordingly.
|
|
|
|
|
|
gareth111 wrote: IsNullOrEmpty is not recommended as it can throw an exception which you wouldn't expect.
I have only ever seen this bug reproduced in the do-nothing example, not in any real code.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
This only applies in a very specific case and, if you move to .NET 3.5, it's been fixed.
|
|
|
|
|
Pete O'Hanlon wrote: This only applies in a very specific case and, if you move to .NET 3.5, it's been fixed.
Thats good know. Thanks.
Regards,
Gareth.
|
|
|
|
|
Every method that does something like "return someObject == null || someObject.SomeProperty == someValue;" can cause that exception (but only if it's called in a useless loop).
And it's fixed in .NET 2.0 SP1.
|
|
|
|
|
I have a ListBox set as Multiselect. I am populating the table thruough asp.net code. But I am using another dataset to get the items that should be selected. The only item that ends up selected is the last item in the dataset, and I know in several cases there are at least two items that should be selected. The code I am using for setting the selected items is:
DataSet ds1 = SqlHelper.ExecuteDataset(ConnStr, "StoredProd", Parm);
lbRequestTime.SelectionMode = ListSelectionMode.Multiple;
foreach (DataRow row in ds1.Tables[0].Rows)
{
lbRequestTime.SelectedValue = row["PerfTimeId"].ToString();
}
Any help on how to get the Mulitple selected items selected would be great.
Thanks, Doug
modified on Tuesday, March 25, 2008 9:33 AM
|
|
|
|
|
Hi,
you can use the following code
<br />
ListItem li;<br />
foreach (DataRow row in ds1.Tables[0].Rows)<br />
{<br />
li = lbRequestTime.Items.FindByValue(row["PerfTimeId"].ToString());<br />
if (li != null)<br />
li.Selected = true;<br />
}<br />
Do let me know if you need more info.
Cheers...
|
|
|
|
|
Hi,
I am using two sitemaps.I wrote code like this
web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="" description="Home">
<siteMapNode url="Default.aspx" title="Computer" description="Computer" >
<siteMapNode url="Default.aspx" title="Laptop" description="Laptop" />
<siteMapNode url="Default.aspx" title="Desktop" description="Desktop" />
</siteMapNode>
</siteMapNode>
</siteMap>
web1.sitemap
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="User" description="User">
<siteMapNode url="" title="Forgot Password" description="Forgot Password" />
<siteMapNode url="" title="Change Password" description="Change Password" />
<siteMapNode url="" title="Login" description="Login" />
</siteMapNode>
</siteMap>
Web.config
<siteMap enabled="true">
<providers>
<add name="Example" type="System.Web.XmlSiteMapProvider" sitemapfile="~/Web.sitemap"/>
<add name="Example1" type="System.Web.XmlsitemapProvider" sitemapfile="~/Web2.sitemap"/>
</providers>
</siteMap>
.aspx page
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" SiteMapProvider="Example" />
It showing following error
Server Error in '/MultipleSitemap' Application.
The attribute 'sitemapfile' is unexpected in the configuration of the 'Example' provider.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.ConfigurationErrorsException: The attribute 'sitemapfile' is unexpected in the configuration of the 'Example' provider.
Source Error:
[No relevant source lines]
Source File: c:\Documents and Settings\system3\Local Settings\Temp\Temporary ASP.NET Files\multiplesitemap\85793d13\552d1a9d\App_Web_dbjhdcj7.0.cs Line: 0
How to solve this?
anyone help me please.
|
|
|
|
|
This is case sensitive. Use siteMapFile instead of sitemapfile . Please remove the posts below as well.
|
|
|
|
|
|
Hi,
Has anyone worked with Client Application Services in Visual Studio 2008? Can someone please tell me where I can find a good tutorial on using Client Application Services concerning SQL 2005? I have a lot of tutorials on how to impliment it but there's nothing on how to impliment it using SQL Server.
Thank you!!
Illegal Operation
Making Computer Software Talk
|
|
|
|
|
Hi,
I am using two sitemaps.I wrote code like this
web.sitemap
<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<sitemapnode url="Default.aspx" title="" description="Home">
<sitemapnode url="Default.aspx" title="Computer" desscription="Computer">
<sitemapnode url="Default.aspx" title="Desktop" description="Desktop">
web1.sitemap
<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<sitemapnode url="" title="User" description="User">
<sitemapnode url="" title="Forgot Password" description="Forgot Password">
<sitemapnode url="" title="Change Password" description="Change Password">
<sitemapnode url="" title="Login" description="Login">
Web.config
<sitemap enabled="true">
<providers>
<add name="Example" type="System.Web.XmlSiteMapProvider" sitemapfile="~/Web.sitemap">
<add name="Example1" type="System.Web.XmlsitemapProvider" sitemapfile="~/Web2.sitemap">
.aspx page
<asp:sitemapdatasource id="SiteMapDataSource1" runat="server" sitemapprovider="Example">
It showing following error
Server Error in '/MultipleSitemap' Application.
The attribute 'sitemapfile' is unexpected in the configuration of the 'Example' provider.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.ConfigurationErrorsException: The attribute 'sitemapfile' is unexpected in the configuration of the 'Example' provider.
Source Error:
[No relevant source lines]
Source File: c:\Documents and Settings\system3\Local Settings\Temp\Temporary ASP.NET Files\multiplesitemap\85793d13\552d1a9d\App_Web_dbjhdcj7.0.cs Line: 0
How to solve this?
anyone help me please.
|
|
|
|
|
Hi,
I am using two sitemaps.I wrote code like this
web.sitemap
<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<sitemapnode url="Default.aspx" title="" description="Home">
<sitemapnode url="Default.aspx" title="Computer" desscription="Computer">
<sitemapnode url="Default.aspx" title="Desktop" description="Desktop">
web1.sitemap
<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<sitemapnode url="" title="User" description="User">
<sitemapnode url="" title="Forgot Password" description="Forgot Password">
<sitemapnode url="" title="Change Password" description="Change Password">
<sitemapnode url="" title="Login" description="Login">
Web.config
<sitemap enabled="true">
<providers>
<add name="Example" type="System.Web.XmlSiteMapProvider" sitemapfile="~/Web.sitemap">
<add name="Example1" type="System.Web.XmlsitemapProvider" sitemapfile="~/Web2.sitemap">
.aspx page
<asp:sitemapdatasource id="SiteMapDataSource1" runat="server" sitemapprovider="Example">
It showing following error
Server Error in '/MultipleSitemap' Application.
The attribute 'sitemapfile' is unexpected in the configuration of the 'Example' provider.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.ConfigurationErrorsException: The attribute 'sitemapfile' is unexpected in the configuration of the 'Example' provider.
Source Error:
[No relevant source lines]
Source File: c:\Documents and Settings\system3\Local Settings\Temp\Temporary ASP.NET Files\multiplesitemap\85793d13\552d1a9d\App_Web_dbjhdcj7.0.cs Line: 0
How to solve this?
anyone help me please.
|
|
|
|
|
Here is the deal:
I have got quite old application which was written in VB 6 using some ActiveX Controls. My task is to perform some automatic test using Quick Test Pro, which doesn’t recognize those ActiveX controls, but it doesn’t matter.
What I want to attain is to get control over an another application ActiveX control using its window’s (control’s) handle. http://rotanes.pl/Project1.exe <- here is really simple application (requires VB 6 runtime) with a data grid (microsoft Data Grid Control 6.0, MSDATAGRID.OCX) and one button, which changes data grid height. I want to be able to do the same from, for example, .net application. Just pass the handle (I can take it from any spy software) and perform the action.
What I discovered:
This ActiveX grid implements some COM interfaces, which are defined in the same dll (ocx) file, just use OLE/COM Viewer and everything is visible. So I’ve spent more then one week trying (using .net and C#) grab this interface knowing only controls hwnd.
My attempts (I used to be a .net developer so I wrote everything in C#):
-> Implement interface _cGrid (which is the interface I would like to cast a COM as) by myself:
[ComImport, Guid("60E9A471-E4DF-4687-B419-15A644E8AD57]
public interface _cGrid
{…}
Or use the one generated by tlbimp.exe.
-> import some extern procedures:
[DllImport("oleacc.dll", PreserveSig = false)]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern object AccessibleObjectFromWindow(IntPtr hwnd, uint dwId, ref Guid riid);
(I tried this import in several different manners, for example with UnmanagedType.IUnknonw, UnmanagedType.IDispatch, adding “out IntPtr ppvd“as the last parameter and changing returned value to int…)
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
-> Dozens of tries to make everything working (unsuccessfully ):
_cGrid result = (_cGrid )InteropClass.AccessibleObjectFromWindow(handle, 0, ref ITypeInfoGuid); <- throws en exception “Invalid Cast”
InteropClass.AccessibleObjectFromWindow(handle, 0, ref ITypeInfoGuid, out _cGridPtr); <- after every statement execution _cGridPtr has different value and it is different from Marshal.GetIUnknownForObject(obj) (I had reference to the control for my learning purposes, but I won’t have). It sends single WM_GETOBJECT message to the control wit 0xffffffff and 0x00000000 parameters (the second parameter referes to the second parameter of AccessibleObjectFromWindow procedure) which always returns different value (the subtraction of two sibling values equals 32, coincidence?)
Marshal.GetTypedObjectForIUnknown <- always throws “invalid cast exception” or something like this.
I would appreciate any (the simpler the better, prefereably c# by can be managed/unmanaged c++ or VB as well) example of code which works and can retrieve valid IUnknown pointer (or even cast pointer as interface) from ActiveX control knowing only its hwnd.
I found followiong links helpful:
[Some basis]
http://www.codeguru.com/csharp/csharp/cs_misc/com/article.php/c9065/
http://www.clarionmag.com/cmag/v1/v1n6callingole_part1.html
http://www.codeproject.com/KB/COM/COM_from_scratch_1.aspx
[I think the same problem]
http://www.vbforums.com/archive/index.php/t-158336.html
[Hopeful links]
http://www.thescripts.com/forum/thread233284.html
http://msdn2.microsoft.com/en-us/library/ms696137(VS.85).aspx
Especially -> Clients call this function to retrieve the address of an object's IAccessible, IDispatch, IEnumVARIANT, IUnknown, or other supported interface pointer.
I originally posted this message on http://www.codeguru.com/forum/showthread.php?p=1700068
Thanks in advance.
|
|
|
|
|
How to determine what process is running at the active TCP ports??
Som
|
|
|
|
|
Hi everyone
Is anybody can help me, I have a problem here , how to generate not repeated random integer values ?
Thanx in advance
Regard,
Edwin
|
|
|
|
|
|
I assume he means he wants the random numbers to not repeat. 4 2 3 1 5, not 4 2 1 4 5
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 )
|
|
|
|
|
I need to write an article, this gets asked so often.
You create a list of numbers, which is the range of numbers you want to choose from ( such as 1-100 ).
You generate a random number between 0 and 99 ( for example ). You pull the number at that index out, and remove it from the list. Next time, you generate a number between 0 and 98, and do the same. And so on.
The other option is to write a custom sorting routine that returns a random number, but I've never tried that, I'm not sure if it wouldn't end up going for ever as the sort order keeps changing.
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 )
|
|
|
|
|
Christian Graus wrote: You create a list of numbers, which is the range of numbers you want to choose from ( such as 1-100 ). You generate a random number between 0 and 99 ( for example ). You pull the number at that index out, and remove it from the list. Next time, you generate a number between 0 and 98, and do the same. And so on.
Hey, Christian, your technique works very well if the sample size is small and many of those numbers will be used (for instance, you want 15 unique random numbers less than 25).
If the sample size is large ( 0 - 10 million ) and very few of them will be used, you are better off generating numbers within the range and checking if they have already been generated (you have to maintain a list for that). If not, you add the number to the list and use it.
Cheers,
Vikram.
Zeppelin's law: In any Soapbox discussion involving Stan Shannon, the probability of the term "leftist" or "Marxist" appearing approaches 1 monotonically.
Harris' addendum: I think you meant "monotonously".
Martin's second addendum: Jeffersonian... I think that should at least get a mention.
|
|
|
|
|
how many teachers are going to get their students to run this code on a sample size that large though
|
|
|
|
|
Yes, that's probably true, I can't imagine needing a small number of unique values between 1 and 10 million, tho. I guess it's possible, and what you say is a good point.
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 )
|
|
|
|