• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=Klownox;25088342][code]int code = 0; if(telephoneBox.getState()) code = 1; else if(inStoreBox.getState()) code = 2; else if(outsideBox.getState()) code = 3; [/code][/QUOTE] The second else isn't paired with any if. What you are doing is this [code] if |-else |-if else |-if[/code] That is to say, you need to turn each else .. if to elseif and/or put their content in a block (Inside {}, that is) [editline]06:14PM[/editline] Oh wow, that was confusing. [code] if (a) b; elseif (c) d; elseif (e) f;[/code]
[QUOTE=esalaka;25088406]The second else isn't paired with any if. What you are doing is this [code] if |-else |-if else |-if[/code] That is to say, you need to turn each else .. if to elseif and/or put their content in a block (Inside {}, that is) [editline]06:14PM[/editline] Oh wow, that was confusing. [code] if (a) b; elseif (c) d; elseif (e) f;[/code][/QUOTE] Tried that out, still not having any luck.. [code] public int getCode() { int code = 0; if (telephoneBox.getState()) { code = 1; } else if (inStoreBox.getState()) { code = 2; } else if (outsideBox.getState()) { code = 3; } return code; } [/code]
This is something simple as I'm just learning vb. All I want to do is check to see if an online file exists (.txt file) Any real simple way to do this? Thankyou. :smile:
[QUOTE=Klownox;25088709]Tried that out, still not having any luck..[/QUOTE] The else if should still be replaced with elseif...
[QUOTE=Snakess;25088715]This is something simple as I'm just learning vb. All I want to do is check to see if an online file exists (.txt file) Any real simple way to do this? Thankyou. :smile:[/QUOTE] I can't quite remember, but I think that there's a function called FileExists in VB. [editline]11:45AM[/editline] [QUOTE=esalaka;25088743]The else if should still be replaced with elseif...[/QUOTE] Okay, and then it throws this at me. I'm guessing I need to make a method called elseif(if I'm understanding it correctly). [IMG]http://imgur.com/FUFMY.png[/IMG] [code] public int getCode() { int code = 0; if (telephoneBox.getState()) { code = 1; } elseif (inStoreBox.getState()) { code = 2; } elseif (outsideBox.getState()) { code = 3; } return code; } [/code]
Can't find it All it needs to do, for example, is check that; [url]www.example.com/test.txt[/url] exists then if exist ** else ** etc. I am hopeless at vb. :saddowns:
I don't know what the exact code is, but look at the WebClient class. I think trying to download the file should tell you whether it exists or not. Seems like a crap solution though, so... sorry
[QUOTE=Klownox;25088756]Okay, and then it throws this at me. I'm guessing I need to make a method called elseif(if I'm understanding it correctly).[/QUOTE] Seriously, [B]Java has no elseif?!?[/B] Okay, then you just put each if in the parent else-block like this [code] if () { else { if { else { } } } }[/code]
no, 'else if' is correct java syntax, don't confuse the poor boy
[QUOTE=shill le 2nd;25090511]no, 'else if' is correct java syntax, don't confuse the poor boy[/QUOTE] I've never programmed java :saddowns: [editline]08:35PM[/editline] Besides, why didn't it work if it is valid syntax, I'm confus
C also does not know elseif. That's something you do know.
If i remember correctly java uses: [CODE]If(A==A) { Do one; }else if(A==B) { Do two; }else if(A==C) { Do three; }else { Do default; } [/CODE]
[QUOTE=esalaka;25090562]I've never programmed java :saddowns: [editline]08:35PM[/editline] Besides, why didn't it work if it is valid syntax, I'm confus[/QUOTE] Because "elseif" is not "else if". Because of the way the Java compiler works, the if is regarded as one line and you can leave out the parentheses. [code] if(something) { //do something } else if(somethingelse) { //do something else } [/code] Is parsed into [code] if(something) { //do something } else { if(somethingelse) { //do something else } } [/code]
Is that the same way that C / C++ / C# and so on do it as well? That's something I've always thought about (or at least a few times)
[QUOTE=Chris220;25090751]Is that the same way that C / C++ / C# and so on do it as well? That's something I've always thought about (or at least a few times)[/QUOTE] Not sure about C and C++, but with C# that's definitely how it works. (That's the net result anyway, it might be optimized somehow behind the scenes)
[QUOTE=ZeekyHBomb;25090605]C also does not know elseif. That's something you do know.[/QUOTE] I never knew this.
Whoa! I never knew it worked like that.
[QUOTE=PvtCupcakes;25083193]Sounds like you have memory errors. I've seen a few bugs like that, and after running my program through valgrind and fixing all the memory errors the bug went away.[/QUOTE] Thanks, found it. It was an uninitialized value created by a stack allocation. I knew this was going to be trouble; I'm trying to mix recursion and inheritance.
[QUOTE=Chris220;25090751]Is that the same way that C / C++ / C# and so on do it as well? That's something I've always thought about (or at least a few times)[/QUOTE] C++ does it the same way as Java The only language i have ever used that used elseif (all together) was VB
[QUOTE=Richy19;25091484]C++ does it the same way as Java The only language i have ever used that used elseif (all together) was VB[/QUOTE] PHP has elseif, as does Perl.
Lua has elseif and python has elif. I really think "else if" makes perfect sense though. "else" executes the next block if the previous comparison was false, and if the next block just happens to be another "if" conditional it's exactly the same as nesting the two. i.e. shorthand for: [code] if (a) { } else if (b) { } /* is the same as */ if (a) { } else { if (b) { } }[/code] The addition of a specific "elseif"/"elif"/"elsif" keyword seems redundant.
[QUOTE=ROBO_DONUT;25091691]Lua has elseif and python has elif. I really think "else if" makes perfect sense though. "else" executes the next block if the previous comparison was false, and if the next block just happens to be another "if" conditional it's exactly the same as nesting the two. i.e. shorthand for: [code] if (a) { } else if (b) { } /* is the same as */ if (a) { } else { if (b) { } }[/code] The addition of a specific "elseif"/"elif"/"elsif" keyword seems redundant.[/QUOTE] That's exactly what I said a couple posts up.
[QUOTE=arienh4;25091732]That's exactly what I said a couple posts up.[/QUOTE] Pfft. Reading is for squares. :c00l: Regardless, it's a good point that deserves reiterating.
[QUOTE=ROBO_DONUT;25091767]Pfft. Reading is for squares. :c00l: Regardless, it's a good point that deserves reiterating.[/QUOTE] It makes sense in languages with blocks similar to C. But elseif is hardly redundant in Lua, Python and the like that use different system for blocks.
So, theoretically, this should work? [code] public int getCode() { int code = 0; if (telephoneBox.getState()) { code = 1; } else if (inStoreBox.getState()) { code = 2; } else if (outsideBox.getState()) { code = 3; } return code; } [/code]
[QUOTE=Klownox;25093415]So, theoretically, this should work? [code] public int getCode() { int code = 0; if (telephoneBox.getState()) { code = 1; } else if (inStoreBox.getState()) { code = 2; } else if (outsideBox.getState()) { code = 3; } return code; } [/code][/QUOTE] Apparently yeah. But if it doesn't, try doing as I posted... Somewhere above. If even that doesn't work, it's not that code that is wrong :|
[QUOTE=esalaka;25093521]Apparently yeah. But if it doesn't, try doing as I posted... Somewhere above. If even that doesn't work, it's not that code that is wrong :|[/QUOTE] Ugh, this is so frustrating.
[QUOTE=Klownox;25093726]Ugh, this is so frustrating.[/QUOTE] Are you sure the GetState method works properly ?
[QUOTE=pikzen;25094195]Are you sure the GetState method works properly ?[/QUOTE] Well, it works for telephoneBox and inStoreBox :tinfoil:
It seems to work too good for inStoreBox :v: What happens if you check inStoreBox.getState first?
Sorry, you need to Log In to post a reply to this thread.