FAQ Database Discussion Community


Full absolute path to file's parent directory in PHP

php,global-variables
I need to return full absolute path to file's parent directory by PHP, which should include protocol, domain address and path to the file. Purpose could be to automatically generate a link so it could be appended to social networks sharer link, regardless of site's domain migration. $_SERVER["HTTP_HOST"] will get...

What are the advantages to passing a global DB connection into each function of a model?

php,oop,dependency-injection,global-variables
I am working with an older code base that passed a db connection into most functions in each class of the models. The db connection is created as a global and passed everywhere in the application: $user = new User(); $user->loadById($db, $userId); What advantages do we get by doing this...

Allocation of global variables C++

c++,memory,global-variables
It seems unclear as to where global variables get stored when declared different ways and which way is best? For example, where are the variables stored in each example and what is their scope? //Example 1 (at the top of a cpp file): Rectangle rect(15,12); //Example 2: Rectangle *rect =...

How to import efficiently values in Python from a list of global variables in a C header file

python,header,global-variables,readfile
I would like to find an efficient and quick way to load the values of a list of global variables from a C header file into Python. For instance, suppose I have the file header.h: /* comments */ int param_nx=2049; // comment int param_ny=2049; // comment double param_dt=0.01; // comment...

Making a PHP variable global accross multiple web pages

php,global-variables
I'm fairly new to PHP so sorry if this is a naive question, but I want to build a php function library that utilizes a variable that is global across multiple pages. I'm using these 3 files to test: functions.php <?php function report() { echo "Value = ".$GLOBALS["var"]; } ?>...

unreported exception UnknownHostException; must be caught or declared to be thrown during global declaration

java,exception,jframe,global-variables,netbeans-8
I am trying to declare one global variable in a class, whenever i create simple variables like int i; , they are created easily, but when I try to create an object like Socket socket = new Socket("192.168.1.3",4917); it gives the error that I have mentioned. I know that its...

Export of PATH not permanent

linux,path,export,global-variables,environment-variables
I'm using this command to export the path to use some packages I installed globally. export PATH=~/.composer/vendor/bin:$PATH the problem is whenever I restart my machine, I would still need to export it again. Is there a way to make this export permanent?...

Side effect/ changing global varaibles that pass into a function

javascript,arrays,global-variables,variable-assignment
Forgive me if this question has been asked, but I can't seem to find it. I am attempting to create an array and reverse it (without using reverse) This bit of code works perfect: function reverseArrayInPlace(array) { for (var i = 0; i < Math.floor(array.length / 2); i++) { var...

Unexpected performance with global variables

c,pointers,gcc,global-variables
I am getting a strange result using global variables. This question was inspired by another question. In the code below if I change int ncols = 4096; to static int ncols = 4096; or const int ncols = 4096; the code runs much faster and the assembly is much simpler....

Static global C-like variables in Ruby

ruby,global-variables
Does Ruby has static global variables? With this I mean global variables only accessible from the file where they were defined....

Using and assign variables of other file (package) in go

mongodb,variables,go,global-variables
I have a http server using mongodb as a backend db, I wrapped the db operations in a separate file (package), and I don't want to make a connection every time, So I think make a global session and copy it like this maybe a good idea. So this is...

Global variable is not updating in python

python,global-variables
I have 3 files. globalVar.py global m_pTest m_pTest = None FileOne.py import globalVar import fileTwo m_pTest = Class.getOutput() # Value is assigne fileTwo.fun() #Do anything fileTwo.py import globalVar def fun(): intVal = m_pTest.getInt() # int value from m_pTest object print intVal This is my short program sample when i run...

Shared instance with global variables

ios,objective-c,static,singleton,global-variables
Thanks to some previous questions I managed to share global variables in my whole application. But still I'm wondering if what I've done is a good practice : GlobalVariables.h @interface GlobalVariables : NSObject @property (nonatomic, retain) NSMutableArray *eventType; @property (nonatomic, retain) NSMutableArray *docType; // Getters of properties + (NSMutableArray *)...

How do I organize input global variables?

c++,global-variables,config
In some spare time, I'm working on some physical simulation code so I a) have a framework to build off of in the future and b) keep myself fresh with C++. I have several values (speed of light, box size, number of particles, things like that) that very nearly every...

