|
carbon_golem wrote: it just might be pointing out that there are higher quality alternatives.
You mean like "goto"?
LOLOL
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Jammer wrote: What do other folks think of this?
It's not Object Oriented and the following is a section of my own notes to myself (quotes ) from Kent Becks book "Implementation Patterns"
<w:worddocument xmlns:w="#unknown"><w:punctuationkerning><w:validateagainstschemas><w:compatibility><w:breakwrappedtables><w:snaptogridincell><w:wraptextwithpunct>
<p class="MsoNormal">Conditional (page 36)</p><p class="MsoNormal">If/then and switch statements are the simplest form of
instance –specific behavior….</p><p class="MsoNormal">The more paths through a program the less likely the program
is to be correct….The proliferation of conditionals reduces reliability….This
problem is compounded when conditionals are duplicated.</p>
<p class="MsoNormal">These problems can all be eliminated by converting the
conditional logic to messages, either with subclasses or delegation.</p>
Last modified: 5hrs 28mins after originally posted --
led mike
|
|
|
|
|
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Wow what a mess. Fixed. Thanks
|
|
|
|
|
Well, your colleague is a moron, and it sound s like his father should have used a switch on him more often when he was a child.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Whoa ... it wasn't my colleague that stated this ... he was passing on things he'd read/heard ... it was a light-hearted conversation!
He is far from a Moron as well, a very good developer in fact.
|
|
|
|
|
Jammer wrote: He said that he'd read/heard more than once that if you find yourself using a switch you can more or less be assured that its because you've done something wrong in your architecture elsewhere.
That probably comes from someone who don't know how to use a switch properly...
What seems more elegant?
This:
int result;
SomeClass.SomeEnum value = SomeClass.GetValue();
if (value == SomeClass.SomeEnum.Option1 || value == SomeClass.SomeEnum.Option2) {
result = 1;
} else if (value == SomeClass.SomeEnum.Option3) {
result = 2;
} else if (value == SomeClass.SomeEnum.Option4 || value == SomeClass.SomeEnum.Option5 || value == SomeClass.SomeEnum.Option6) {
result = 3;
} else {
result = 4;
}
or this:
int result;
switch (SomeClass.GetValue()) {
case SomeClass.SomeEnum.Option1:
case SomeClass.SomeEnum.Option2: result = 1; break;
case SomeClass.SomeEnum.Option3: result = 2; break;
case SomeClass.SomeEnum.Option4:
case SomeClass.SomeEnum.Option5:
case SomeClass.SomeEnum.Option6: result = 3; break;
default: result = 4; break;
}
Besides, the switch solution is faster.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
It depends on the situation. There are definitely situations where I've seen needless use of switch statements, and others that would have benefitted from a switch statement.
If you find that you are switching on a specific property of a class a lot within that class then it can be an indication that you might want to refactor the code into a class hierarchy. Each derived class handles a specific case that was in the switch statement.
|
|
|
|
|
As others said, switch statement has many benefits. So use it wisely. You should read something about method cohesion[^].
|
|
|
|
|
Hello friends,
I'm writing a program that reads all the files in a specified folder and stores their attributes in a MS-Access database. I'm using the FileInfo, and the FileVersionInfo classes to query file attributes. But these classes don't expose properties or methods to query advanced attributes such as image dimensions, ablum title, etc. I googled to find out the answer and it came up with GetDetailsOf method of shell32.dll. It seems that the GetDetailsOf method would be a perfect fit for my purpose as I only need to read that info. But what is really worrying me is its portability. The second argument is an integer and it specifies the info. to be retrieved. Is its value consistent across all Windows versions. I just want to make sure that I don't get two different values for the same file, with the same integer value under different Windows versions.
Many thanks in advance
|
|
|
|
|
Yes, those constants are the same from version to version. They won't change the constants, only add to them.
Ankit Rajpoot wrote: But what is really worrying me is its portability.
What's your definition of "portability" and your concerns? Which platforms are you going to look at supporting? Or were you just referring to the constants passed to the GetDetailsOf method?
|
|
|
|
|
Hello Sir,
I'm planning to support Win98 and later versions of Windows. I've Windows XP SP2 on my Development machine. So I need to make sure that the code that I write and test on Xp runs on earlier versions too and on Vista too.
What I'm worried about is that the constant-value to file-attribute mapping is same on all Windows versions or not. For example, passing 15 returns the Artist's name from the file. Is it true for all Windows versions.
|
|
|
|
|
Ankit Rajpoot wrote: What I'm worried about is that the constant-value to file-attribute mapping is same on all Windows versions or not. For example, passing 15 returns the Artist's name from the file. Is it true for all Windows versions.
Yes, it is. If there are any changes, they are additions to the constant list. All previous constants will work the same way they did in previous versions of Win32.
|
|
|
|
|
Hi,
I have one problem and would like that when I click on the button is automatically saved me a report that the disk in pdf format. I can show it in pdf only does it can not be saved.
Anybody got any idea? I work in VS2003 asp.net (C #)
thanks
lp
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection sqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["povezava"]);
SqlDataAdapter da = new SqlDataAdapter("select * from posta1" , sqlConnection1 );
da.Fill(dataSet11,"posta1");
myReport.Load(Server.MapPath(Request.ApplicationPath)+"\\CrystalReport1.rpt");
MemoryStream oStream; // using System.IO
myReport.SetDataSource(dataSet11);
oStream = (MemoryStream)
myReport.ExportToStream(
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat );
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(oStream.ToArray());
Response.End();
}
modified on Monday, October 13, 2008 4:06 PM
|
|
|
|
|
Hello everyone,
Synopsis: I’m trying to recieve and process calls from clients via Remoting.
Architecture scenario 1
Server A (Console Application): receives and processes calls from clients via remoting ( TCP / Singlecall )
Architecture scenario 2
Server B (Windows Service): receives and processes calls from clients via remoting ( TCP / Singlecall )
Problem
Scenario 1 works; scenario 2 doesn’t work over the network with the same code. I receive a time-out after 40 seconds. Local it does work fine.
Servercode
TcpServerChannel channel = new TcpServerChannel(IdtProgrammaConfiguratie.Poort);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteClass), "RemoteClass", WellKnownObjectMode.SingleCall);
Clientcode
if (ChannelServices.RegisteredChannels.Length == 0)
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
string server = servernaam + ":" + port.ToString();
RemoteClass serverRemotingObject = (RemoteClass)Activator.GetObject(typeof(RemoteClass), "tcp://"+server+"/RemoteClass");
test = serverRemotingObject.HandleRequest(query, databasenaam);
Errormessage:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.56:8989-
Server stack trace:
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at BCT_Group.RemotingConnector.HandleRequest(String Query, String Databasenaam)
at IDT_ComApi.ResponseXml.GetXmlResponse(String query, String host, Int32 port, String databasenaam) in C:\IDT_Com_Remote\IDT_ComApi\ResponseXML.cs:line 21
at IDT_ComObject_Remote.IDT_ComObject_Remote.Get_Response(String query, String host, Int32 port, String databasenaam) in C:\IDT_Com_Remote\IDT_ComObject_Remote\IDT_ComObject_Remote.cs:line 37
|
|
|
|
|
I had the same scenario and had problem with Windows Application and finally wrote that in Console and I'm working with it and have no problem, what about you? No problem? Fine... Well I had to go, bye
While (true) { Human.isLearnable = true; }
|
|
|
|
|
Hmmmm, I need to run a service; or is there a way to make the console application invisible to the user?
|
|
|
|
|
I don't know about a console app with no console - but you can do a WinForms app with no form very easily. Just remove the
Application.Run(new Form1());
line from the Program.cs file, then remove the not needed Form from the project.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
MegaBlasterX wrote: make the console application invisible to the user
What? A Console app have a Console which users can see. Wait a minute... We can pass Console inputs to a WinForm!
Application.Run(new Form1(Console.ReadLine()));
Yes, We can get the Server messages in Console and pas them throw our WinForm
While (true) { Human.isLearnable = true; }
|
|
|
|
|
hi guys
i am in need of an IRIS Recognition SDK, i downloaded Verieye it is good but the license has expired and it stopped working. any ideas please, its very important to me.
thank you everyone
|
|
|
|
|
If you're looking for a free one, I haven't been able to find one that does biometric ID. There are free libraries that can FIND an iris in an image, but that's about it.
|
|
|
|
|
Hi,
.net2 vs2005
Im creating a winform app that will display a list of images and some text under them. the images will be displayed horizontally across the screen and the user can scroll left or right using buttons.
I could display pictureboxes and text boxes across the screen but what I would like is something like a horizontally scrolling datagridview (where the rows are actually columns and the columns are rows) and i would use CellFormatting to display the images.
Is there a control that would enable me to do this or can someone point me in the right direction as to how to do this?
Many thanks.
Chas
|
|
|
|
|
Based on the description of what you've said, I wouldn't be relying on a datagrid or any other control in the ToolBox. I'd probably start by creating my own control to do this. I'd probably start with a scrollbar and a rendering system that only draws the thumbnails in the view.
|
|
|
|
|
Hi,
I managed to get it working using a datagridview - the issue was with having different datatypes in the same column...
Instead of binding to the datasource i looped through the datasource and and created and appended DataGridViewImageCell and DataGridViewTextBoxCell objects to DataGridViewRow objects.
Then adjusted some of the datagridview properties until it looked better...
Thanks,
Chas
|
|
|
|
|
Hey people I´m still having a little problem here!!! I´m trying to execute a program by double clicking on a file shown in List View... The methods to show fthe files and folder I did and it´s working well...
to execute a file I created a new mwthod executeFile
private void executeFile(TreeNode nodeCurrent)
{
Process.Start(getFullPath(nodeCurrent.FullPath));
Process.Start(String.Format("\"{0}\"", getFullPath(nodeCurrent.FullPath)));
}
as you can see getFullPath(nodeCurrent.FullPath) gets the path for the directory where the file is. I don´t know if I did right but do call the method I greated another by doubleclickin on th list view lvFiles_SelectedIndexChanged and called the method executeFile(nodeCurrent) but It doesn´t work... it says nodeCurrent doesn´t exists on the namespace...
I don´t know if I did executeFile right...
Could some good soul please help me????
Thanks!
|
|
|
|