Daily Archives

Articles indexed Sunday May 30 2010

Page 5/72 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Is using decimal ranges in a switch impossible in C#?

    - by phobia
    I'm justing starting out learning C# and I've become stuck at something very basic. For my first "app" I thought I'd go for something simple, so I decided for a BMI calculator. The BMI is calculated into a decimal type which I'm now trying to use in a switch statement, but aparently decimal can't be used in a switch? What would be the C# solution for this: decimal bmi = calculate_bmi(h, w); switch (bmi) { case < 18.5: bmi_description = "underweight."; break; case > 25: bmi_description = "overweight"; case > 30: bmi_description = "very overweight"; case > 40: bmi_description = "extreme overweight"; break; }

    Read the article

  • Strongly Typed Controls in .NET

    - by Tigraine
    I am working on a Windows Forms app for quite some time now, and I really find myself doing more typecasts in the GUI code than I ever did in my underlying business code. What I mean becomes apparent if you watch the ComboBox control that accepts some vague "object" as it's item. Then you go off and may display some DisplayMember and a ValueMember and so on. If I want to retrieve that value later I need to typecast my object back to what it was. Like with strings getting the value takes string value = (string)combobox1.SelectedItem; Since there are generics in the Framework for quite some time now, I still wonder why in the Hell not one control from the standard toolbox is generic. I also find myself using the .Tag property on ListViewItems all the time to keep the displayed domain object. But everytime I need to access that object I then need another typecast. Why cant I just create a ComboBox or ListView with items of type ListViewItem Am I missing something here or is this just another example of not perfectly well thought through controls?

    Read the article

  • Suppress Eclipse compiler errors in in a plug-in

    - by Jan Gorzny
    Hi, I'm currently working on a plug-in for Eclipse that translates some custom Java code (which doesn't necessarily run/compile), to runnable Java code. In particular, the plug-in allows code to be written using classes created or imported during the translation. In general, the pre-translation code runs/compiles fine provided the writer uses import statements at the top of their class files. However, it would be convenient for my users if it was not necessary to import these classes. At the moment, the lack of import statements results in (obvious) compiler errors. Would it be possible to empower my plug-in to either a) suppress/ignore these errors, or b) have Eclipse find these classes automatically, without the use of import statements? I should point out that the translated code would these include the required import statements--but this is not a problem for me. I'm also aware that this could lead to lazy programmers and some bad habits. To clarify, consider the following example of pre-translated code: File f = new File("Somefilename.txt"); which clearly requires the possibly imported class File. Without an import statement (import java.io.File;), Eclipse reports that File can not be resolved to a type. This is the error I'd like to hide in files pertaining to projects created for use with my plug-in. (The translated code would include import java.io.File; so that it would be runnable) In closing, I should point out I'm not necessarily looking for code (though I wouldn't be opposed to it), but rather some links to some relevant tutorials (if they exist), or helpful tips/ideas. Also, as this is my first plug-in, it's entirely possible that what I'd like to do is not possible and that I don't realize it--if this is the case, please let me know, preferably with some justification. Thanks!

    Read the article

  • algorithmes with no executable example code

    - by gcc
    [link] http://stackoverflow.com/questions/2932016/parsing-of-mathematical-expressions (problem has been told before) ** program is to create the infix tree for the given math expression.** if the expression is given completely paranthesized then the out put is fine but when there are no paranthesis or some part paranthesized then the out put is wrong. cant get the idea how to solve. my problem is told above. I have some algorithm to solve my problem, but I have no simple code which will be guide for me. Can anyone give me simple code (not working code) so that I will try working to understand.(for a 3 hours ,I have been searching and reading some text to understand algorithm which is told above.Actually,there is no example code investigating how it is working. Can anyone send me example which is written in c not other language.

    Read the article

  • Restoring Mac-bootcamp-windows-partition image to Windows machine

    - by jpwagner
    Hi, I'm running Windows XP sp3 on my mac using bootcamp. Objective: I'd like to move this partition to a windows machine. This is what I tried: 1. create image using winclone 2. restore drive to disk partition on windows machine using paragon 3. reboot from new partition Results: it attempts to boot in XP (windows flag and progress bar load screen) but then gives me the old BSOD. safe mode just hangs while loading. (I then uninstalled KB977165 on a hunch, but that did nothing to help the issue.) Any ideas, advice, etc would be greatly appreciated. Thanks!

    Read the article

  • Sending an email when an Exception is Thrown

    - by hariubc
    Hi: I have written a java class where if a method throws an exception, an email is sent, via java mail, with a report to the administrators. It works - my question is w.r.t elegance - to catch the exception thrown by the main method, the sendEmail() method resides in the catch block of the main method. The sendEmail() method has its own try-catch block. In effect - it looks like below - is there a more beautiful way of writing this? try { foo; } catch { try{ sendEmail(); } catch { log(e.message); } }

    Read the article

  • Creating a Multiwindowed Cocoa Program - Launching Procedure Suggestions?

    - by Jeffrey Kern
    I'm porting an application I developed in Visual Studio 2008 over to Cocoa. I'm currently doing a 'learn-as-you-go' approach to Cocoa, so I can experiment with different ideas and techniques in smaller, simpler projects and eventually combine them into one big application. My program logic is as follows (in a dumbed-down sense). Items in the list are mandated by my boss. Application is started 1a. Verify CD program is in drive. Verify license. If found and is valid, skip to step 7 Display license agreement. Display serial number prompt. Verify and save serial number. Hide all prior windows. Load main application window Intercept requests and commands from main application window, including making a duplicate main application window Exit program when requested by user What would the best bet be for this type of application? From another question I asked, I found out that I should keep the 'main application' window in a separate XIB file from the rest, because I might need to clone and interact with it. I know that since Cocoa and Objective-C is based off of C, there is a Main method somewhere. But what would you all suggest as a starting place for an application like this?

    Read the article

  • FF extension: displaying an array of string elements in a sidebar

    - by sujay-jain
    I am developing a ff extension which displays a list of elements from an array (dynamic) in the sidebar. The array is dynamic and needs to be constructed in a function everytime the sidebar is opened (or any other event handler). Later, i will need to implement link functionality on parts of the string. What is the best way to go about this? I have created an empty sidebar and just know the label element as of now. menu, and menuitem dont work. What other elements can i use to display text in a good way which supports dynamic contruction. Is there some good tutorial/sample extension which i can see and learn?

    Read the article

  • getting a key out of a javascript hash

    - by mcintyre321
    I working with the latest draft of the twitter annotations api. An example bit of data looks like status { annotations : [ {myAnnotationType:{myKey:myValue}}, {someoneElsesAnnotationType:{theirKey:theirValue}}, ] } now i want to check a status to see if it has an annotation with myAnnotationType in it. If annotations was a hash instead of an array I could just write var ann = status.annotations.myAnnotationType. But its not so I wrote this instead: function getKeys(obj){ var keys = []; for (key in obj) { if (obj.hasOwnProperty(key)) { keys[keys.length] = key; } } return keys; } function getAnnotation(status, type){ for(var i=0;i<status.annotations.length;i++){ var keys = getKeys(status.annotations[i]); for(var j=0;j<keys.length;j++){ if(keys[j] == type){ return status.annotations[i]; } } } } var ann = getAnnotation(status, "myAnnotationType"); There must be a better way! Is there? PS I can't use jquery or anything as this is js to be used in a caja widget and the container doesn't support external libs

    Read the article

  • How to set a default value in an IF snippet?

    - by kuti
    Hello, I have the following snippet in a bash script written in Solaris 10: printf "port(389)=" read PORT if [[ $PORT == "" ]]; then PORT=389 fi What I am trying to get that if the user hits the enter key, the Port should be set to 389. The snippet above does not seem to be working. Any suggestions?

    Read the article

  • How do I get callgrind to dump source line information?

    - by Jeremybub
    I'm trying to profile a shared library on GNU/Linux which does real-time audio processing, so performance is important. I run another program which hooks it up to the audio input and output of my system, and profile that with callgrind. Looking at the results in KCacheGrind, I get great information about what functions are taking up most of my time. However, it won't let me look at the line by line information, and instead says I need to compile it with debugging symbols and run the profiling again. The program which I am profiling is not compiled with debug symbols, but the library is. And I know this, because interestingly, source code annotations for cachegrind work fine. When I run callgrind, it says the default is to dump source line information, but it just isn't doing that. Is there some way I could force it to, or figure out what's stopping it?

    Read the article

  • Calculating bounding grid coordinates to a user click on google maps/google earth

    - by user170304
    Hello, I have a requirement to calculate the centroid or geodesic midpoint of when a user clicks in between the lat/long grid crossing. The crossing forms a square in most parts of GE and sometimes elongated rectangles. This is due to the shape of the earth of course. I'm looking for a valid mathematical formula that would allow a user to click anywhere in between this grid and then an accurate function (in Javascript or server side code) that would take an assumed grid resolution (say 1km intervals for this discussion) and the input coordinates that should return a centroid coordinate within that graticule grid. To clarify please take a look at the attached image to my google group post: http://google-earth-api.googlegroups.com/web/Picture+5.png?gda=h5oFPz8AAAD315KpovipQeBwdfGpmW3ZhBc9PTADwYa-n193hZ6AItFmHuno63c7phcEXYVuRA6ccyFKn-rNKC-d1pM%5FIdV0&gsc=sz6bbAsAAABBKF7YXWYyc4GmXg-QruHj What I need to be able to do is if a user clicks anywhere in this grid square, I need to find the centroid or center point of that grid intersection/square or at least the bounding grid coordinates (that make the square). If we assume that the grid is UTM standard and has a max resolution of 1km (or make this a parameter), I need to detect the four other points nearby and then calculating the centroid is not as difficult. I welcome any feedback you all may have and appreciate it. I don't have a simple way of letting a user click anywhere on the grid and finding the grid bounding coordinates (making a square of 4 coordinates) or the centroid / midpoint of the graticule grid square necessary. One thought is to use assumptions as much as possible using a reference such as UTM coordinate reference. If I assume that the grid is X degrees wide, can we have a pure javascript function take any input coordinate and return for me the bounding graticule coordinates in Decimal Degrees? Another thought I had was to create the grid in a geo-spatial layer to take any input coordinate and return the nearest centroid of the graticule? Does this make sense? Thanks! Omar

    Read the article

  • Appdomain recycle settings on mod_mono & Apache

    - by Radu094
    How does one control the application recycle settings for an ASP.NET application runnin on mod_mono & Apache ? On IIS6 & 7 there was an option to specify either a time period, a number of requests, etc. when the AppDomain would be recycled and the application would basically do an Application_End() / Application_Start(). I am seeing the same behaviour on mod_mono & Apache ,but I can't find where to change the settings.

    Read the article

  • How do i create a portable app (runs without installing)

    - by jiewmeng
    how do i create an app that is: lightweight: i am guessing don't require .NET frameworks maybe? portable: runs without installing and saves data in the app directory, so i can just move the folder or maybe even the exe? this is just a personal experiment: i want to try create a simple todo list app that has the above attributes i am thinking C#/WPF (but requires .NET framework, i can explore client profile tho) Appcelerator Titanium (i think this will be lightweight & good enough? i dunno if i can have a portable titanium app tho)

    Read the article

  • Simple animation using C#/Windows Forms

    - by clintp
    I need to knock out a quick animation in C#/Windows Forms for a Halloween display. Just some 2D shapes moving about on a solid background. Since this is just a quick one-off project I really don't want to install and learn an entire new set of tools for this. (DirectX dev kits, Silverlight, Flash, etc..) I also have to install this on multiple computers so anything beyond the basic .Net framework (2.0) would be a pain in the arse. For tools I've got VS2k8, 25 years of development experience, a wheelbarrow, holocaust cloak, and about 2 days to knock this out. I haven't done animation since using assembler on my Atari 130XE (hooray for page flipping and player/missile graphics!) Advice? Here's some of the things I'd like to know: I can draw on any empty widget (like a panel) by fiddling with it's OnPaint handler, right? That's how I'd draw a custom widget. Is there a better technique than this? Is there a page-flipping technique for this kind of thing in Windows Forms? I'm not looking for a high frame rate, just as little flicker/drawing as necessary. Thanks. Post Mortem Edit ... "a couple of coding days later" Well, the project is done. The links below came in handy although a couple of them were 404. (I wish SO would allow more than one reply to be marked "correct"). The biggest problem I had to overcome was flickering, and a persistent bug when I tried to draw on the form directly. Using the OnPaint event for the Form: bad idea. I never got that to work; lots of mysterious errors (stack overflows, or ArgumentNullExceptions). I wound up using a panel sized to fill the form and that worked fine. Using the OnPaint method is slow anyway. Somewhere online I read that building the PaintEventArgs was slow, and they weren't kidding. Lots of flickering went away when I abandoned this. Skip the OnPaint/Invalidate() and just paint it yourself. Setting all of the "double buffering" options on the form still left some flicker that had to be fixed. (And I found conflicting docs that said "set them on the control" and "set them on the form". Well controls don't have a .SetStyle() method.) I haven't tested without them, so they might be doing something (this is the form): this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); So the workhorse of the code wound up looking like (pf is the panel control): void PaintPlayField() { Bitmap bufl = new Bitmap(pf.Width, pf.Height); using (Graphics g = Graphics.FromImage(bufl)) { g.FillRectangle(Brushes.Black, new Rectangle(0, 0, pf.Width, pf.Height)); DrawItems(g); DrawMoreItems(g); pf.CreateGraphics().DrawImageUnscaled(bufl, 0, 0); } } And I just called PaintPlayField from the inside of my Timer loop. No flicker at all.

    Read the article

  • Flex 3 Close UrlLoader throws exception

    - by gmoniey
    I am trying to simulate a 'HEAD' method using UrlLoader; essentially, I just want to check for the presence of a file without downloading the entire thing. I figured I would just use HttpStatusEvent, but the following code throws an exception (one that I can't wrap in a try/catch block) when you run in debug mode. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()"> <mx:Script> <![CDATA[ private static const BIG_FILE:String = "http://www.archive.org/download/gspmovvideotestIMG0021mov/IMG_0021.mov"; private var _loader:URLLoader; private function init():void { _loader = new URLLoader(); _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, statusHandler); _loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler); _loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler); _loader.load(new URLRequest(BIG_FILE)); } public function unload():void { try { _loader.close(); _loader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, statusHandler); _loader.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler); _loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler); } catch(error:Error) { status.text = error.message; } } private function errorHandler(event:Event):void { status.text = "error"; unload(); } private function statusHandler(event:HTTPStatusEvent):void { if(event.status.toString().match(/^2/)) { status.text = "success"; unload(); } else { errorHandler(event); } } ]]> </mx:Script> <mx:Label id="status" /> I tried using ProgressEvents instead, but it seems that some 404 pages return content, so the status event will correctly identify if the page exists. Anyone have any ideas?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >