Questions tagged [declare]

Use this tag for questions related to declare, which is usually meant for declaring variables, statements, etc.

Filter by
Sorted by
Tagged with
251 votes
6 answers
569k views

How to declare an ArrayList with values? [duplicate]

ArrayList or List declaration in Java has questioned and answered how to declare an empty ArrayList but how do I declare an ArrayList with values? I've tried the following but it returns a syntax ...
alvas's user avatar
  • 119k
137 votes
2 answers
218k views

Declare variable in table valued function

How can I declare a variable in a table valued function?
esquare's user avatar
  • 4,077
136 votes
10 answers
495k views

How do I use variables in Oracle SQL Developer?

Below is an example of using variables in SQL Server 2000. DECLARE @EmpIDVar INT SET @EmpIDVar = 1234 SELECT * FROM Employees WHERE EmployeeID = @EmpIDVar I want to do the exact same thing in ...
Nathan's user avatar
  • 1,361
111 votes
11 answers
406k views

SELECT INTO Variable in MySQL DECLARE causes syntax error?

I´d like to SELECT a single value into a variable. I´d tried to following: DECLARE myvar INT(4); -- immediately returns some syntax error. SELECT myvalue FROM mytable WHERE anothervalue = 1; -...
Matt Bannert's user avatar
103 votes
15 answers
472k views

Declaring array of objects

I have a variable which is an array and I want every element of the array to act as an object by default. To achieve this, I can do something like this in my code. var sample = new Array(); sample[0] ...
Prasath K's user avatar
  • 4,990
78 votes
2 answers
162k views

Declare local variables in PostgreSQL?

There is an almost identical, but not really answered question here. I am migrating an application from MS SQL Server to PostgreSQL. In many places in code I use local variables so I would like to go ...
UnDiUdin's user avatar
  • 15.1k
71 votes
4 answers
59k views

C function pointer syntax

Normally, when declaring some variable, you put its type before it, like: int a; a function pointer may have type like: int(*)(int,int), in case we point to a function that takes two integers and ...
user1941583's user avatar
68 votes
2 answers
145k views

typescript declare third party modules