How could I use these local variables for object position in my main function?

c++,vector,global-variables,computer-vision,local-variables
I'm using some computer vision code in c++ that tracks an object after you draw a bounding box around it, and it can track multiple objects with multiple bounding boxes. In one of the header files there is a function that processes the frame and defines the objects center pixel...

Global variable and scope - R

r,function,scope,global-variables
I don't understand why a globally-scoped list in R, cannot be modified from within a function as follows: global <<- list() f <- function(x) { global[[x]] <- "blah" } f(1) f(2) print(global) The output is list() However, I was expecting the output: [[1]] [1] "blah" [[2]] [1] "blah" Why is...

Passing a reference of a global variable to a function

javascript,global-variables,parameter-passing
Is it possible to send a link to a global variable to a function in JavaScript? This guy says no. But I cannot believe, there is no workaround. What I mean is something like the following. It is not working, but it shall explain what I mean: var data_1; var...

munmap_chunck(): invalid pointer in c

c,pointers,memory-management,global-variables
I have a program that I've written to do some data analysis, and this data is stored in a global structure called P. I allocate the memory for this structure in one function and then, since I need it for the entire program, don't call free until the very end...

How should I declare global variables in my C++ project?

c++,c,include,global-variables,header-files
I have two matrices as global variables. However, when I run my project, I get a apache Mach-O linker error in xCode that says that my global variables are declared more than once. I've determined the problem to be the placement of my global variables and the imports of the...

Rails: How to change the variable in Application Controller

ruby-on-rails,model-view-controller,global-variables,applicationcontroller
In my application, I have Company, Division, Users.... Company - have many Divisions, Users - belongs to one or more Divisions. When user login, the current_division is set to User.division[0] in the Application_controller. I want to implement a feature where user can switch between different divisions. Any ideas about how...

Access to variable interval

