FAQ Database Discussion Community


Batch Variable name and Percent sign

variables,batch-file,environment-variables,variable-scope
I have a variable named ABC SET ABC=Brazil I have another variable named DEF containing a string with the name of the first variable: SET "DEF=%%ABC%%" How can I access to the string "Brazil" by only using the variable DEF? (I can't use the variable ABC) If I use the...

Call model from within itself

php,laravel,variable-scope
I have a model in laravel and need to call it within itself to check if there already are entries. It's for a generic (polymorphic) case where I don't want to do it in the controller. This works just fine: $check = self ::where('foreign_id',$this->attributes['foreign_id']) ->where('foreign_type', $this->attributes['foreign_type']) ->where('category', $this->attributes['category']) ->orderBy('created_at','desc') ->first()...

CodeIgniter, pass data from model to controller to use in view

php,codeigniter,variable-scope,variable-assignment
I want to pass data queried in my model to the controller, to do so I am using return $data. Then in the controller I use $this->load->view('my_view', $data); From my understanding var_dump($data); in the view should show me the results from the query... This is not the case. I am...

Referring to session variables (\set var='value') from PL/PGSQL

postgresql,variable-scope,plpgsql,psql
I can pass variables into PostgreSQL using psql --variable="var='value'" <<<'SELECT :var' ...and refer to them as, in this case, :var in SQL queries passed to psql on stdin. However, this doesn't work from code using PL/PGSQL: psql --variable=var="'value'" <<'EOF' DO $$ BEGIN SELECT :var; END; $$ EOF ...yielding the error:...

How can I refer to a module variable in a function without referring to its module in Elixir 1.0.3? In its parent scope?

import,module,variable-scope,elixir
I'd like to make a function in Elixir 1.0.3 refer to a variable inside its "parent" scope. In this case, its parent scope is a module. Here's the same code as that which I used in my last question: defmodule Rec do def msgurr(text, n) when n <= 1 do...

python unboundLocalError why

python,variable-scope
import os def createFile(): if os.path.exists("highscores.txt") == False: myFile = open("highscores.txt","w") myFile.close() def inputInt(): number = input(str("please input your score ")) try: return int(number) except: print ("this is not an acceptable input, please try again") inputInt() def addScore(): name = input("Please enter the name you wish to add") score =...

How can I set the value of a variable passed into a function?

php,html,function,variable-scope
I am working on a page that allows the user to "upload" multiple files at once (they are stored locally in folders relative to their type). My problem is that when I try to pass $upFile1 and $fileInfo1 to writeResults() to update $fileInfo1 with information about $upFile1, the echoed result...

Xcode 6 variable inspector showing nil

objective-c,xcode,variable-scope
I've got something like this: NSArray* titleColors = @[defaultColorForTitles, defaultColorForTitles, defaultColorForTitles]]; If I NSLog it out, I get: 2015-02-09 15:26:21.984 project[27352:1574376] ( 6c6c6c, red, blue ) Yay! But if I set a breakpoint at the next line and hover over the variable, instead of seeing the array values (like I'd...

Changing the value of a variable after an event

javascript,variables,object,variable-scope,onchange
Right now in the below code the var selected doesn't change (it outputs the empty string i guess). I need you to help me change the selected variable so that the value should be the selected option all of the time (in the select element). I also want to be...

Should variables be declared inside the loop or outside the loop in java [duplicate]

java,performance,garbage-collection,variable-scope
This question already has an answer here: Declaring variables inside or outside of a loop 18 answers I know similar question has been asked many times previously but I am still not convinced about when objects become eligible for GC and which approach is more efficient. Approach one: for...

One all-encompassing definition of JavaScript closure

javascript,closures,variable-scope,scopes,lexical
I have read 10s of SO references on closures, MDN references and other blog articles. They all seem to define closures in their own ways. For example, From MDN documentation: function makeFunc() { var name = "Mozilla"; function displayName() { alert(name); } return displayName; } var myFunc = makeFunc(); myFunc();...

Javascript variable visibility

javascript,variables,global-variables,variable-scope
I'm new in javascript world. Reading about the variables scope and I think I got the idea behind. I did some experiments and I'm having a situation here which gives me unexpected results. Here's what I mean var x = 0; function set(){ x++; } set(); console.log(x) // 1 At...

What is the correct way to do this?

java,arrays,variable-scope
I know this must be a fundamental design problem because I clearly can't do this. I want to call the ownGrokk, ownTyce, etc methods from another class depending on the value of the integer assigned to OwnedSpirits(int). This in turn fills arrays. The problem is, I do this multiple times,...

class argument/variable scope application / argument result references in subsequent argument

ruby,class,scope,variable-scope
I'm tasked with making an interest calculator with class arguments, but I'm having a hard time applying variables/arguments. I keep getting an argument error (4 for 0). Moreover, how can I properly refer to the amount argument result in my `statement' argument? Any suggestions? Can anyone offer insight to help...

Give “x” on this.x a variable value when passing objects to an array

javascript,jquery,this,variable-scope
I have seen in multiple questions on Stackoverflow, that I can pass a variable to a this keyword: name = "world"; alert("Hello " + this.name); However, I am struggling with the following code: $('.test').click(function() { var data = $(this).data(); var type = data.type; $('#world-map-geo1').empty(); $.getJSON('json/geoCountries-' + site + '.json', function...

Why aren't instance variables defined in a controller's methods available in the corresponding partials?

ruby-on-rails,ruby,ruby-on-rails-4,variable-scope,partials
For example, given a basic controller such as: class PostsController < ApplicationController def index @post = Post.all end The instance variable @post is available in the view posts/index.html.erb but not the partial posts/_index.html.erb My primary questions are: Why is this? and How can I define a method for a partial...

Is it safe to return a passed-in temporary value and read from it in the same statement?

c++,variable-scope,undefined-behavior
I just wrote this without thinking too hard about it. It seems to work fine, but I'm not sure if it's strictly safe. class Foo { struct Buffer { char data [sizeof ("output will look like this XXXX YYYY ZZZZ")]; }; const char * print (const char * format =...

A require statement is overwriting global variables in lua

lua,include,variable-scope,require
Consider the following two files: a.lua function x() return 1 end -- return x b.lua function x() return 2 end print( x() ) local y = require "a" print( _G.x(), y ) print( x(), y() ) When I execute my b.lua I receive the following output: 2 1 function: 0024B710...

Is there a valid way of defining a variable within the condition statement of a conditional(if) structure?

javascript,variable-scope,variable-declaration
Is there a condensed way of defining a variable within the condition of an if statement in JavaScript? For example: var arr = [1,2,3]; console.log(len); // output is null, since it was never declared if ((var len = arr.length) > 0) { // len == 3 // logic using variable...

Appcelerator scope issue when clicking a view

javascript,variable-scope,appcelerator
I'm going crazy here trying o work out why the scoping of my variable won't pick up the right value from a loop of 60 items from a DB in my Appcelerator project. My map marker displays the correct label, but when I click it, no matter what combo of...

Dynamic vs. lexical scoping in JavaScript / loop confusion

javascript,for-loop,scope,variable-scope
I hit a subtle bug which has been distilled as follows: function huh() { for (var i = 0; i < 10; i++) { if ( i % 2 == 1 ) { var x = i; console.log(i + ' ' + x); } else { console.log(i + ' '...