variables

When are VBA Variables Instantiated

回眸只為那壹抹淺笑 提交于 2020-08-24 10:23:24
问题 I'm hesitant to ask, but there's no documentation that I can find for VBA . Relevant (but I don't think a dupe): C++ When are global variables created? In Java, should variables be declared at the top of a function, or as they're needed? C++ Declare variables at top of function or in separate scopes? and the most likely relevant When are a module's variables in VB.NET instantiated? I also took a look at C# on programmers.SE. I think I'm using the word "Instantiate" right, but please correct

When are VBA Variables Instantiated

我怕爱的太早我们不能终老 提交于 2020-08-24 10:23:13
问题 I'm hesitant to ask, but there's no documentation that I can find for VBA . Relevant (but I don't think a dupe): C++ When are global variables created? In Java, should variables be declared at the top of a function, or as they're needed? C++ Declare variables at top of function or in separate scopes? and the most likely relevant When are a module's variables in VB.NET instantiated? I also took a look at C# on programmers.SE. I think I'm using the word "Instantiate" right, but please correct

Simple js FOR loop returning 'undefined'

喜你入骨 提交于 2020-08-24 05:58:19
问题 Not sure what I'm doing wrong here; the variable newStr should just return "Hello World", but I'm getting this instead: "undefinedHello World" undefined JS function translate2(x){ var newStr; x = "Hello World"; for(i=0; i<x.length; i++) { newStr+=x.charAt(i); } console.log(newStr); } 回答1: In JavaScript, if a variable is not initialized explicitly, it will by default have undefined. That is not a string but a primitive type of the Language. You can check that by printing it var newStr; console

Why use abs() or fabs() instead of conditional negation?

梦想的初衷 提交于 2020-08-20 18:48:12
问题 In C/C++, why should one use abs() or fabs() to find the absolute value of a variable without using the following code? int absoluteValue = value < 0 ? -value : value; Does it have something to do with fewer instructions at lower level? 回答1: The "conditional abs" you propose is not equivalent to std::abs (or fabs ) for floating point numbers, see e.g. #include <iostream> #include <cmath> int main () { double d = -0.0; double a = d < 0 ? -d : d; std::cout << d << ' ' << a << ' ' << std::abs(d)

Calling variables in the same class with python

孤街浪徒 提交于 2020-08-20 02:12:57
问题 I am trying to call a variable defined in a function, inside another function of the same class, but with self doesn't work. class Project(): def function1(self): a='hello world,' def function2(self): b=self.a + ' I am alive' Project1=Project() print Project1.function1() print Project1.function2() python says: Project instance has no attribute 'a' . I don't know very well how to use classes. I didn't use __init__ 'cause I do not have anything to put, is there maybe a way to add it even if I

Calling variables in the same class with python

▼魔方 西西 提交于 2020-08-20 02:09:02
问题 I am trying to call a variable defined in a function, inside another function of the same class, but with self doesn't work. class Project(): def function1(self): a='hello world,' def function2(self): b=self.a + ' I am alive' Project1=Project() print Project1.function1() print Project1.function2() python says: Project instance has no attribute 'a' . I don't know very well how to use classes. I didn't use __init__ 'cause I do not have anything to put, is there maybe a way to add it even if I

error: variable-sized object may not be initialized| (C language)

微笑、不失礼 提交于 2020-08-19 00:13:52
问题 I am a beginner of programming so I am not familiar to errors yet. int integer=1; struct myStruct **str1[integer] = malloc(sizeof(struct myStruct *)); I have this code segment, and I get following error: error: variable-sized object may not be initialized| I figured out the problem is causing from the variable 'integer' as when I delete it, I don't face this error. But I can't understand why I am seeing it because I already initialized 'integer' variable. Also, I already initialized "myStruct

How to make a for loop variable const with the exception of the increment statement?

强颜欢笑 提交于 2020-08-17 19:20:29
问题 Consider a standard for loop: for (int i = 0; i < 10; ++i) { // do something with i } I want to prevent the variable i from being modified in the body of the for loop. However, I cannot declare i as const as this makes the increment statement invalid. Is there a way to make i a const variable outside of the increment statement? 回答1: From c++20, you can use ranges::views::iota like this: for (int const i : std::views::iota(0, 10)) { std::cout << i << " "; // ok i = 42; // error } Here's a demo

Python, variable importing between files

别说谁变了你拦得住时间么 提交于 2020-08-17 11:55:28
问题 Preamble: I feel I probably have wasted so much time for a simple situation... Now, I am making a game with pygame, and at some point, I wanted to split files into two, namely main.py and configurations.py in order to make it more readable. Everything was going good, until I ran into this problem. I will share whole code at the bottom, but I want to summarize first: Now first of all, in main.py , I am importing by, from configurations import * now, the game loop on the main.py depends on the

Why does a `let` assignment that uses the same variable name in its right-hand side throw a ReferenceError? [duplicate]

青春壹個敷衍的年華 提交于 2020-08-11 19:46:51
问题 This question already has answers here : What is the temporal dead zone? (3 answers) Closed 3 years ago . I’m sure it’s a little caveat somewhere but, here is the issue: var x = x || {}; // Works! let y = y || {}; // ReferenceError: can't access lexical declaration 'y' before initialization const z = z || {}; // ReferenceError: can't access lexical declaration 'z' before initialization The let and const cases throw “ReferenceError: can't access lexical declaration 'variableName' before