Search Results

Search found 4243 results on 170 pages for 'bool'.

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

  • determining True/False.

    - by sil3nt
    Hi there, the following code #include <iostream> using namespace std; int main(){ char greeting[50] = "goodmorning everyone"; char *s1 = greeting; char *s2 = &greeting[7]; bool test = s2-s1; cout << "s1 is: " << s1 << endl; cout << "s2 is: " << s2 << endl; if (test == true ){ cout << "test is true and is: " << test << endl; } if (test == false){ cout<< "test is false and is: " << test << endl; } return 0; } outputs: s1 is: goodmorning everyone s2 is: ning everyone test is true and is: 1 here what does the line bool test = s2-s1; actually evaluate?, is it the length of the string?. If so, then seeing as s2 is a smaller than s1 it should be negative correct?, and yet the output is true?. Also if i change it to bool test = s1-s2; I still end up with the same result. So it doesnt matter whether its negative or positive the it will be true? and only false when 0?. what does the s2-s1 mean? -cheers (trying to get rid of doubts:))

    Read the article

  • Cleanup vs Dispose(bool) in MVVM-light

    - by Budda
    In the lastest version of MVVM-light (V3 SP1) both "Dispose()" and "Dipose(bool)" methods in ViewModel class are marked Do not use this method anymore, it will be removed in a future version. Use ICleanup.Cleanup() instead Does this mean that IDisposable interface must not be implemented in all ViewModel classes that are derived from GalaSoft.MvvmLight.ViewModelBase (and cleanup must be overrided)? If yes, using can't be used for view-model instances... Probably I didn't understand something... Please clarify... What are the benefits of such cleaning up? Thanks.

    Read the article

  • Python MQTT: TypeError: coercing to Unicode: need string or buffer, bool found

    - by user2923860
    When my python code tries to connect to the MQTT broker it gives me this Type Error: Update- I added the Complete Error Traceback (most recent call last): File "test.py", line 20, in <module> mqttc.connect(broker, 1883, 60, True) File "/usr/local/lib/python2.7/dist-packages/mosquitto.py", line 563, in connect return self.reconnect() File "/usr/local/lib/python2.7/dist-packages/mosquitto.py", line 632, in reconnect self._sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0)) File "/usr/lib/python2.7/socket.py", line 561, in create_connection sock.bind(source_address) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) TypeError: coercing to Unicode: need string or buffer, bool found The code of the python file is: #! /usr/bin/python import mosquitto broker = "localhost" #define what happens after connection def on_connect(rc): print "Connected" #On recipt of a message do action def on_message(msg): n = msg.payload t = msg.topic if t == "/test/topic": if n == "test": print "test message received" # create broker mqttc = mosquitto.Mosquitto("python_sub") #define callbacks mqttc.on_message = on_message mqttc.on_connect = on_connect #connect mqttc.connect(broker, 1883, 60, True) #Subscribe to topic mqttc.subscribe("/test/topic", 2) #keep connected while mqttc.loop() == 0: pass I have no idea why its giving me this it work 2 days ago.

    Read the article

  • Better way to clean this messy bool method

    - by Luís Custódio
    I'm reading Fowler Clean Code book and I think that my code is a little messy, I want some suggestions: I have a simple business requirement that is return the date of new execution of my Thread. I've two class fields: _hour and _day. If actual day is higher than my _day field I must return true, so I'll add a month to "executionDate" If the day is the same, but the actual hour is higher than _hour I should return true too. So I did this simple method: private bool ScheduledDateGreaterThanCurrentDate (DateTime dataAtual) { if (dateActual.Day > _day) { return true; } if (dateActual.Day == _day && dateActual.Hour > _hour) { return true; } if (dateActual.Day == _day && dateActual.Hour == _hour) if (dateActual.Minute>0 || dateActual.Second>0) return true; return false; } I'm programming with TDD, so I know that the return is correct, but this is bad maintain code right?

    Read the article

  • Having a problem with simple bool

    - by Code
    Hi guys, I've some really simple code that checks if my bool is == YES but it does not ever enter. NSLog(@"boool %d",self.arrayAlreadyPopulated ); if (self.arrayAlreadyPopulated == YES) { Match *aMatch = [appDelegate.matchScoresArray objectAtIndex:(numMatchCounter)]; aMatch.teamName1 = TeamNameHolder; } else { Match *aMatch = [[Match alloc] init]; aMatch.teamName1 = TeamNameHolder; [appDelegate.matchScoresArray addObject:aMatch]; [aMatch release]; } The debug at the top says that the value of self.arrayAlreadyPopulated is 1 on the 2nd pass as it should be. But it never enters the first first part but jumps down to the 'else' I cant see for the life of me what the problem is. -.- Anybody able to clue me in? Thanks -Code EDIT declaration code int theCounterCauseABoolWontWork; @property (nonatomic) int theCounterCauseABoolWontWork; @synthesize theCounterCauseABoolWontWork;

    Read the article

  • How to check a bool setting in my iphone app

    - by dusk
    I have a setting in Root.plist with Key = 'latestNews' of type PSToggleSwitchSpecifier and DefaultValue as a boolean that is checked. If I understand that correctly, it should = YES when I pull it in to my code. I'm trying to check that value and set an int var to pass it to my php script. What is happening is that my boolean is either nil or NO and then my int var = 0. What am I doing wrong? int latestFlag; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; BOOL latestNews = [prefs boolForKey:@"latestNews"]; if (latestNews) latestFlag = 1; else latestFlag = 0; NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.mysite.com/folder/iphone-test.php?latest=%d", latestFlag]; NSURL *url = [[NSURL alloc] initWithString:urlstr]; //these are auto-released NSString *ans = [NSString stringWithContentsOfURL:url]; NSArray *listItems = [ans componentsSeparatedByString:@","]; self.listData = listItems; [urlstr release]; [url release];

    Read the article

  • Best way to represent Bit Arrays in C#??

    - by divinci
    Hi all, I am currently building a DHCPMessage class in c#. RFC is available here : http://www.faqs.org/rfcs/rfc2131.html Pseudo public object DHCPMessage { bool[8] op; bool[8] htype; bool[8] hlen; bool[8] hops; bool[32] xid; bool[16] secs; bool[16] flags; bool[32] ciaddr; bool[32] yiaddr; bool[32] siaddr; bool[32] giaddr; bool[128] chaddr; bool[512] sname; bool[1024] file; bool[] options; } If we imagine that each field is a fixed length bit array, what is : The most versitile Best practice way of representing this as a class??? OR.. how would you write this? :)

    Read the article

  • binding a usercontrol to the opposite of a bool property

    - by SnOrfus
    Pretty straightforward: I'm looking to do the same as this but in winforms. Everything that google seems to pull up is wpf specific (ie. I don't want to reference presentationframework.dll) Explained if you don't want to read the link: The following is a representation of the intent of what I'd like to do, though it obviously doesn't work. CheckBox1.DataBindings.Add(new Binding("Checked", this.object, "!SomeBool"));

    Read the article

  • IPhone sdk stop the accelerometer from working when something happens.

    - by Harry
    Hi, I am using the accelerometer to move a few UIImageViews around the screen, at the moment the accelerometer only works when a NSTimer is at 0, this is fine. I would also like to make the accelerometer stop again when a different function happens. here is my code at the moment: -(BOOL) accelerometerWorks { return time == 0; } -(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{ if(![self accelerometerWorks]) return; valueX = acceleration.x*25.5; int newX = (int)(ball.center.x +valueX); if (newX 320-BALL_RADIUS) newX = 320-BALL_RADIUS; if (newX < 0+BALL_RADIUS) newX = 0+BALL_RADIUS; int XA = (int)(balloonbit1.center.x +valueX); if (XA 320-BALL_RADIUS) XA = 320-BALL_RADIUS; if (XA < 0+BALL_RADIUS) XA = 0+BALL_RADIUS; int XB = (int)(balloonbit2.center.x +valueX); if (XB 320-BALL_RADIUS) XB = 320-BALL_RADIUS; if (XB < 0+BALL_RADIUS) XB = 0+BALL_RADIUS; int XI = (int)(balloonbit3.center.x +valueX); if (XI 320-BALL_RADIUS) XI = 320-BALL_RADIUS; if (XI < 0+BALL_RADIUS) XI = 0+BALL_RADIUS; int XJ = (int)(balloonbit4.center.x +valueX); if (XJ 320-BALL_RADIUS) XJ = 320-BALL_RADIUS; if (XJ < 0+BALL_RADIUS) XJ = 0+BALL_RADIUS; int XE = (int)(balloonbit5.center.x +valueX); if (XE 320-BALL_RADIUS) XE = 320-BALL_RADIUS; if (XE < 0+BALL_RADIUS) XE = 0+BALL_RADIUS; int XF = (int)(balloonbit6.center.x +valueX); if (XF 320-BALL_RADIUS) XF = 320-BALL_RADIUS; if (XF < 0+BALL_RADIUS) XF = 0+BALL_RADIUS; int XH = (int)(balloonbit8.center.x +valueX); if (XH 320-BALL_RADIUS) XH = 320-BALL_RADIUS; if (XH < 0+BALL_RADIUS) XH = 0+BALL_RADIUS; ball.center = CGPointMake (newX, 429); balloonbit1.center = CGPointMake (XA, 429); balloonbit2.center = CGPointMake (XB, 426); balloonbit3.center = CGPointMake (XI, 410); balloonbit4.center = CGPointMake (XJ, 415); balloonbit5.center = CGPointMake (XE, 409); balloonbit6.center = CGPointMake (XF, 427); balloonbit8.center = CGPointMake (XH, 417); } This all works fine, i would now like to stop the accelerometer from working, using the same accelerometerWorks method or a new method, accelerometerWontWork. This is the code that when it is called i would like the accelerometer to stop. (it is very long so i wont put all of it there, but its all the same throughout): -(void) checkCollision{ if (CGRectIntersectsRect(pinend.frame, balloonbit1.frame)){ if (balloonbit1.frame.origin.y pinend.frame.origin.y){ [maintimer invalidate]; levelfailed.center = CGPointMake (160, 235); } } if (CGRectIntersectsRect(pinend.frame, balloonbit2.frame)){ if (balloonbit2.frame.origin.y pinend.frame.origin.y){ [maintimer invalidate]; levelfailed.center = CGPointMake (160, 235); } } if (CGRectIntersectsRect(pinend.frame, balloonbit3.frame)){ if (balloonbit3.frame.origin.y pinend.frame.origin.y){ [maintimer invalidate]; levelfailed.center = CGPointMake (160, 235); } } } I understand that i may have to turn this into a BOOL. Thats fine. If i haven't explained it well please say and i will re write it. Thanks! Harry.

    Read the article

  • Cannot implicity convert type void to System.Threading.Tasks.Task<bool>

    - by sagesky36
    I have a WCF Service that contains the following method. All the methods in the service are asynchrounous and compile just fine. public async Task<Boolean> ValidateRegistrationAsync(String strUserName) { try { using (YeagerTechEntities DbContext = new YeagerTechEntities()) { DbContext.Configuration.ProxyCreationEnabled = false; DbContext.Database.Connection.Open(); var reg = await DbContext.aspnet_Users.FirstOrDefaultAsync(f => f.UserName == strUserName); if (reg != null) return true; else return false; } } catch (Exception) { throw; } } My client application was set to access the WCF service with the check box for the "Allow generation of asynchronous operations" and it generated the proxy just fine. I am receiving the above subject error when trying to call this WCF service method from my client with the following code. Mind you, I know what the error message means, but this is my first time trying to call an asynchronous task in a WCF service from a client. Task<Boolean> blnMbrShip = db.ValidateRegistrationAsync(FormsAuthentication.Decrypt(cn.Value).Name); What do I need to do to properly call the method so the design time compile error disappears? Thanks so much in advance...

    Read the article

  • Extract information from a Func<bool, T> or alike lambda

    - by Syska
    I''m trying to build a generic cache layer. ICacheRepository Say I have the following: public class Person { public int PersonId { get; set; } public string Firstname { get; set; } public string Lastname { get; set; } public DateTime Added { get; set; } } And I have something like this: list.Where(x => x.Firstname == "Syska"); Here I want to extract the above information, to see if the query supplied the "PersonId" which it did not, so I dont want to cache it. But lets say I run a query like this: list.Where(x => x.PersonId == 10); Since PersonId is my key ... I want to cache it. with the key like "Person_10" and I later can fetch it from the cache. I know its possible to extract the information with Expression<Func<>> but there seems to be a big overhead of doing this (when running compile and extract the Constant values etc. and a bunch of cache to be sure to parse right) Are there a framework for this? Or some smart/golden way of doing this ?

    Read the article

  • What is the point of Convert.ToDateTime(bool)?

    - by Paul Alan Taylor
    I was doing some type conversion routines last night for a system I am working on. One of the conversions involves turning string values into their DateTime equivalents. While doing this, I noticed that the Convert.ToDateTime() method had an overload which accepted a boolean parameter. First question? Under what circumstances could this ever be useful? I went a little further and tried to execute the method in QuickWatch. Either way ( true or false ), the routine returns an InvalidCastException. Second question? Why is this method even here?

    Read the article

  • Passing a bool condition to method which I can invoke when I need

    - by dotnetdev
    Hi, I need to pass in a predicate which I can invoke whenever I want (just like a delegate). I am trying to do something like this (I thought Predicate delegate would meet my needs): MyMethod(Predicate,string pred); Called like: MyMethod(s = s.Length 5); I want to write the condition inline BUT invoke it when I want, just like a delegate. How could I do this? Thanks

    Read the article

  • array loop not working correctly? c++

    - by igor
    Trying to count how many elements within the array are not equal to 0, is something set up wrong? I'd like to check all values in the array (it's a sudoku board) and then when all elements are "full" I need to return true. Is something off? bool boardFull(const Square board[BOARD_SIZE][BOARD_SIZE]) { int totalCount=0; for (int index1 = 0; index1 < BOARD_SIZE; index1++) for (int index2 = 0; index2 < BOARD_SIZE; index2++){ if(board[index1][index2].number!=0) totalCount++; } if(totalCount=81) return true; else return false;

    Read the article

  • Why overload true and false instead of defining bool operator?

    - by Joe Enos
    I've been reading about overloading true and false in C#, and I think I understand the basic difference between this and defining a bool operator. The example I see around is something like: public static bool operator true(Foo foo) { return (foo.PropA > 0); } public static bool operator false(Foo foo) { return (foo.PropA <= 0); } To me, this is the same as saying: public static implicit operator bool(Foo foo) { return (foo.PropA > 0); } The difference, as far as I can tell, is that by defining true and false separately, you can have an object that is both true and false, or neither true nor false: public static bool operator true(Foo foo) { return true; } public static bool operator false(Foo foo) { return true; } //or public static bool operator true(Foo foo) { return false; } public static bool operator false(Foo foo) { return false; } I'm sure there's a reason this is allowed, but I just can't think of what it is. To me, if you want an object to be able to be converted to true or false, a single bool operator makes the most sense. Can anyone give me a scenario where it makes sense to do it the other way? Thanks

    Read the article

  • Errors not printing correctly..Is this logic flow correct? c++

    - by igor
    Example user input: PA1 9 //correct PJ1 9 //wrong, error printed "Invalid row" because it is not between A and I PA11 9 //wrong, error printer "Invalid column" because it is not between 1 and 9. The problem I am having is that it should clear the remaining input and then ask for the user to enter the "move" again, and it is not. Where did I go wrong? I've been at it for a while and still got no progress.. void clearInput() { cin.clear(); } bool getCoords(int & x, int & y) { char row; while(true){ cin>>row>>y; row=toupper(row); if(/*(id=='P' || id=='p' || id=='D' || id=='d') && */row>='A' && row<='I' && isalpha(row) && y>=1 && y<=9){ x=row-'A'; y=y-1; return true; } else if(!(y>=1 && y<=9)){ cout<<"Invalid column\n"<< endl << endl; cout<<y; clearInput(); cout<<y; //return false; } else{ cout<<"Invalid row\n"<< endl << endl; clearInput(); //cout<<x<<y; //return false; } } }

    Read the article

  • Why .NET Boolean has TrueLiteral and TrueString?

    - by user309937
    Why in Boolean type there are two fields with the same value? internal const int True = 1; internal const int False = 0; internal const string TrueLiteral = "True"; internal const string FalseLiteral = "False"; and public static readonly string TrueString; public static readonly string FalseString; static Boolean() { TrueString = "True"; FalseString = "False"; } in reflector generated code, methods don't use those strings but: public string ToString(IFormatProvider provider) { if (!this) { return "False"; } return "True"; } would't it be better to use those const values?

    Read the article

  • Python operators returning ints

    - by None
    Is there any way to have Python operators line "==" and "" return ints instead of bools. I know that I could use the int function (int(1 == 1)) or add 0 ((1 == 1) + 0) but I was wondering if there was an easy way to do it. Like when you want division to return floats you could type from __future__ import division. Is there any way to do this with operators returning ints? Or could I make a class extending __future__._Feature that would do what I want?

    Read the article

  • Which MySQL Datatype to use for storing boolean values from/to PHP?

    - by Beat
    Since MySQL doesn't seem to have any 'boolean' datatype, which datatype do you 'abuse' for storing true/false information in MySQL? Especially in the context of writing and reading from/to a PHP-Script. Over time I have used and seen several approaches: tinyint, varchar fields containing the values 0/1, varchar fields containing the strings '0'/'1' or 'true'/'false' and finally enum Fields containing the two options 'true'/'false'. None of the above seems optimal, I tend to prefer the tinyint 0/1 variant, since automatic type conversion in PHP gives me boolean values rather simply. So which datatype do you use, is there a type designed for boolean values which I have overlooked? Do you see any advantages/disadvantages by using one type or another?

    Read the article

  • Forcing value to boolean: (bool) makes warning, !! doesnt.

    - by Newbie
    I like (bool) way more, but it generates warnings. How do i get rid off the warnings? I have code like: bool something_else = 0; void switcher(int val = -1){ if(val != -1){ something_else = (bool)val; }else{ something_else ^= 1; } } Should i just do it like everyone else and use '!!' or make it somehow hide the warning messages when using (bool) ? Or is '!!' actually faster than (bool) ? I would like to use (bool) and so i have to hide the warning, but how?

    Read the article

  • C#: Using as bool? instead of object something = ViewState["hi"]

    - by Programmin Tool
    So I'm going through old code (2.0) and I came across this: object isReviewingValue = ViewState["IsReviewing"]; if (isReviewingValue is bool) { return (bool)isReviewingValue; } My first thought was to us the "as" keyword to avoid the unneeded (bool)isReviewingValue; But "as" only works with non value types. No problem, I just went ahead and did this: bool? isReviewingValue= ViewState["IsReviewing"] as bool?; if (isReviewingValue.HasValue) { return isReviewingValue.Value; } Question is: Besides looking a bit more readable, is this in fact better?

    Read the article

  • Return enum instead of bool from function for clarity ?

    - by Moe Sisko
    This is similar to : http://stackoverflow.com/questions/2908876/net-bool-vs-enum-as-a-method-parameter but concerns returning a bool from a function in some situations. e.g. Function which returns bool : public bool Poll() { bool isFinished = false; // do something, then determine if finished or not. return isFinished; } Used like this : while (!Poll()) { // do stuff during wait. } Its not obvious from the calling context what the bool returned from Poll() means. It might be clearer in some ways if the "Poll" function was renamed "IsFinished()", but the method does a bit of work, and (IMO) would not really reflect what the function actually does. Names like "IsFinished" also seem more appropriate for properties. Another option might be to rename it to something like : "PollAndReturnIsFinished" but this doesn't feel right either. So an option might be to return an enum. e.g : public enum Status { Running, Finished } public Status Poll() { Status status = Status.Running; // do something, then determine if finished or not. return status; } Called like this : while (Poll() == Status.Running) { // do stuff during wait. } But this feels like overkill. Any ideas ?

    Read the article

  • When and why you should use void (instead of i.e. bool/int)

    - by Jonas
    I occasionally run into methods where a developer chose to return something which isn't critical to the function. I mean, when looking at the code, it apparently works just as nice as a void and after a moment of thought, I ask "Why?" Does this sound familiar? Sometimes I would agree that most often it is better to return something like a bool or int, rather then just do a void. I'm not sure though, in the big picture, about the pros and cons. Depending on situation, returning an int can make the caller aware of the amount of rows or objects affected by the method (e.g., 5 records saved to MSSQL). If a method like "InsertSomething" returns a boolean, I can have the method designed to return true if success, else false. The caller can choose to act or not on that information. On the other hand, May it lead to a less clear purpose of a method call? Bad coding often forces me to double-check the method content. If it returns something, it tells you that the method is of a type you have to do something with the returned result. Another issue would be, if the method implementation is unknown to you, what did the developer decide to return that isn't function critical? Of course you can comment it. The return value has to be processed, when the processing could be ended at the closing bracket of method. What happens under the hood? Did the called method get false because of a thrown error? Or did it return false due to the evaluated result? What are your experiences with this? How would you act on this?

    Read the article

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