w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Returning 'nil' from a Lua function in C vs returning 0 values
Yes, this is perfectly valid. If you're trying to request/assign more return values than there are (no matter whether you try to get one or ten), you'll get nil for the undefined ones (i.e. those not returned). function test1() return 5 end local a, b = test1() -- a = 5, b = nil function test2() return 1, 2 end local c, d, e = test2() -- c = 1, d = 2, e = nil function test3() end local f, g = test3() -- f = nil, g = nil You probably can't find it in Lua's source because it's no special case or anything. It's just Lua's generic way to handle return values. Update: The difference you've noticed when trying to print return values is the fact that this is not just an assignment. Of course there is a slight difference between returning nil and returning nothing at all - and it

Categories : C

Returning values from two tables based on a third "key" table, then multiplying values and summing products
I recommend that you create a procedure that uses a cursor to accomplish your goal. Iterating over one of the three tables, it should be a pretty straightforward process. MySQL Cursors: http://dev.mysql.com/doc/refman/5.0/en/cursors.html Edit: The following stored MySQL script creates and calls a stored procedure that correctly reproduces the results you're looking for: DELIMITER $$ DROP PROCEDURE IF EXISTS `computeBuyouts` $$ CREATE PROCEDURE `computeBuyouts` () BEGIN DECLARE done INT DEFAULT FALSE; DECLARE o, b VARCHAR(32); DECLARE bc FLOAT; DECLARE cur CURSOR FOR SELECT Owner,Buyer FROM Buyout; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur; read_loop: LOOP FETCH cur INTO o, b; IF done THEN LEAVE read_loop; END IF; SET bc = 0; -- compute the sum

Categories : Mysql

for loop returning unexpected values when squaring values
You iterate over the list by using for elem in testList, which yields elements of the list and not their indices. >>> b = [1, 3, -4, 5, 5, 3, 2, 1, 4, 8, 9] >>> for i in b: print i, 1 3 -4 5 5 3 2 1 4 8 9 # Whereas you expected 0 1 2 3 4 5 6 7 8 9 10 So, your code fetches the elements using the values as the indices and returns the square of those values. This is what happens - >>> for index, val in enumerate(b): # enumerate yields an (index, value) tuple which gets unpacked. print '{0} : {1}*{1} = {2}'.format(index, val, val**2) 0 : 1*1 = 1 1 : 3*3 = 9 2 : -4*-4 = 16 3 : 5*5 = 25 4 : 5*5 = 25 5 : 3*3 = 9 6 : 2*2 = 4 7 : 1*1 = 1 8 : 4*4 = 16 9 : 8*8 = 64 10 : 9*9 = 81 Whereas in your initial code, the a list happens to be the indices you

Categories : Python

As we all know constructor is not having a returning type but in the code below constructor is returning...can any one explain
This: complex_1 complex_1::operator+(complex_1 c) is a definition of a class complex_1 member function (complex_1:: means this) that returns an object of type complex_1. c is not a constructor but an object of type complex_1 that is returned in this function.

Categories : C++

