Questions tagged [local-variables]

Local variables have a limited scope, generally one function or one functional block.

Local variables have a limited scope, generally one function or one functional block.

Compare with global variables, which are accessible from any part of a program.

1302 questions
0
votes
2 answers

Actionscript 3.0, using FlashDevelop: local variables. Can they be mistakenly created ad infinitum?

Riddle me this: I have my MouseEvent.MOUSE_DOWN which calls mouseHandler. The latter looks something like this: public function mouseHandler(evt:MouseEvent):void { var p:Point = new Point(mouseX, mouseY); var objs:Array = new…
0
votes
2 answers

Javascript Local Variable Not Updated

I have coded this function to detect and update postLat and postLon variables. function searchAddSubmit(){ var shopId = 1; //random number to test the function var postLon, postLat; var shopTime =…
Robert Sim
  • 194
  • 3
  • 13
0
votes
2 answers

In Lua, should a functions arguements be (re)localised in the function?

Consider: function function_name(var_one, var_two) var_one = var_two return var_one end print( function_name("string_one", "string_two") ) As appose to local var_one = var_two Is var_one now a global variable or is it still in the…
user805687
0
votes
1 answer

T-sql use local variable like a as clause

I want to use that i declare local variable like a as clause, for example i get last year and current year declare @lastYear varchar(4)=datepart(YEAR,DATEADD(year,-1,GETDATE())); declare @currentYear…
enginocal
  • 309
  • 1
  • 5
  • 19
0
votes
2 answers

How to create variables from arguments in python

I want to make a function in python were one of the arguments is a variable later... as an example it should be like this foo=myfunction("var1","var2",otherarguments) (note that var1 and var2 are string never used before) then the program should…
0
votes
1 answer

UnboundLocalError: local variable "xyz" referenced before assignment

UPDATE: In response to Wooble's comment, adding a "sector = None" before the for simply returns "None". I think the issue is that the variable in the for loop is not being returned. The following is part of a function that was running fine, until…
snakesNbronies
  • 3,619
  • 9
  • 44
  • 73
0
votes
1 answer

Datagrid multitrigger referencing values from code-behind

I'm still bloody green in WPF and have not yet fully grasped the concept behind it. I've got the following problem: I want to set triggers in a datagrid depending on a precondition. Example: In my code-behind, I have a string variable, let's call…
tcm1211
  • 25
  • 5
0
votes
1 answer

Access private members of local objects (of same class type)

I need to access the private members of a local object from a member function. The example explains it better I think. Is there a way to do this without making *a public, or without providing a function specifically for assigning to *a ? This…
xst
  • 2,536
  • 5
  • 29
  • 41
-1
votes
2 answers

Java - How to use changing/modified variables in several methods in a class?

The idea of local variables is a little hard to understand when I want one method to initialize a variable and another method to use that initialized variable. Example public class abc public int startAngle; public void angleMethod(){ startAngle =…
-1
votes
0 answers

Terraform Error: Cycle - Dependency issue?

enter code hereI have an issue with my Terraform config for GCP resources. I have an InstanceTemplate, MIG, LB. I am looking to pass the LB Frontent IP to the metadata of the Instance being created during the initial terraform apply but the Cycle…
-1
votes
2 answers

UnboundLocalError: local variable 'x' referenced before assignment in python (bilinear interpolation)

import cv2 as cv import numpy as np def twirl(img,xc,yc,alpha,r_max): height=img.shape[0] width=img.shape[1] transformed=np.copy(img) for x_prime in range(img.shape[0]): for y_prime in range(img.shape[1]): …
-1
votes
1 answer

My method isn't working although no error messages are shown

I need to write a method that needs to output a certain string an amount of times that equals to a variable in the main class. I wrote it with the for loop but it isn't outputting anything nor is it showing any errors. (method must contain local…
Bake
  • 1
  • 1
-1
votes
2 answers

Does a function's local array remain preserved after the execution of the function is finished in C?

I have declared and initialized a (dynamic?) array inside a bool function, as seen in this simple example below. I'm using the same function to populate it. I don't want the array to remain preserved in the computer's memory once the function's…
-1
votes
1 answer

How to use local, non-local and global variables in the same inner function without errors in Python?

When trying to use the local and non-local variables x in inner() as shown below: x = 0 def outer(): x = 5 def inner(): x = 10 # Local variable x += 1 print(x) nonlocal x # Non-local variable …
-1
votes
2 answers

What is the exact names of three kinds of variable in shell script? (Global Environment vs Global vs Local)

I read a lot of explanation of kinds of variable in bash shell script. But I still confused because people uses mixed terminology for the same thing. From my knowledge there are three kinds of variable even though I don't know exact official term…
myoldgrandpa
  • 871
  • 7
  • 21