variable-assignment

How to combine variable assignment with data-retrieval operations in T-SQL

Just to clarify, I'm running Sybase 12.5.3, but I am lead to believe that this holds true for SQL Server 2005 too. Basically, I'm trying to write a query that looks a little like this, I've simplified it as much as possible to highlight the problem: DECLARE @a int, @b int, @c int SELECT @a = huzzah.a ,@b = huzzah.b ,@c = ...

Is it OK to use assignments in expressions?

I came across this code and wanted others to provide their point of view... is it good or bad ? ;) Class ReportClass { public string ReportName {get; set;} } Then it was used as follows in code: displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString()) That is about the simplest form example I can give you. Qu...

integer value changes when exiting preprocessor block

I have a chunk of code where it appears that a variable is changing at the end of a pre-processor block of code. int initialKeyCount; #if(DEBUG) // int initialKeyCount = _root.CountAllKeys(); initialKeyCount = 20000; #endif currNode = currNode.EnsureDegreeKeysPresent(parent); //initialKeyCount = 19969 here #if(DEBUG...

Basic assignment of swig wrapped variables fails

I created a lua module with a very large number of wrapped C++ classes using swig. The wrappers are generated and compiled (with -Wall) without any issues. However, in a couple of places that I've found, I run into the following issue: basic assignment of member data fails. If I run: Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio...

Is there a right way to return a new object instance by reference in C++?

So I was writing some code, and I had something like this: class Box { private: float x, y, w, h; public: //... Rectangle & GetRect( void ) const { return Rectangle( x, y, w, h ); } }; Then later in some code: Rectangle rect = theBox.GetRect(); Which worked in my debug build, but in release ther...

Assigning string to class redirects it to property

I have a class named Car with property Name. Now every time I like to change Name of my Car I must write Car1.Name = "Porka Turbo". Now what I would like to acomplish is 5 characters less to write like this: Car1 = "Porka Turbo" It should work like this: if I assign a class derrived from Car class it should make regular class assignme...

C# Shortest Way to Check for Null and Assign Another Value if Not

I am pulling varchar values out of a DB and want to set the string I am assigning them to as "" if they are null. I'm currently doing it like this. if (IsNullOrEmpty(planRec.approved_by) == true) this.approved_by = ""; else this.approved_by = planRec.approved_by.toString(); There seems like there should be a way to do this in a s...

iPhone Obj-C error: assignment of read-only variable 'prop.149' in Xcode

I'm programming an iPhone app using Objective-C. Here's the error Xcode gives me: error: assignment of read-only variable 'prop.149' The code: // Create CATransition object CATransition *transition = [CATransition animation]; // Animate over 3/4 of a second transition.duration = 0.75; // using the ease in/out timing function transit...

How to assign output of cat to an object?

How would it be possible in the example below to skip the step of writing to file "test.txt", i.e. assign the cat-result to an object, and still achieve the same end result? I thought I'd include the full example to give background to my problem. test <- c("V 1", "x", "1 2 3", "y", "3 5 8", "V 2", "x", "y", "V 3", "y", "7 2 1", "V 4", ...

foreach, performance-wise. Should we declare variable once before loop or inside it?

What is better for performance wise declaring the variable outside the foreach statment and the each time reassign it in side it (foreach) or create an new variable inside foreach for example private List<ListItem> GetItems() { var items = new List<ListItem>(); var collection = new List<int> { 0, 1, 2, 3,...

Multiple left-hand assignment with JavaScript

var var1 = 1, var2 = 1, var3 = 1; This is equivalent to this: var var1 = var2 = var3 = 1; I'm fairly certain this is the order the variables are defined: var3, var2, var1, which would be equivalent to this: var var3 = 1, var2 = var3, var1 = var2; Is there any way to confirm this in JavaScript? Using some profiler possibl...

Logical value of an assignment in C

while (curr_data[1] != (unsigned int)NULL && ((curr_ptr = (void*)curr_data[1]) || 1)) Two part question. What will (curr_ptr = (void*)curr_data[1]) evaluate to, logically. TRUE? Also, I know its rather hack-ish, but is the while statement legal C? I would have to go through great contortions to put the assignment elsewhere in the...

C * operator meaning in array assignment

What does this line mean? I havn't done C in a few years. Does it perform the operation in parens then make the int result a pointer?? b[0] = *(start + pos++); ...

Assigning the result of an expression to a variable

Working with DrScheme (language-- Pretty Big). Trying to pass the result of an expression to a variable that can later be used in another expression. Here is a simplified version of the problem: Definitions window: (define (tot a b c) (+ a b c)) (define (tot2) (+ (tot a b c) 1)) Interpreter window > (tot 5 6 7) 18 > (tot2) . ....

Linux bash: Multiple variable assignment

Does exist in linux bash something similar to the following code in PHP: list($var1, $var2, $var3) = function_that_returns_a_three_element_array() ; i.e. you assign in one sentence a corresponding value to 3 different variables. Let's say I have the bash function myBashFuntion that writes to stdout the string "qwert asdfg zxcvb". Is ...

Is this wrong or am i missing something ( int count = 10, x; )

Came across this example in the book im reading and it didn't make sense at all to me, I'm probably missing something but it seems like youre assigning count with the values '10' and then the value 'x' which isnt even an int. Just wondering if this is a syntax that is valid. The book says this: The variables count and x are declared to...

Is it better to assign variables in a class itself or in the class' constructor?

This is a sort of design question, and I'm sure there are people who do it both ways. But in your opinion, is it better to assign a variable in the class or in the constructor? For example (regardless of syntax or language, this is just to explain): public class Example { private final int TIME_STAMP = Now(); private int num = 2; ...

Can one make an assignment on conditional statement in php?

Can you make an assignment on conditional statement in php as so: if(siteName_err = isValid("sitename", $_POST['sitename'], false)) { $siteName = $_POST['sitename']; } ...

What's the difference between `=` and `<-` in R?

I'm using R 2.8.1 and it is possible to use both = and <- as variable assignment operators. What's the difference between them? Which one should I use? ...

Global Variable JavaScript (Changing Value)

Is it possible to change the value of a global variable in JavaScript? If so, is it possible to do it in a function called by an event listener such as "onreadyStateChange"? It's working for normal functions. but doesn't change when I call a function like this: <script.......> var dom1 = 3; function work() { ... ...