Why is this code seen as not always returning a value?
You should ALWAYS return a value, even if the code throws an exception, because you're using a method which returns a string and isn't a void method(which doesn't return anything) You should return a string between the Catch brackets.

Categories : C#

code always returning NAN
You are attempting to perform arithmetic calculations and comparisons using strings. NaN is "Not A Number", which is the numeric result of an arithmetic operation that fails (for example dividing by zero, or any calculation on NaN). Note the use of numbers, not strings, below: var employeeDisc = .10; var largeOrderDisc = .05; var contractorDisc = .20; var taxRate = .08; var noTax = 0; //Calculations if (orderAmount >= 800) { var discounta = orderAmount * largeOrderdisc; } else { var discounta = 0; } Additionally, prompt() will return a string. You should convert that to a number before performing your calculations. You probably want to use parseInt() or parseFloat(). Here is a simple example which produces NaN: var x = 'x5'; var y = '2'; var difference = x - y; console

Categories : Javascript

Returning Multiple Values From Map
Use Enumerable#flat_map b = [0, 3, 6] a = b.flat_map { |x| [x, x+1, x+2] } a # => [0, 1, 2, 3, 4, 5, 6, 7, 8]

Categories : Ruby

MYSQLI_QUERY not returning values
The problem is the assignment: $closedsales[$row['month']] = $row['total']; $closedsales is the result returned by mysqli_query, it's not an array you can assign to. Use a different variable for this.

Categories : PHP

returning Boolean values
This the ternary-operator, you can "translate" this expression almost 1:1 to C#. It is the same like if(ucvalue) return false; return true; From MSDN for C#: The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator. condition ? first_expression : second_expression; From here for C++: You can exchange simple if-else code for a single operator – the conditional operator. The conditional operator is the only C++ ternary operator (working on three values). Other operators you have seen are called binary operators (working on two values).

Categories : C#

How strcmp() is returning -1 even though the two values are same?
You have to give to strcmp two strings. A string is an array of char with the last value being . In your example, the second value you are passing it is just the address of a char and there is no string terminator so the function goes blindly ahead until it finds a 0 ( same thing as ). You should either use strcmp with a char vector like char ch[2] ( One value for the character you want and the other for the I mentioned earlier or, in your case you should just use the == operator since you want to compare only one character.

Categories : C

php array_search not returning values
Because file(): Returns the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached To prove this try the following: var_dump(array_search('Bob ', $usernameFileContent)); You could use array_map() and trim() to correct the behavior of file(). Or, alternatively, use file_get_contents() and explode().

Categories : PHP

Returning pairs of values
It's not clear whether you've actually tried creating a new object to return from the method each time. That would be my first attempt - if you're worried about the performance, you can tackle that when you've actually proved it's a problem. Create an immutable Point class (probably with equals and hashCode overridden for testing purposes - but beware of normal floating point issues) and an overridden toString method. It'll be pretty short, and should be your universal way of representing a point. Then your method signature looks a lot more sensible: public Point getNextPointOnPath() { ... } Any time you write a get method which has a void return type, you should be worried. The next option would be to create a mutable type containing a pair of floats. Pass a reference to an existi

Categories : Java

Returning from the top of the code in Java,How?
It seems like you want a loop: int selectedOption = JOptionPane.YES_OPTION; // by default while (selectedOption == JOptionPane.YES_OPTION) { // do your stuff selectedOption = JOptionPane.showConfirmDialog(null,"Continue?","Choose",JOptionPane.YES_NO_OPTION); }

Categories : Java

why is my php code returning a null value?
Trail and error debugging when the php code is sending you the null value.. i think you mean 0 with null? Because i think your code breaks here? catch (PDOException $ex) { $response["success"] = 0; $response["message"] = "Database Error. Couldn't add post!"; die(json_encode($response)); }

Categories : Java

why is my code returning nil in ruby?
In your initialize method, you're overwriting the hash that is passed into the function. def initialize(f) f = Hash.new @f = f end should be something like def initialize(f={}) @f = f end

Categories : Ruby On Rails

AS3 leaving and returning to the code
Not really a solution, but you can System.pause() the running application as long as it's in debug mode running in a debug player. You could just pause and resume your code when you like and trace/display the textfield with the data you want just before that.

Categories : Actionscript

for statement not returning values from array
Syntax error because you forgot a x. Change for (var x = 0; < vowel.length; x++) { to for (var x = 0; x < vowel.length; x++) {

Categories : Javascript

List comprehension returning values plus [None, None, None], why?
print is a function (in Python3). It prints something to the screen, but returns None. In Python2, print is a statement. [print(x) for x in g] would have raised a SyntaxError since only expressions, not statements, can be used in list comprehensions. A function call is an expression, which is why it is allowed in Python3. But as you can see, it is not very useful to use print in a list comprehension, even if it is allowed.

Categories : Python

returning values of functioncalls in a for loop
EUREKA! I think I've got the solution. The actual problem is not the Oberserverable pattern but the example case itself. Maybe I should do sth. like this: obj["on"+type] = function(e) { e = e || window.event; e.cancelBubble = bub; obj["e"+type].notify(e); if(typeof e.preventDefault == "function") { return e.preventDefault(); } }; And the other part simular to this: addEvent(document, "contextmenu", function(e) { document.defaultAction = false; if (e.preventDefault) e.preventDefault(); else e.preventDefault = function() { return false; }; if (e.stopPropagation) e.stopPropagation(); if (e.returnValue) e.returnValue = false; }); It seems

Categories : Javascript

R Optimization Returning Incorrect Values
Let's start with a slight rewrite of your code. I replaced one-column matrices with vectors. I also added an option for returning the error itself or its absolute value. You'll want to use the absolute value when trying to minimize the error with optim while you'll want the value itself when trying to find its root with uniroot. helper.post <- function(monthly.mean.return, start.capital, target.legacy, monthly.inflation.post, monthly.withdrawals, n.obs, return.abs = TRUE) { req <- numeric(n.obs + 1) req[1] <- start.capital for (month in 1:n.obs) { req[month + 1] <- req[month] * (1 + monthly.mean.retur

Categories : R

Returning values with a foreign key CakePHP
first of all, checking $this->Post->exists() with $user_id won't give you the wanted exception. I guess you want to check, if the User exists, use $this->Post->User->exists() instead. Second - check your Model namings and your relationships between them (in Category,Post,User - Model) You've somehow got a Posts and a Post Model in your SQL. I guess, you've added a 's' where it shouldn't be ;)

Categories : Cakephp

form dropdown not returning values
You have repeated field names in your form. Look at 112-24 CCC-241 Coke Coke Classic Cans 24/355ml cs, for example. Ensure that you have unique names, otherwise you'll override the values with an empty or hidden field. Also: it will simplify your life if you select shorter field names (preferably without spaces!)

Categories : PHP

Actionbar.getHeight() returning different values between API 16 and 17
Read it from: ?android:attr/actionBarSize Check this post for more information: What is the size of ActionBar in pixels?

Categories : Android

Request.Form returning no values
Alright, the solution was as simple as attaching the appropriate name onto the HTML DOM element. The final HTML ended up looking something like this: <div class="form_section" ID="Exhibitors" style="display:none;"> <div class='wExhibitor' data-bind="foreach: $root.exhibitors"> <h2>Exhibitor <span data-bind="text: $index() + 1"></span> Information</h2> <div class="eccform_section"> <div class="eccform_column"> <div class="eccform_label">First Name*</div> <div class="eccform_field"><input id="exFirstName" runat="server" class="exFirstName" title="First Name" data-bind="value:FirstName,attr:{name: 'exFirstName_'+$index()}" /></

Categories : C#

returning values greater than the target value
You can use a list comprehension approach: def countTarget2(myList, target): return len([element for element in myList if element > target]) print countTarget2([1,2,3,4], 2) # prints 2 UPD: This is actually a short form of: def countTarget2(myList, target): l = [] for element in myList: if element > target: l.append(element) return len(l) So, yes, there is an intermediate list - generator expression is a better choice.

Categories : Python

Variable not returning actual values
Create a class or struct with members you need public class Stat { public int Id { get; set; } public long Clicks { get; set; } ... } Change the signature of your method from void GetAdsStats to IEnumberable<Stat> GetAdsStats and either return a collection of stats or use yield keyword to return the stat object. Also if you do not want your method to return anything (return type void) do not use a name starting with Get. Example: public static IEnumerable<Stat> GetAdsStats(...) { ... var statList = new List<Stat>(); for (int i = 0; i < reklamos; i++) { var stat = new Stat(); statList.Add(stat); int dienos = kazkas.Ads[i].Days.Length; for (int lop = 0; lop < dienos; lop++) { AllClicks = A

Categories : C#

Paypal IPN Listener not returning values
I had to do this same thing, but in Web Forms. It should apply just the same since we're both dealing with HttpWebRequest objects. Look at the below code- this is my Page_Load() method of my listener URL (Listener.aspx.cs). Note the section that says if (strResponse == "VERIFIED") and look inside that where it says string[] responseArray = strRequest.Split('&'); - this is where you get all of your response variables. You will have to back track a little to the definition of strRequest which is being used to get the values (delimited by the ampersand). And also, look at the IPN response on your PayPal account. The response will be a long string delimited by ampersands- this will be the same value as strRequest. This is the string where you extract other information about the paym

Categories : C#

Returning all values from an array in an exercise
Use implode to turn your array back into a string, with first param serving as a separator. $points = implode(' ', $lukutaulukko);

Categories : PHP

returning values from python functions
Make sure you return fun2(...) and return fun1(...). Without the returns, Python functions return None by default. def fun1(val1, val2): val2 -= 1 if val2 > 0: print "val2: ", val2 return fun2(val1, val2) else: print "val2 ended" return val1 def fun2(val1, val2): val1 -= 1 if val1 > 0: print "val1: ", val1 return fun1(val1, val2) else: print "val1 ended" return val2 blah = fun1(10,8) print blah

Categories : Python

Qt frameGeometry is returning incorrect values
Only workaround I know and it seems to worked for me several times then I faced same issue was: pWidget->show(); pWidget->hide(); pWidget->whatever geometry method

Categories : Qt

Looking up values in cells from 2 different spreadsheets and returning a Y or N value
I don't know about vb, but the formula I'm pretty sure can be translated there. =VLOOKUP("*"&'Spreadsheet 1'!G2&"*",'Spreadsheet 2'!F:Y,20,0) To get a Y/N result: =IF(ISERROR(COUNTIF('Spreadsheet 2'!F:F, "*"&'Spreadsheet 1'!G2&"*")),"N","Y") Or using vlookup: =IF(ISERROR(VLOOKUP("*"&'Spreadsheet 1'!G2&"*",'Spreadsheet 2'!F:F,1,0)),"N","Y")

Categories : Excel

MySQL query though PHP not returning values
Try removing quotes. PDO does NOT replace given parameters if they are wrapped in quotationmarks. Example: $st = $db->prepare('INSERT INTO users ( name, surname ) VALUES( :name, ":surname" )'); $st->execute( array( ':name' => 'John', ':surname' => 'Carlo' ) ); Results: -> John, :surname You can also use debugDumpParams to see the parameters are either correct or not. http://www.php.net/manual/en/pdostatement.debugdumpparams.php

Categories : PHP

Linq to xml query not returning any values
You're not specifying the namespace in your Elements call. Fortunately this is easy in LINQ to XML: XNamespace ns = "http://schemas.microsoft.com/sharepoint/soap/directory/"; ... from el in root.Elements(ns + "User"); If you know that the ID attribute will always be an integer, I'd actually make that clear, and also avoid using a query expression when it doesn't help you: // TODO: Find a nicer way of doing this; you shouldn't need to parse it again XElement root = XElement.Parse(siteUsers.InnerXml); var siteUserElements = root.Elements(ns + "User") .Where(el => (int) el.Attribute("ID") == 814); foreach (XElement el in siteUserElements) { Console.WriteLine("el: " + el); }

Categories : C#

combine two methods returning two different values
You could create a method to execute any query using ado.net, for sample: private static T ExecuteQuery<T>(ContextObject contextObject, string query) { T result; using (SqlConnection con = con = new SqlConnection(contextObject.ConnectionString)) { try { con.Open(); using (SqlCommand cmd = cmd = new SqlCommand(query, con)) { result = (T)cmd.ExecuteScalar(); } } catch { result = null; } finally { con.Close(); } } returnr result; } And pass a query that return a single value (in sql we use TOP 1), something like this: var resultComment = ExecuteQuery<string>("SELECT TOP 1 Comments From dbo.Tran

Categories : C#

Returning Unique Values from an Array
You could try using this jquery function: http://api.jquery.com/jQuery.unique/ "The $.unique() function searches through an array of objects, sorting the array, and removing any duplicate nodes."

Categories : Javascript

My function is not returning all checked Values
I believe the problem you are having is that it is updating all, but only the last one is alive, because you continuously replace the html of .divNewCountriesList with your last response. You probably need to build an array/long string: var checkedItems = $("#checkboxes input:checked"); var productInputList = []; checkedItems.each(function (index,element) { manu = $(this).val(); alert("Brand value:" + manu); // Here I am getting only one Selected checkbox but not all. selectedBrands = selectedBrands + "," + manu; alert("Selected brands:" + selectedBrands); var productInput = ""; var myUrl = "/Countries/GetCountiresForManufacturer/" + selected + "/" + input; $.ajax({ url: myUrl, type: 'get', success: function (data) { pr

Categories : Javascript

Returning values between different scopes in javascript
This has nothing to do with scope, it is about timing. readdir is asynchronous. It sends off the request to the filesystem and then lets the previous function carry on. console.log(b); executes before b=self.loader() does. If you want to work with data from a function that takes a callback, you need to perform that work inside the callback.

Categories : Javascript

Returning code block in Scala
First of all. Don't use return, its semantics is completely different in Scala than in Java or Groovy. The Unit type isn't a synonym for anonymous function. It's more like a indication of side-effects. The type for an anonymous function is () => A. In your case you want a function that doesn't return any thing, but causes a side-effect. So its type should be () => Unit. Let's see some code: def makeCounter : () => Unit = { var x = 0 { () => x = x + 1 } } val counter = makeCounter counter(); counter(); counter() Great! We made makeCounter give us a fresh counter! There is only one problem. x is a local variable in the method makeCounter and since it's never returned we can't see its value! Ever! We could, for example, remove x from the method, making it public in

Categories : Scala

Stop returning to executing code
Assuming the problem is really what you described, then there are two things you could do (together) to address it: When you send an ajax request, you store the reference to that request. When you receive another keyup, cancel that ajax request. When you start executing the onEnter handler, set some variable to indicate that auto-suggestions are no longer needed. In the auto-suggest handler, after your ajax returns, only show the suggestions if that variable is not set. Essentially, your code structure would be like this (note that this is pseudocode and is not meant to be copied into your application): var ajaxReq == null; var needSuggestions = true; $('#textfield').on("keyup", function(e) { if(ajaxReq != null) { ajaxReq.abort(); ajaxReq = null; } if(k

Categories : Javascript

javascript code this is not returning true
The code within onreadystatechange is called an "event handler", and will execute only once your POST operation has finished. This is what your validatenewcat function is actually doing when you run it: var category = document.getElementById("cat").value; var url = "catnamecheck.do?id=" + category; xmlhttp.open("post", url, true); xmlhttp.send(null); xmlhttp.onreadystatechange = (code to be called later) return false; // <-- Always return false You need to move the code that requires the TRUE / FALSE result inside the onreadystatechange function, so that it is executed after the HTTP operation has finished: xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { var temp = xmlhttp.responseText; obj =

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.