How could I declare a third party module which looks like this: in third party module: module.exports = function foo(){ // do somthing } in my code: import * as foo from 'foo-module'; // Can not ...
Saman Mohamadi's user avatar
63 votes
3 answers
30k views

Differences between declare, typeset and local variable in Bash

When typing variables in Bash, what is the difference between declare and typeset? When used inside a function: what is the difference between declare and typeset and local? The only difference I ...
lecodesportif's user avatar
54 votes
2 answers
18k views

What does "#!/bin/env" mean (at the top of a node.js script)?

I found serval node.js projects that have this at top of their app.js (as in this openshift program): #!/bin/env node What does this mean? How does this work? Where is it useful?
hh54188's user avatar
  • 15.2k
46 votes
8 answers
101k views

name 'times' is used prior to global declaration - But IT IS declared

I'm coding a small program to time and show, in a ordered fashion, my Rubik's cube solvings. But Python (3) keeps bothering me about times being used prior to global declaration. But what's strange is ...
AntonioPT's user avatar
  • 483
44 votes
6 answers
49k views

Declare multiple variables in JavaScript

I want to declare multiple variables in a function: function foo() { var src_arr = new Array(); var caption_arr = new Array(); var fav_arr = new Array(); var hidden_arr = new ...
TunaFFish's user avatar
  • 11.2k
40 votes
10 answers
37k views

Why use constants in programming? [closed]

I've just been going back over a bit of C studying using Ivor Horton's Beginning C book. I got to the bit about declaring constants which seems to get mixed up with variables in the same sentence. ...
Adam N's user avatar
  • 409
32 votes
4 answers
173k views

Create View - Declare a variable

I am creating a view that is using that STUFF function. I want to put the result of STUFF in a variable for my view. The problem I am having is declaring my variable. It gives me the message "...
Ethel Patrick's user avatar
32 votes
5 answers
50k views

MySQL local variables

I am trying to define and initialize a MySQL variable for a query. I have the following: DECLARE @countTotal INT; SET @countTotal = SELECT COUNT(*) FROM nGrams; I am using MySQL in Netbeans and it ...
CodeKingPlusPlus's user avatar
32 votes
2 answers
8k views

Can I declare the same variable twice in different for loops in JavaScript? [duplicate]

Possible Duplicate: JavaScript Variable Scope I have a JavaScript function for HTML select options for days: // Show and hide days according to the selected year and month. function ...
Uri's user avatar
  • 3,072
31 votes
2 answers
14k views

PHP using Declare ? What is a tick?

I am a little bit confused by the PHP function declare. What exactly is a single tick? I thought a tick equals one line of code? But if I use: function myfunc() { print "Tick"; } ...
opHASnoNAME's user avatar
  • 20.5k
30 votes
3 answers
2k views

Why don't methods of structs have to be declared in C++?

Take, for example, the following code: #include <iostream> #include <string> int main() { print("Hello!"); } void print(std::string s) { std::cout << s << std::endl; ...
user avatar
27 votes
2 answers
92k views

Declare variable set = select

How do I declare a variable for used in a PostgreSQL 9.3 query? CREATE or replace FUNCTION public.test() returns int4 AS $BODY$ DECLARE cod_process bigint :=30001; cod_instance bigint ; ...
ASA's user avatar
  • 311
27 votes
1 answer
36k views

Declare row type variable in PL/pgSQL

As I found SELECT * FROM t INTO my_data; works only if: DO $$ DECLARE my_data t%ROWTYPE; BEGIN SELECT * FROM t INTO my_data WHERE id = ?; END $$; Am I right? If I want to get only 2-3 columns ...
Vyacheslav's user avatar
  • 26.9k
25 votes
3 answers
54k views

TypeScript define object structure for later use

Is it possible to define an object structure in TypeScript that can be used then as parameter type? What I mean: I have (let's say) 5 functions that return the same object structure like so: foo(): {...
kristóf baján's user avatar
24 votes
4 answers
64k views

Cannot assign a default value to a local variable in SQL

I am trying to declare local variable like: DECLARE @thresholdDate DATETIME = '2014-11-30' And I am getting error: Cannot assign a default value to a local variable. As per documentation: ...
Vladimirs's user avatar
  • 8,411
23 votes
4 answers
23k views

Avoiding declaring private functions in class header files (C++)

(In C++) I have a class whose structure is declared in a header file. That header file is included in lots of source files, such that when I edit it I need to recompile lots of files. The class has a ...
user664303's user avatar
  • 2,053
22 votes
3 answers
15k views

Why are "declare -f" and "declare -a" needed in bash scripts?

Sorry for the innocent question - I'm just trying to understand... For example - I have: $ cat test.sh #!/bin/bash declare -f testfunct testfunct () { echo "I'm function" } testfunct ...
setevoy's user avatar
  • 4,504
22 votes
1 answer
12k views

TypeScript - Declare vs Export - Best Practices?

Short and sweet, is it better practice to define my own interfaces with declare or with export? // i.something.d.ts export default interface ISomething { myValue: string; } // something.ts ...
user avatar
21 votes
2 answers
51k views

Create a function declaring a predefined text array

I need to create a function in Postgres and one of the variables I declare is a predefined text array, but I don't know the syntax to set its values. This is what I have so far: CREATE OR REPLACE ...
Edson Horacio Junior's user avatar
20 votes
3 answers
34k views

Declare variable syntax invalid in MySQL Workbench?

I am trying to create and set a variable: DECLARE myId INT; SET myId = 5; However, I am getting invalid syntax complaint in MySQL Workbench: SQL syntax error near 'DECLARE myId INT;' I have ...
Roy Hinkley's user avatar
  • 10.4k
18 votes
2 answers
16k views

Difference between DECLARE and SET in SQL [closed]

What's the difference between DECLARE and SET using SQL (or more specifically MySQL)? Both can set variables it seems. I have read the MySQL docs and I did not understand the difference between the ...
C H's user avatar
  • 185
17 votes
4 answers
30k views

DllImport vs Declare in VB.NET

I notice in the MSDN documentation that there are multiple ways to declare a reference to a function in an external DLL from within a VB.NET program. The confusing thing is that MSDN claims that ...
Mike's user avatar
  • 4,582
16 votes
8 answers
9k views

What exactly are C++ definitions, declarations and assignments?

I tend to use the words define, declare and assign interchangeably but this seems to cause offense to some people. Is this justified? Should I only use the word declare for the first time I assign to ...
user avatar
16 votes
3 answers
7k views

Forward declare a struct in Objective-C

I'm creating a protocol, and one of the parameters to a method I'm defining is a CMTime*. I would like to forward declare CMTime as opposed to including it. However, I've tried @class CMTime and it ...
user1186226's user avatar
15 votes
2 answers
2k views

How to read/write memory on Mac OS X with VBA?

On Windows the declared function RtlMoveMemory provides a way to copy a block of bytes from one address to another: Private Declare PtrSafe Sub RtlMoveMemory Lib "kernel32" ( _ ...
michael's user avatar
  • 949
14 votes
3 answers
32k views

C# Declare a string that spans on multiple lines

I'm trying to create a string that is something like this string myStr = "CREATE TABLE myTable ( id text, name text )"; But I get an error: https://i.stack.imgur.com/o6MJK.png What is going on ...
Ben's user avatar
  • 5,727
14 votes
1 answer
2k views

Is there ever a reason to use the declare keyword in front of types and interfaces?

I have come across some code like this: declare type A = { ... }; declare interface B { ... } From searching for the declare keyword (and none of the hits pointed to me the TypeScript docs for some ...
pushkin's user avatar
  • 9,918
13 votes
6 answers
122k views

creating array without declaring the size - java

i've digging around about the same issue but i couldn't find the same as i had i want to create an array without declaring the size because i don't know how it will be ! to clear the issue i'd like ...
Hamoudaq's user avatar
  • 1,498
11 votes
1 answer
73k views

How to declare session variable in C#? [duplicate]

I want to make a new session, where whatever is typed in a textbox is saved in that session. Then on another aspx page, I would like to display that session in a label. I'm just unsure on how to ...
Carrie's user avatar
  • 137
9 votes
4 answers
7k views

Missing partial modifier on declaration of type 'x' - cause by auto-generated code by designer

The full error description is as per below: And I found a few similar question posted before: A and B But the question in A and B does not provide detail of problem description (perhaps we prompted ...
jhyap's user avatar
  • 3,801
8 votes
4 answers
345 views

why a[n] is accepted in c during runtime?

why can we do this in c? int n; scanf("%d",&n); int a[n]; I thought array is located memory during load time but seems like the above example works during runtime. Do I misunderstand any thing? ...
user avatar
8 votes
2 answers
46k views

Declare a variable in Oracle SQL to use in a query

Hi I am trying to declare a variable to use in Oracle SQL select query as such: DECLARE myDate DATE; BEGIN SELECT Source as "Source", DT as "Date", Status as "Status", COALESCE("Count", 0) as "...
Kairan's user avatar
  • 5,442
7 votes
5 answers
18k views

How is this private variable "not declared in this scope"?

I'm currently trying to learn more about object oriented design in C++ (familiar with Java) and am running into some walls. The project I am trying to put together to learn these principles in a game ...
XBigTK13X's user avatar
  • 2,735
7 votes
1 answer
13k views

Declare Variable Not In Function by postgres

I want to declare variable in postgres but not in function... Declare c varchar; a integer; b integer; select b = count (*) from table set a = 1 while a <= b begin ...
Nike's user avatar
  • 101
7 votes
2 answers
23k views

character encoding of a framed document was not declared

I get this warning in FF when developing a site of mine. I can't find any real info about it and how to fix this. the character encoding of a framed document was not declared. The document may appear ...
Philip's user avatar
  • 6,967
7 votes
2 answers
20k views

how can i declare variables via macros?

first of all, I'm using MS's Visual Studio and using C language. Recently I need to declare variables with just one same statement which likes a macro. However as you know, I can declare just one ...
Darpangs's user avatar
7 votes
4 answers
5k views

How to assign char array in struct inline?

I'm trying to do something like this: struct SomeStruct { const char *bytes; const char *desc; }; SomeStruct example = { { 0x10, 0x11, 0x12, 0x13 }, "10-13" }; Why isn't this working?
d0c_s4vage's user avatar
  • 3,977
7 votes
1 answer
17k views

JavaScript: Can I declare variables inside switch cases? [duplicate]

In C language, you cannot declare any variables inside 'case' statements. switch ( i ){ case 1: int a = 1; //error! break; } However, you can when you use with curly parentheses. switch ( i ){ ...
PRIX's user avatar
  • 83
7 votes
4 answers
23k views

Cant declare variable SQL

I've been trying to declare an integer variable but its just not working. Here is my query: DECLARE @count INT SET @count = 5633 SELECT count(matchid) FROM `matches` WHERE id = @count Im ...
James Stevenson's user avatar
7 votes
2 answers
120k views

Python: Declare as integer and character

# declare score as integer score = int # declare rating as character rating = chr # write "Enter score: " # input score score = input("Enter score: ") # if score == 10 Then # set rating = "A" # ...
John's user avatar
  • 91
7 votes
3 answers
93k views

Declaring SQL variables - SQL Server

Can anyone check on my statement... DECLARE @tblName varchar(MAX), @strSQL varchar(MAX) SET @tblName ='SELECT DISTINCT o.name as TableName FROM sysobjects o ...
Argel Joseph's user avatar
7 votes
2 answers
1k views

Clojure: resolve declares symbol

I get some weird behaviour when checking if a symbol can be resolved. user=> ok CompilerException java.lang.RuntimeException: Unable to resolve symbol: ok in this context, compiling:(...
Dominik G's user avatar
  • 1,469
7 votes
2 answers
2k views

Kotlin declare nested array

How can nested lists be declared in Kotlin? I'm looking for something in the form of: var nestedList:List = [1,[2,[3,null,4]],[null],5] so that I can flatten it later on (result should be nestedList ...
Dan Crisan's user avatar

1
2 3 4 5
15