return-value

Mysql Stored Procedures - Returning Message

It's a bit silly asking homework questions here, however I'm genuinely stumped as to what this question is asking. Create a stored procedure to add results. The procedure should take four (4) parameters. These are; The student's name (first and last), the name of the apparatus and the score. When the data has been inserted,...

In Java, How do I return a String or a double depending on the circumstance of the method? Is it possible?

For example, I have a method that looks through a string for data separated by a specified deliminator, but some items might be a names, and other items might be numbers. If a user calls my method to return item number X from the deliminated list, i want it to return a string if item X is a name, or a double if item X is a number. For ...

JAVA: What do the return values mean for ArrayIndexOutOfBoundsException exceptions?

When my program throws the exception, i'm getting a return value of 7. What exactly does a 7 mean, and where can I get a list of these return values? Or is that just the first line where it happened (although i got a -1 one time)? Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at DataReader.get(DataReader.ja...

Python function prints None

I have the following exercise: The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return True if we sleep in. Here's what I've done, but the second print function only prints 'None'. def sleep_in(weekday, vac...

Python - Function has a list as argument. How to return another list without changing the first?

I'm pretty new in Python (and programming as a whole). I'm pretty sure the answer to this is obvious, but I really don't know what to do. def do_play(value, slot, board): temp=board (i,j) = slot temp[i][j] = value return temp board is a list of lists. value is an integer. slot is and integer tuple. What I am trying to...

call svn as a subprocess to check out source code and expect returns

hi, guys, if i use python write a script to call svn as a subprocess to checkout source code, e.g. p = subprocess.Popen("svn checkout file:///tmp/repos/test mine"), what is the return value of the success or failure of svn-checkout subprocess? Thanks ...

Should I return null or throw an exception?

I found questions here http://stackoverflow.com/questions/175532/return-null-or-throw-exception and http://stackoverflow.com/questions/1626597/should-functions-return-null-or-an-empty-object, but I think my case is quite different. I'm writing an application that consists of a webservice and a client. The webservice is responsible to ac...

best way to return an std::string that local to a function

In C++ what is the best way to return a function local std::string variable from the function? std::string MyFunc() { std::string mystring("test"); return mystring; } std::string ret = MyFunc(); // ret has no value because mystring has already gone out of scope...??? ...

Does C# support multiple return values?

The noob here again. This is a very basic question, and if what I am thinking of doing is complicated/involved, then I don't expect you to go into detail... I've read that this may involve structs or hash or some other scary procedure I've not gotten to yet. If so, I'm sure it'll get me soon. Working on learning classes, methods, and re...

Calling a non-void function without using its return value. What actually happens?

So, I found a similar question here, but the answers are more about style and whether or not you are able to do it. My question is, what actually happens when you call a non-void function that returns an object, but you never assign or use said returned object? So, less about whether or not you can, because I absolutely know you can and...

Returning value from a function

const char *Greet(const char *c) { string name; if(c) name = c; if (name.empty()) return "Hello, Unknown"; return name.c_str(); } int _tmain(int argc, _TCHAR* argv[]) { cout << Greet(0) << '\t' << Greet("Hello, World") << endl; return 0; } I see 2 bugs with the above code. Returning c_str from...

Method return status: bool, string, const... (PHP)

Hi all! This question: http://stackoverflow.com/questions/356248/best-way-to-return-status-flag-and-message-from-a-method-in-java is similar to mine, however I would do it in PHP, not Java (which could make a slight difference here). The problem: There's a method that can have either a successful outcome (this may change to be more su...

Is there a cleaner way to write this? (Ruby/Rails blocks, return value)

def find_users_online(count = 1) users = Array.new count.times do users += get_users_online end users # <==== I want to remove this here end In the code above im must put the "users" variable again at the end of the function to return the right value (users). But is it possible that the times block ...

C# Call function in a class from another class

I'll start of by saying I'm not a developer. Yes this is a c# nightmare. But this is a one time tool and thats it. Quick and Dirty it just needs to work and thats it. I have the following code: public string[] get_status(string local_fname) { var dts_doc = new HtmlAgilityPack.HtmlDocument(); dts_doc.Load(...

Alternative to if statement in this simple example

if(metres >= 0) return true; else return false; Can I do this with a single calculation? (ignoring the ternary operator) ...

Is it ok to skip "return None"?

I wonder if it is bad manner to skip return None, when it is not needed. Example: def foo1(x): if [some condition]: return Baz(x) else: return None def foo2(x): if [some condition]: return Baz(x) bar1 = foo1(x) bar2 = foo2(x) In both cases, when condition is false, function will return with None....

How to return post results through function?

I am calling a function that returns the result of an ajax GET request using jQuery. How do you return its result through the function to the callee? function makePrPoContent(s_firstName, s_lastName, s_email){ $.get('/includes/snippets/privacy_policy.jsp', { firstName: s_firstName, lastName: s_lastName, email: s_e...

Why does invoking print in a subroutine append 1 to the string?

I have created the following subroutine gender to randomly print string MALE or FEMALE. When subroutine is invoked, the print command suffixes a "1" at the end of the string. See the sample code and output below: sub gender { if ( (int rand(100)) >50) { print "MALE "; } else { print "FEMALE"; } } fo...