javascript,angularjs,global-variables
How can i get qLength in this : var intervalPromise = $interval( function (){ $http.get(request).success(function (datatemp) { // Get Queue info JSON every 2s if (angular.equals(store.queues, datatemp)) { //if like the last, no change console.log('Same values'); qLength = store.queues.Jobs.length; } else { //Else, update store.queues = datatemp; console.log('Values updated') }...

Global variables in Android

android,global-variables,conventions
Is possible to define, in Android, variables that are shared between more Activities? I tried to use "special purpose" classes, but i was looking for the best-pratice. I already looked for similar questions, but i didn't find an exact answer to this question....

Difference between static and global variables

objective-c,global-variables,instance-variables,static-variables
What is the difference between the code below? @implementation MyClass static int myVar =0; int _myVar =0; I am getting same values for different objects of MyClass and both are visible to the all methods of MyClass......

Python, not able to append to a list from a recursive function

python,algorithm,recursion,data-structures,global-variables
I am in the mid-way of writing a code to find all possible solutions of a input similar like "a&b|c!d|a", where a,b,c,d all are booleans and &-and, |-or !-not are the operators. By solution I mean the set of values of these variables which makes the input expression give True....

Assigning UIColor values to macros

ios,objective-c,macros,global-variables,uicolor
This question refers to this SO post: How to set global variable with UIColor class The accepted answer suggests defining a macro like so: AppDelegate header: // AppDelegate.h #import <UIKit/UIKit.h> #define black = [UIColor blackColor] #define myColor = [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f] @interface AppDelegate : UIResponder <UIApplicationDelegate> @end ViewController...

distribution as global variable

c++,random,global-variables
In my project, I am trying to use a uniform distribution as a global variable. In one file (global.h), I write: #include <random> extern std::uniform_real_distribution<> sample; Then, in another file, I want to initialize it (set the parameters) with: #include "global.h" std::uniform_real_distribution<>::param_type Params(-0.3,0.3); sample.param(Params); But I get the following error...

c programming global variable updating

global-variables
iam new to c programming and written a function to swap two numbers.the problem is that inside swap function variables are getting updated correctly but the global variables a and b are not changing.Please help me with any misconception I have.Thanks for the help. int main(){ int a = 2;...

Multiple instances of static class in same process in C++

c++,class,static,global-variables
I'm working with a huge project written in C++ (moses, smt translation). The situation is that it stores initial settings in non-static class called "StaticData" with static field "instance" (StaticData.h). Any other class uses "StaticData.GetInstance()" to access current smt model settings. Now the question is: what would you do to...

Javascript global variables used as flags

javascript,loops,global-variables
I am trying to use global variables as flags and cant get it to work. I have two functions: This function sets a flag to be false when it is done. function buildYearsTable(btn) { //console.log ("At build years table") var fundCode = document.getElementById("fundCode").value buildYearsFlag = true; $.ajax({url: "/scholarship/scholarshipMaintenance/buildYearsTable", method: "POST",...

Javascript - Calling A Variable From Outside Of If/Else Block Returns Undefined

javascript,node.js,scope,global-variables
I thought this is how you make a variable inside a if/else block global (Case 3). connection.query(sql, function (err,rows){ //Handle Errors if(err){ //Log The Error & Die } //If Successful - Log Results For Now (Change To Export Results) else { //console.log(rows); foo = rows; } }); console.log(foo); // Out:...

How do I make a variable created inside a function become global?

python,function,global-variables
I have a function in a program that I`m working at and I named a variable inside this function and I wanted to make it global. For example: def test(): a = 1 return a test() print (a) And I just can`t access "a" because it keeps saying that a...

How to use a global string in Broadcast receiver?

android,broadcastreceiver,global-variables
How to use a global string in Broadcast receiver? What is wrong with sms variable? public class MainActivity extends Activity { String sms=""; //here is wrong??? TextView view = new TextView(this); Uri uriSMSURI = Uri.parse("content://sms/inbox"); Cursor cur = getContentResolver().query(uriSMSURI, null, null, null ,null); while (cur.moveToNext()) { if(cur.getString(13).startsWith("\n ")){ sms +=cur.getString(13)+"\n";...

Declaring global char array in C header file

c,global-variables
I have a header file that contains all the string command as shown below: const char AT_RSSI[] = "ATRSSI\r\n"; const char AT_DEVICE_SECURITY[] = "ATDS"; But, using this method each of char sentence is appended with \0 at the end and this is inconvenient as I need to remove 1 char,...

Java EE application and “global” variables

java,java-ee,glassfish,global-variables
we have a Java EE application with primefaces and we are wondering if there's a way to have a "global" application variable. I mean: imagine user1 is editing document1, when user2 try to access document1 we'd like to show a message: "User1 is already editing this document". So, we have...

Python: Unable to import global variable initialized in setUp method from init file

python,scope,global-variables,python-unittest
I have a package with testing modules and inside the init file I have a setUp method with some operations. These operations are executed correctly before any unit test in the package's modules run. Inside the setUp method I'd like to initialize a global variable and then access it from...

On declaring variables as global gives different answers

c++,variables,global-variables,fibonacci
I have two similar codes Code1: #include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int fib(long long int n) { if(n <= 2) return 1; long long int k = n/2; long long int a = fib(k+1); long long int b = fib(k); if(n%2 ==...

Why does my function not have access to the globally created array? [duplicate]

php,arrays,scope,global-variables
This question already has an answer here: Can't access global variable inside function 4 answers I created an array outside of an functions, which means it should have global scope. I then try to loop through it from within a function, which should have access to the globally created...

Identify the arguments, parameters, local variables and global variables used in the following code?

javascript,parameters,arguments,global-variables,local-variables
The code is: var x = 32; var y = 44; var radius = 5; var centerX = 0; var centerY = 0; var width = 600; var height = 400; function setup(width, height) { centerX = width/2; centerY = height/2; } function computeDistance(x1, y1, x2, y2) { var dx...

Declaring global variables with a function in python

javascript,python,global-variables
This piece of JavaScript code works well. My issue isn't with fixing the code itself, rather how I can mimic this in Python. function setupSomeGlobals() { // Local variable that ends up within closure var num = 666; // Store some references to functions as global variables gAlertNumber = function()...

Why a variable defined global is undefined? [duplicate]

javascript,global-variables,local-variables,hoisting
This question already has an answer here: 'Hoisted' JavaScript Variables 4 answers Hi guys here I have a simple function and a global variable. My question is why myname = "glabol" is undefined and not the string "global" var myname = "global"; // global variable function func() { alert(myname);...

How does extern work in namespaces?

c++,namespaces,global-variables,const,extern
I'm running a simple program similar to what I found here. It's meant to reduce code bloat when including constants in multiple files. It does this by using const global variables within a namespace with their respective extern forward declarations. globals.h #ifndef GLOBALS_H_ #define GLOBALS_H_ namespace Constants { // forward...

Use Commands from argv to Initialize a Global Mutex

pthreads,global-variables,global,mutex,argv
What I wish to do is to define a global mutex using data from argv. Not a problem, except that I also want this mutex to be global. This isn't global:: int main (int argc, char **argv) { int arg_1 = atoi(argv[1]); pthread_mutex_t mutex[arg_1]; return 0; } And this isn't...

How to get my global variables to be available during imports of other modules?

python-3.x,global-variables
In python 3 I have a global dictionary, mydict that looks like: global mydict #this is line 1 mydict = {'property1':'value',... After this line, I import a module: from my_module import my_mod Putting a breakpoint on the import shows my global as existing as part of the globals. Putting a...

How to Declare Global Array Variable in SAS?

arrays,sas,global-variables,sas-macro
I'm new to SAS and spinning my wheels. The SAS documentation and other Google searches have not helped me figure this out. How can I declare a global array variable that I can use in various procedures to loop through the contents? Here is what I've tried: %let fileArray =...

Linked Lists - Global v. Local Variables

c,linked-list,global-variables
I have the following algorithm which is meant to reverse a linked list. typedef struct node { int data; struct node* next; }LL_t; void insert(LL_t** head, int value) { LL_t* new_node = (LL_t*) malloc(sizeof(LL_t)); new_node->data = value; new_node->next = (*head); (*head) = new_node; } LL_t* head; // Post: L contains...

Why are these global variables when they have namespace scope?

c++,namespaces,scope,global-variables,forward-declaration
In the following code, this is calling the variables in the globals.cpp namespace actual global variables. globals.h #ifndef GLOBALS_H_ #define GLOBALS_H_ namespace Constants { // forward declarations only extern const double pi; extern const double avogadro; extern const double my_gravity; } #endif globals.cpp namespace Constants { // actual global variables...

Android global variable dynamic value

android,global-variables,value
Hello all i want to make use of a global integer variable that i shall be incrementing in 7 different activities according to the users right or wrong choise. The problem is that i every time i implement the variable in each different activity , the value is not kept....

python input check function not being called properly

python,return,global-variables,try-catch,raw-input
I'm working on a very simple temperature converter in Python (just for practice), and am struggling with some of the UX components. I'd like to have checks in place to continue prompting for variable input when invalid entries are made. My full code is below: o_temp = '' def temp_input(o_temp):...

Programmatically Alias Method that uses $& Global Variable

ruby,global-variables,metaprogramming
I'm trying to alias a method that use's Ruby's special $& (returns last regex match). I can do this manually and it works: original = String.instance_method(:sub) String.send(:define_method, :sub) do |*args, &block| puts "called" original.bind(self).call(*args, &block) end "foo".sub(/f/) { $&.upcase } called # => "Foo" However if I try to write...

Inability to pass values in variable between inner and outer for loops python 3.3

for-loop,global-variables,pass-by-reference,nested-loops,python-3.3
I'm attempting utilizing TeamTreehouse learning subscription & this Starting Out With Programming Logic And Design book to attempt learning programming & python. Please don't shoot to kill me I'm having difficulty with repetition structures! Goal: I'm attempting to collect input from a user in the outer for loop. The inner...

How to initialise global cell reference variables correctly in VBA

excel,vba,excel-vba,initialization,global-variables
In my VBA project I have a number of cells which I refer to within many modules and subs. For ease of reading sake I have declared and initialised a variable to the cell reference in the following way: LowerBound = ThisWorkbook.Sheets("Rules").Range("B22").Value I would like to initialize this variable just...

How to make and access global variables in Objective-C

objective-c,global-variables,coordinates
I have dropped a pin on a map through a search bar and I retrieve its coordinates, saving them in myLatitude and myLongitude doubles. This is done in the following snippets of code: class1.h @interface Location : UIViewController <UISearchBarDelegate, MKMapViewDelegate> @property (nonatomic, readwrite) double myLatitude; @property (nonatomic, readwrite) double myLongitude;...

Setting Global Var and calling it in HTML

javascript,html,variables,global-variables
I am trying to set a global var and then calling it in an HTML file var test = ''; $(document).ready(function() { function test() { alert("test"); } }); In the HTML part i tried doing this and it did not work. I also tried window.onload method document.write(test); ...

Static variable link error, C++

c++,static,global-variables,linkage
Consider this code. //header.h int x; //otherSource.cpp #include "header.h" //main.cpp #include "header.h" ... int main() { } In this case compiler erred with the message. "fatal error LNK1169: one or more multiply defined symbols found" but when I add static before x, it compiles without errors. And here is the...

will there be memory leak or the best way for storing global variables?

android,memory-leaks,global-variables,best-in-place
With this question the main concern is what could be best approach. In my android app an Application class is subclassed mainly for two reasons, 1), Maintaining the global state across the app, 2), Ability to initialise and use SharedPreferences in non-activity classes. The code is somewhat like this, public...

Print global pointer gives coredump

c,memory,global-variables
I wrote a simple program below: #include <stdio.h> unsigned int *time = 0; int main(){ printf("time = %u\n", *time); return 0; } This will gives me segmentation fault on x86-64. Could someone explain the root cause?...

GLM in all data frames global environment

r,loops,global-variables,environment-variables,glm
I have a master data frame that contains ~200 unique 'IDs' and each of these IDs have about ~200 each 'orders'. I have split the master data frame into 200 individual data frames using list2env(split(df, df$id), envir = .GlobalEnv) Now since I have 200 individual data frames per each unique...

JS: How to use abbreviations for full named variables?

javascript,global-variables
I prefer to declare all global variables at the beginning of my code using self-explanatory, full-named variables: var $interval_start_dates = []; // date intervals var $interval_end_dates = []; var $interval_start_milli = []; // convert dates to milliseconds var $interval_end_milli = []; var $interval_start_milli_sorted = []; // sort millisecond dates var...

Python class and global vs local variables [duplicate]

python,class,namespaces,global-variables
This question already has an answer here: Python class scoping rules 2 answers I have a problem understanding what is happening with the outcome of the following pieces of code: my_str = "outside func" def func(): my_str = "inside func" class C(): print(my_str) print((lambda:my_str)()) my_str = "inside C" print(my_str)...

Go Namespace/Scope Issue for Global Session Management Across Multiple Packages

web-applications,go,global-variables,session-cookies,beego
First let me say I'm new to Golang. Working with it for a couple of weeks now. Really like the language but... I'm having some trouble with global session management in Golang. I see how it works and I can me it work if scope is all in one package,...

Global Variable usage on page reload

javascript,jquery,global-variables,form-submit,persistent-storage
I am basically trying to capture the submit button press of my form and if the form is submitted, the page refreshes and I show a few hidden fields. So basically I would like to capture whether the form has been submitted before or not and if it submitted on...

Adding c# file with global variables and helper functions without adding a web page with it

c#,asp.net,visual-studio,global-variables
i'm new to asp.net and will appriciate if you can help me with that: I'm using VS and I want to add a C# file that will include some global variables and helper functions that I'll use on different pages. I don't see any option to add a standalone file...

Calculating execution time using boost::chrono

c++,boost,type-conversion,global-variables
I tried to calculate the sum of a function execution time in a loop but something goes wrong : #include <boost/chrono.hpp> #include <iostream> boost::chrono::milliseconds sumGlobal; int main() { boost::chrono::high_resolution_clock::time_point t1 ; boost::chrono::high_resolution_clock::time_point t2 ; for (i=0;i<10;i++) { t1 = boost::chrono::high_resolution_clock::now(); f(); //to waste time t2 = boost::chrono::high_resolution_clock::now(); sumGlobal +=...

What will be the possible causes for the 1st code fragment to output differently than 2nd and 3rd?

c++,global-variables
This is an excerpt from Insertion sort program. Below are given three code fragments, which are different version of same function, and ought to give same output; unfortunately, only the 2nd and 3rd code fragments give the expected output. Why does code fragment 1 act differently? int find_smallest_index(int get_array[],int size,int...

How to pass a variable to coffeescript depending on build profile in mimosa

coffeescript,global-variables,preprocessor,mimosa
I have a typical mimosa front-end project with coffeescript for scripting. I want a certain variable (api path) to have different values, depending on build profile (dev or prod). How can I achieve this in mimosa? Example of what I want: prod.coffee: exports.api = 'myserver' dev.coffee: exports.api = 'localhost' api-accessor.coffee...

How to access a variable across CoffeeScript functions?

javascript,coffeescript,global-variables
I use CS in Rails. If I have: foo = -> ... bar = -> ... -> someCount = 123 foo() bar() How can I access someCount inside foo() and bar() without passing it directly as an argument? I thought that this would require declaring someCount as a global variable....

Java Garbage collection against Local and Global variable with Thread Safe

java,garbage-collection,thread-safety,global-variables,local-variables
Which of the below snip of code is more Garbage Collection efficient in terms of TIME Class Test{...} Local Variable private void function(){ Test test = new Test(); .... } Global Variable Test test = null; private void function(){ if(test == null){ test = new Test(); } } Let assume...

Objective C Global Variable

objective-c,global-variables,extern
Can anyone tell me where I'm going wrong here please. I have created an NSobject called BeaconData. The header file is: #import <Foundation/Foundation.h> #import <CoreLocation/CoreLocation.h> #import <CoreBluetooth/CoreBluetooth.h> @interface BeaconData : NSObject @property (nonatomic, strong) NSMutableArray * jsonArray; @property (nonatomic, retain) NSString * bMajor; @property (nonatomic, retain) NSString * bMinor; @property...

Python global variable/scope confusion [duplicate]

python,scope,global-variables,jes
This question already has an answer here: Python scope [duplicate] 4 answers I've started teaching myself python, and have noticed something strange to do with global variables and scope. When I run this: x = 2 y = 3 z=17 def add_nums(): y = 6 return z+y The result...

NameError: global name 'b' is not defined

python,global-variables,getopt
I have an script wih the following structure: def func(): bfile=open(b, 'r') cfile=open(c, 'r') dfile=open(d, 'r') if __name__=='__main__': if len(sys.argv)==1: print 'guidence' sys.exit() else: opts,args=getopt.getopt(sys.argv,'b:c:d:a') a=False for opt,arg in opts: if opt=='-a': a=True elif opt=='-b': b=arg elif opt=='-c': c=arg elif opt=='-d': d=arg func() I run it in this way: #...

Define global constant in Matlab

matlab,namespaces,global-variables,constants,superglobals
I want to define SI global prefixes in Matlab to make my code self explaining. I defined it in startup.m: % define SI prefix global SI SI.milli = 1e-3; SI.micro = 1e-6; % and so on.. It works fine, if I run test.m directly % test.m file Area = 10...

How to use global functions/Utility Class in EXTJS

extjs,global-variables
My code structure is as follows-> MyApp-> app -> controller, model, store, shared (util-> Utility.js), view I have created the following Utility Class Ext.define('MyApp.shared.util.Utilities', { myFunction : function (val, meta, rec) { //do something return val; } }); I am trying to call the myFunction while rendering a column in...

WooCommerce - get_order() is not working

php,wordpress,woocommerce,global-variables,helpers
I'm trying to create a function that will retrieve an order by its ID. For some reason I can't get the WooCommerce global function get_order to work. I'm passing a valid order id to the function and trying to print it out to verify that it's working. The function has...

Is there a way to modify class state from a function pointer passed to a C API?

c++,c,class,callback,global-variables
I have a class that has some internal state. The class uses a C library called GLFW to deal with window managing and keyboard input. The class looks something like this: class Object { public: Object(...); ... private: int _member_variable; // Internal state GLFWwindow *_window; ... } Background about GLFW...

extern variable and array declare issue c++

c++,arrays,global-variables,const,extern
I have a problem with an extern variable and an array declaration with it. How to declare an array with global variable which located not in the declarable file. file1.cpp const int size = 10; mainfile.cpp extern const int size; void main() { int mas[size]; } int mas[size]; This line...

Reducing map look-up times

c++,c++11,global-variables
Is there a significant difference in speed when scaling the following two program structures: map<string, std::function<string()>> myMap = { {"hello", [](){ return " world"; }} }; int main() { cout << "hello" << myMap["hello"](); return 0; } vs. int main() { map<string, std::function<string()>> myMap; myMap["hello"] = [](){ return " world";...

Initialize Global Variable .Net

vb.net,winforms,global-variables
I'm trying to find some help in the ways of "Initializing" A module/Variable inside the module on an event. I need it to load, in order for the following WinForm to use it (apparently) Let me explain... I am using the WinSCP library and gotten plenty of help in the...

global variable defined in main script can't be accessed by a function defined in a different module

python,module,global-variables
I want to define a few variables in my main python script and use them in a function which is defined in a separate module. Here is an example code. Lets say the main script is named main.py and the module is called mod.py. Mod.py def fun(): print a main.py...

Method is returning undefined [duplicate]

javascript,jquery,global-variables
This question already has an answer here: How to return the response from an asynchronous call? 7 answers I have a piece of JS code in for loop: window.gamesParse = { days: days, dates: dates, times: times, series: series, homes: homes, aways: aways, channels: channels } var image =...

Global variable isn't accessible inside my Wordpress function. Why not?

php,wordpress,global-variables,php-include
I am working in wordpress, and have a function in functions.php. This is meant to set a number of variables based on the context the variable is used in. But there's a problem. I am using the function in an included template file, and the function is intended to work...

undefined variable error in jquery

jquery,variables,global-variables,undefined
I have this code and I want to show il in the elements which will be created by jquery , but il is undefined : this is code : <script> $(document).ready(function(){ var il = 1 ; $("#btn1").click(function(){ $("p").append(" <b>Appended text</b>."); }); $("#btn2").click(function(){ $("ol").append("<li>Appended item " + il + " </li>");...

Using AngularJs UI Router and global variables in single page application

javascript,angularjs,angularjs-scope,global-variables,angular-ui-router
I am creating a hybrid quiz application with AngularJS. I have below pseudo code, index.html where user selects the quiz. 2nd page using ui-view Quiz is rendered and user selected options are stored in a global array (Should I use global here ?) The values in array are compared with...

What do I get if I declare an array without a size in global scope?

c,arrays,int,global-variables
In one of the answers in Tips for golfing in C, I saw this code (ungolfed version): s[],t; main(c){ for(scanf("%*d "); ~(c=getchar()); s[t++]=c) putchar(s[t]); } I think that the above program exhibits UB (but who cares in code golf?). But the thing that I don't understand is the s[] in...

Is the memory allocated to a global static variable defined in cpp freed up after a instance of its class is deleted in C++?

c++,class,memory-leaks,static,global-variables
I have a class whose methods defined in example.cpp file and class defined in example.h. There is a static global pointer defined in a example.cpp file. (I need this pointer defined as a static global pointer in .cpp as it gets called in a static interrupt service routine running on...

How to use global variables in multiple .cpp files?

c++,global-variables,extern,multiple-files
I have this simple program which tries to print my global variable in a separate file. I'm using the Visual Studio 2013 professional IDE. print.h #ifndef PRINT_H_ #define PRINT_H_ void Print(); #endif print.cpp #include "print.h" #include <iostream> void Print() { std::cout << g_x << '\n'; } source.cpp #include <iostream> #include...

Global variable in Matlab that retains an old value and won't change

matlab,function,variables,data-structures,global-variables
I have created a function in Matlab and use the following run.m file to run it. global kanasta EEG_multitaper_autocor_SO_maheen_final(ALLEEG_LANCE_POST,'All','Cz-CPz',3,1,1,1) POST=kanasta; where kanasta is a variable generated from the function EEG_multitaper_autocor_SO_maheen_final and ALLEEG_LANCE_POST is a data structure. From whatever kanasta (which is an array) I get from running this, I store...

Using Assembly global variable in C

c,assembly,makefile,global-variables
Trying to compile this code in a.s: section .bss global _start global TestVar TestVar: RESB 4 section .text extern main _start: and this code in b.c: extern int TestVar; void test2(int x, int y) { int z = TestVar; x = z + y; y = 1; } int main(int...

Using Global vars in GAS, is it advisable? are there any downsides?

javascript,google-apps-script,google-spreadsheet,global-variables
Sorry if this a stupid question, but here goes So I've been learning Javascript for use with Google Application Scripts for about a year now and slowly but surely am finding my feet. I tried to help someone with their script on here, and i notice that they declared var...

Loop resulting in: “TypeError: Undefined is not a function”

javascript,arrays,loops,global-variables
I have made the following script: //Declaring global variables var difference = 6; //difference between two dates var startdate = new Date(2015, 04, 04); //the start date var startday = startdato.getDay(); //the weekday of the start date var dateinterval = [startdate]; //declaring the date array var days = [startday]; //declaring...

Global variables aren't working as expected with frameworks

php,variables,laravel,frameworks,global-variables
I'm trying to use global variables in my php script, and I found the usage of global variable on php.net. But it doesn't work on my local server. Is there any configuration I have missed out? There is an example found on that page: <?php $a = 1; $b =...

Stylus global variables

angularjs,global-variables,middleware,stylus,file-structure
I have a core.styl where I put my grid-style, some stylus-functions and some variables. This file should be imported in all of my routes. Beside that I have an page.styl which dependes on my current route (e.g. contact.styl for /contact) Note: My project is based on angular.js so the html-head...

Change static variable

swift,static,global-variables
im new in swift. I'd like to ask u if i go the right way. I have something like this: class ViewController: UIViewController { struct myVars { var static short_text = "" } override func viewDidLoad() { super.viewDidLoad() loadData() println(short_text) } func loadData() { myVars.short_text = "Hello world!" } }...

I cannot assign a value to a variable after call a function in javascript

javascript,function,variables,global-variables
I am making a modification of the popular game rock-paper-scissors-lizard-spock based on a algorithm proposed by someone on this site. Here is my Js: //¿Es obligatorio declarar las variables? var Elementos = ["AIRE", "OSCURIDAD", "AGUA", "FUEGO", "TIERRA"]; var resultados = [" empata con ", " derrota a ", " pierde...

Use same Python variable in multiple if-statements

python,if-statement,raspberry-pi,global-variables,bottle
I am having issues with my current Python script. The purpose of the 'progress' variable is take a specific value when it goes through one of the if-loops. But, the program never goes further then the first if-statement. It looks as if every if-statement makes his own variable called 'progress'....

Accessing vars inside functions

javascript,variables,scope,global-variables
In the following code: var pie = []; function makeChart() { new Chart(document.getElementById("canvas").getContext("2d")).Doughnut( pie); }; var data = jQuery.getJSON('xxx', function(data) { pie = [{ value: data.company_live_ads, color: "#F7464A" }, { value: data.total_candidates, color: "#46BFBD" }, { value: data.company_ads_published_3days, color: "#FDB45C" }, { value: data.company_apps_today, color: "#4D5360" }]; makeChart(); }); The...

What is the life cycle of a public static variable in Android?

java,android,android-activity,static,global-variables
I have a simple class to keep a few variables to share them between activities in my game, something like: public class TheGlobals { public static boolean IsFullGame = false; } Now, when the game launches, the initial activity is MainMenu, which determines whether the user has purchased the full...

global settings in sailsjs

global-variables,sails.js
What would be a proper way to handle global "settings" in my sailsjs application? The user will want to change those settings via the web front of my app. I imagine I could use a new model "GlobalSettings" with only one item, but I don't really know if it's a...

service method as twig global variable

php,symfony2,service,global-variables,twig
In my symfony2 application, I have a getPorfolioUser method which return a specific user variable. I am looking forward to be able to call {% if portfolio_user %} in twig. I did not understand how I could set this as a global variable as from the documentation I am under...

What is the difference between global variables and #define in c

c,global-variables,c-preprocessor
Whats the reason why there are 2 opportunities : global variables symbolic constants with #define ? So I know what #define does but I don't know what the difference in use is. Which situation do I must have thus I'm able to decide myself upon the right opportunitie? What is...

how to globalize php getimagesize function variables

php,function,global-variables,getimagesize
I am using following code in my web pages to get image dimension. <?php list($width, $height) = getimagesize('images/'.$img); ?> <img src="images/<?php echo $img?>" width="<?php echo $width?>" height=<?php echo $height?>" alt="<?php echo $heading?>"> I know it isn't professional way to include this function in every mysql queries. But When I include...