Daily Archives

Articles indexed Saturday May 29 2010

Page 30/76 | < Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >

  • using switch in strings

    - by xtemer
    guys me trying to use switch in strings by first coverting string into char and then apply switch but still didnt done it....here is my code..help me out.. import javax.swing.*; import java.io.*; class HappyBirthday { public static void main(String[] args) throws IOException { String Month; char[] Months = Month.toCharArray(); BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter your month."); Month = JOptionPane.showInputDialog("enter month"); String month1={"January","feb"}; char[] month2 = month1.toCharArray(); // String s=month1.equals(Month); //System.out.print(month2Array[0]); switch (month2) { case 0: System.out.println("kool"); break; case 1: System.out.println("not kool"); break; default: }}} /** if (month1[1].equals(Month)) System.out.println("kool"); else if(month1[0].equals(Month)) System.out.println("kooooooooooooool"); else System.out.println("Big kooooool"); **/

    Read the article

  • Can I ignore a SIGFPE resulting from division by zero?

    - by Mikeage
    I have a program which deliberately performs a divide by zero (and stores the result in a volatile variable) in order to halt in certain circumstances. However, I'd like to be able to disable this halting, without changing the macro that performs the division by zero. Is there any way to ignore it? I've tried using #include <signal.h> ... int main(void) { signal(SIGFPE, SIG_IGN); ... } but it still dies with the message "Floating point exception (core dumped)". I don't actually use the value, so I don't really care what's assigned to the variable; 0, random, undefined... EDIT: I know this is not the most portable, but it's intended for an embedded device which runs on many different OSes. The default halt action is to divide by zero; other platforms require different tricks to force a watchdog induced reboot (such as an infinite loop with interrupts disabled). For a PC (linux) test environment, I wanted to disable the halt on division by zero without relying on things like assert.

    Read the article

  • Why does Scala apply thunks automatically, sometimes?

    - by Anonymouse
    At just after 2:40 in ShadowofCatron's Scala Tutorial 3 video, it's pointed out that the parentheses following the name of a thunk are optional. "Buh?" said my functional programming brain, since the value of a function and the value it evaluates to when applied are completely different things. So I wrote the following to try this out. My thought process is described in the comments. object Main { var counter: Int = 10 def f(): Int = { counter = counter + 1; counter } def runThunk(t: () => Int): Int = { t() } def main(args: Array[String]): Unit = { val a = f() // I expect this to mean "apply f to no args" println(a) // and apparently it does val b = f // I expect this to mean "the value f", a function value println(b) // but it's the value it evaluates to when applied to no args println(b) // and the evaluation happens immediately, not in the call runThunk(b) // This is an error: it's not println doing something funny runThunk(f) // Not an error: seems to be val doing something funny } }   To be clear about the problem, this Scheme program (and the console dump which follows) shows what I expected the Scala program to do. (define counter (list 10)) (define f (lambda () (set-car! counter (+ (car counter) 1)) (car counter))) (define runThunk (lambda (t) (t))) (define main (lambda args (let ((a (f)) (b f)) (display a) (newline) (display b) (newline) (display b) (newline) (runThunk b) (runThunk f)))) > (main) 11 #<procedure:f> #<procedure:f> 13   After coming to this site to ask about this, I came across this answer which told me how to fix the above Scala program: val b = f _ // Hey Scala, I mean f, not f() But the underscore 'hint' is only needed sometimes. When I call runThunk(f), no hint is required. But when I 'alias' f to b with a val then apply it, it doesn't work: the evaluation happens in the val; and even lazy val works this way, so it's not the point of evaluation causing this behaviour.   That all leaves me with the question: Why does Scala sometimes automatically apply thunks when evaluating them? Is it, as I suspect, type inference? And if so, shouldn't a type system stay out of the language's semantics? Is this a good idea? Do Scala programmers apply thunks rather than refer to their values so much more often that making the parens optional is better overall? Examples written using Scala 2.8.0RC3, DrScheme 4.0.1 in R5RS.

    Read the article

  • character to the corresponding virtual-key code in c#

    - by kambamsu
    Hi, Currently, i'm using the method "VkKeyScan" in the win32 api to convert a character to its virtual keycode. But the problem that this seems to have is that, when i pass small alphabets, it works fine whereas when i pass in a capital alphabet, it doesnt return the appropriate keycode and similarly with special characters like "(" or "}" .. How do i do this? Is there anyway for me to directly convert a string to its virtual equivalent without considering whether it contains capitalized or special characters? Thanks

    Read the article

  • When do I need to use automatic poperties and when properties with propertychanged event ?

    - by Honey
    Hello, I am using wpf and its C sharp! I have this in my Animal.cs clas private string _animalName; public string AnimalName { get { return _animalName; } set { if(_animalName!= value) { _animalName= value; this.NotifyPropertyChanged("AnimalName"); } } } I could also write: public string AnimalName {get;set;} There is no difference in binding and validation. Everythings works as before when I exchange the code. Is this due to the fact that I only create new animals but I do not allow to update the animals name in my application ? So I need to call the propertyChanged("AnimalName"); only when I want to change its property value? I am a c# beginner ;)

    Read the article

  • Interpreter typing in C

    - by typus
    I'm developing an interpreter and I have some questions to it. I recently saw a small C interpreter that used a very simple struct like the below for all its objects/values in the language: struct Object { ubyte type; ubyte value; }; This struct can hold strings, integers, bools and lists (I think) used in the language the interpreter is working with. How can you get this Object struct to hold all these types?

    Read the article

  • CopyLzfileName/CreatLZFileName..what does LZ means?

    - by kiddo
    I am gathering small information regarding kernel dll functions..and I found this function called CopyLZFileName/CreateLZFileName and some other functions related to this LZ..I googled for it..I cant find a proper source for it.From the name I guess it copies/creates file but am not sure what kind of file..does LZ mean something to it.Please let me know.

    Read the article

  • Android Full Text Search

    - by Eduardo
    Does Android come with a way to do Full Text Search? I know is it not even possible to search contacts by the notes field, being Google the search company, but I would be disappointed if there is no API for that.

    Read the article

  • Permits in iPhone apps

    - by zp26
    HI, I want to create i file in the iPhone application. I try it but i have a anomaly. In my pc the file is correctly written. In other pc with the same program the file wasn't exist. In the iPhone device the file not exist. But the strange think thing is that i haven't any error for the app in the all case. Do you have a idea? Thanks so much

    Read the article

  • change all the label icon in a panel

    - by Josh
    I have a panel with several JLabel, I would like to change all their Icon, String path = System.getProperty("user.dir"); for (int x=0;x< 21;x++) { javax.swing.JLabel lab = boardPanel.getComponent(x).; lab.setIcon(new ImageIcon(path + "\\image\\blank.jpg")); } it gives me an error of incompatible type, all inside the boardPanel are JLabel, im using netbeans 6.8.

    Read the article

  • Checking that all libs and dlls are from the same build?

    - by unknownthreat
    I am developing a program in VS C++ 2008. Right now, I have a huge list of dll and lib dependencies and I am adding some more. I worry that when I need to update a dependency by building from source (where I have to manually replace built dlls and libs in the correct place), if I accidently forgot to replace something or vice versa, I may run into a compile and/or runtime problem. And finding which place goes wrong can be a bit difficult. So is there some sort of program or method out there that can suit this task to ease building a program with many updating dependencies?

    Read the article

  • Jquery: change event not triggered in IE

    - by Kenneth
    Hi, I have some code updating a dropdownlist, and then I fire the "change" event manually. It works like it should in firefox, opera and so on, but not in Internet Explorer. Any idea why? Code attached below. $(".bringFraktvalgRadio").click(function() { var selectedValue = $(".bringFraktvalgRadio:checked").val(); $("#<%= dropDeliveryOption.ClientID %> option[value=" + selectedValue + "]").attr("selected", true); $("#<%= dropDeliveryOption.ClientID %>").trigger("change"); });

    Read the article

  • how to: handle exceptions, best practices

    - by b0x0rz
    need to implement a global error handling, so maybe you can help out with the following example... i have this code: public bool IsUserAuthorizedToSignIn(string userEMailAddress, string userPassword) { // get MD5 hash for use in the LINQ query string passwordSaltedHash = this.PasswordSaltedHash(userEMailAddress, userPassword); // check for email / password / validity using (UserManagementDataContext context = new UserManagementDataContext()) { var users = from u in context.Users where u.UserEMailAdresses.Any(e => e.EMailAddress == userEMailAddress) && u.UserPasswords.Any(p => p.PasswordSaltedHash == passwordSaltedHash) && u.IsActive == true select u; // true if user found return (users.Count() == 1) ? true : false; } } and the md5 as well: private string PasswordSaltedHash(string userEMailAddress, string userPassword) { MD5 hasher = MD5.Create(); byte[] data = hasher.ComputeHash(Encoding.Default.GetBytes(userPassword + userEMailAddress)); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { stringBuilder.Append(data[i].ToString("x2")); } Trace.WriteLine(String.Empty); Trace.WriteLine("hash: " + stringBuilder.ToString()); return stringBuilder.ToString(); } so, how would i go about handling exceptions from these functions? they first one is called from the Default.aspx page. the second one is only called from other functions from the class library. what is the best practice? surround code INSIDE each function with try-catch surround the FUNCTION CALL with try-catch something else?? what to do if exceptions happen? in this example: this is a user sign in, so somehow even if everything fails, the user should get some meaningful info - along the lines: sign in ok (just redirect), sign in not ok (wrong user name / password), sign in not possible due to internal problems, sorry (exception happened). for the first function i am worried if there is a problem with database access. not sure if there is anything that needs to be handled in the second one. thnx for the info. how would you do it? need specific info on this (easier for me to understand), but also general info on how to handle other tasks/functions. i looked around the internet but everyone has different things to say, so unsure what to do... will go with either most votes here, or most logicaly explained answer :) thank you.

    Read the article

  • GTK+ Compile Error

    - by Alon
    When trying to compile GTK+ with target for DirectFB, it throws: configure: error: conditional "XINPUT_NONE" was never defined. Usually this means the macro was only invoked conditionally. Any ideas? Thanks.

    Read the article

  • JSP Upload File Java.lang.NullPointer

    - by newbie123
    I want to develope upload and download file from server. Upload.html <form action="/UploadFile/UploadFile" method="POST" enctype="multipart/form-data">Select a file: <input type="submit" name="button" /> <input type="file" name="first"></form> UploadFile.servlet protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String temp = request.getParameter("first"); System.out.println(temp); File origFile = new File(temp); FileOutputStream out = new FileOutputStream(request.getContextPath() + "pdtImages/" + "FirstFile"); InputStream ins = new FileInputStream(origFile); try { System.out.println(request.getContextPath()); byte[] buf = new byte[1024]; int len; while ((len = ins.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } When I submitted the file I got null pointer error message. I not very familiar with jsp can anybody help me? I want to store the file to the server directory.

    Read the article

  • Custom xsl rendering for lookup field in list view (SharePoint 2010)

    - by Luc
    I'm trying to change rendering of a list column on list view page. After a few tutorials and some hair pulling I managed to create an xslt for a calculated and currency field (from fldtypes_XXXXXX.xsl): <xsl:template match ="FieldRef[@Name='MarkCalc']" mode="Text_body"> <xsl:param name="thisNode" select="."/> <xsl:value-of select="$thisNode/@*[name()=current()/@Name]" disable-output-escaping ="yes"/> </xsl:template> <xsl:template match="FieldRef[@Name='CurrencyTest']" mode="Number_body"> <xsl:param name="thisNode" select="."/> <b><xsl:value-of disable-output-escaping="yes" select="$thisNode/@*[name()=current()/@Name]" /></b> </xsl:template> Then I tried to do the same for a lookup field, but it just won't work. This is my last attempt (I copied it from SharePoint designer). What am I missing? <xsl:template match="FieldRef[(@Encoded) and @Name='Lookup1']" mode="Lookup_body"> <xsl:param name="thisNode" select="."/> <b><xsl:value-of select="$thisNode/@*[name()=current()/@Name]" disable-output-escaping="yes" /></b> </xsl:template>

    Read the article

< Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >