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

Creating jQuery global variables for input form validation

I have what I believe to be a simple question, but I'm stuck: I am trying to validate a credit card number in an input field. I have a switch statement which picks up the type of credit card, and executes a validation function depending on the card…
cs_stackX
  • 1,407
  • 2
  • 19
  • 27
0
votes
2 answers

Using variables in an array passed to a def - Rails

I'm using the Google charts API to generate a pie chart in my Rails application. However, I'm having a problem passing local variables to the def in the helper. The def takes a 2D array of [label, value] pairs. It doesn't like it when I try to…
Ryan
  • 557
  • 10
  • 18
0
votes
2 answers

accessing local var value from JS function in PHP

After searching for internet and even here for 5 hours, i am still stuck at getting value of a local variable in a function and sending it to PHP. I have tried different syntaxes but none of them seems to be working. This code below, takes an input…
user2119249
0
votes
3 answers

Memory Management : scope and local pointer variable

Memory Management : scope and local pointer variable Q. In terms of Memory Management, What is the error in the following code? char* secret_message() { char message_buffer[100]; char* text = "Hey man!"; int n = 0; while (text[n] !=…
user2172254
0
votes
1 answer

Why is there a difference in giving values to global javascript objects locally?

Please explain why changing a global objects string property in local scope does affect the property in a global scope but giving a new value to the whole object doesn't. In my example, the first time I run changeMyName function, I get what I'm…
0
votes
1 answer

Using useDelimiter to divide data from txt file

I have a data in a text file which is in format: AB-9, Gregson, Brian, R T, Mr I want to divide the up into and store the first one, AB-9, in a local variable, I have done all of that but the problem currently is that when I print the value of id,…
0
votes
2 answers

Maintain Array value with a recursive javascript function

I have a program that we use at my work, which outputs its data in to XML files (several of them). I am trying to develop an HTA (yes an HTA, i'm sorry) to read these files and process their data. Unfortunately there are a number of XML files and I…
Josh
  • 3
  • 3
0
votes
2 answers

Setting a SQL local variable properly

I'm wondering if there is a way to have a local variable use the 'FROM' statement from a SELECT statement that is not declared in the 'SET' of the variable. I have the following example: DECLARE @IDNO int; DECLARE @ORDERQUANTITY int; SET @IDNO='1';…
kyle_13
  • 1,173
  • 6
  • 25
  • 47
0
votes
4 answers

Local variable not used

I am trying to make a test of whether an inputted word is a palindrome or not (the same spelled forward and backward). From what I can see it should work but Eclipse says "The value of the local variable isPalindrome is not used" , but it is used.…
Ferret9
  • 101
  • 1
  • 12
0
votes
1 answer

In Python IDLE 2.7, why is raw_input storing multiple values?

I'm trying to build a hangman game in Python, and I've set it repeat the input function if the user inputs a letter they've already tried. For some reason though, the "guess" variable stores every single value that I try, and I'm confused why this…
jtimmins
  • 367
  • 3
  • 13
0
votes
6 answers

Trouble with local variables in C#

I have a couple of variables that need to be assigned inside a for loop. Apparently, when the loop exits, C# ignores whatever happened in there, and the variables are returned to their original status. Specifically, I need them to be the last and…
Javier
  • 4,552
  • 7
  • 36
  • 46
0
votes
4 answers

Why does my view code use both an instance variable and a local variable?

I am looking at a book example. In the view section for a Products model, I see some code like this: <% @products.each do |product| %>
<%=…
Bohn
  • 26,091
  • 61
  • 167
  • 254
0
votes
2 answers

Is memory of local function variables cleared on function end?

Consider the following situation.. $var = 'Lots of information'; function go($var) { // Do stuff } Now, when PHP exits the function, does it clear the memory automatically of all local variables within the function or should I be…
Brett
  • 19,449
  • 54
  • 157
  • 290
0
votes
1 answer

Passing Variable to Partial - Page Displays symbol instead of string

Here is the code in my view to call the partial: <%= render :partial => "/divbox", :locals => { :smush => "Science" } %> and now here is what's in _divbox.html.erb:

<%= :smush %>

I expect HTML output of:

Science…

0
votes
1 answer

shared partials error undefined method `empty?' for nil:NilClass

I've create a partial (views/cart/_cart.html.erb) for my applications shopping cart. I'm rendering it in only in my views/layouts/application.html.erb file. But when I run it I'm getting a NoMethodError on every page other than the…