What does -1.#IND000 mean in the Visual Studio debug window? - visual-studio

In the Visual Studio 2010 watch window, I found the value of a variable became -1.#IND000. What does this mean?

IND is the representation of NaN (Not a Number) in Windows system. IND = "indeterminate form", mostly a result from an illegal operation like dividing by zero or arithmetic operation with infinity.

It means the content is undefined, can result from a division by 0.

Related

Can I set a filter condition on Visual Studio 2013's Watch Window

My program has very large matrices but most of the elements tend to be zero. Is there a way to set in the watch window something like the following for a 50x10000x2 matrix variable called tau_bcst:
Name Value
tau_bcst.ge.0 {...}
Such that in watch, it will only show the elements greater than zero. Something like the following:
Name Value
tau_bcst(1,4,1) 3
tau_bcst(10,2000,1) 3
tau_bcst(11,2000,1) 3
tau_bcst(49,2910,2) 3
tau_bcst(21,8930,2) 3
I know it can take some mathematical equations and calculate a value with the variables, so I am wondering if it can do this as well. I tried several ways but it doesn't seem to work.
I would gladly use a simple filter code to check the variable (return 1 if the values are non-zero, for example), except that I have many variables that I want to check at potentially multiple points in the code against another run of the code in another Visual Studio window so that won't be very efficient.

Assignment of arrays in Intel Fortran

I had an old Fortran 90 code with the following command:
data1(1:100) = data_all(:)
where data_all is a bigger array then data1.
Since I know that this is not a robust syntax, it worked good when using Visual Studio 2008.
I recently switched to Visual Studio 2013, and I am not able to use this code anymore, since it tries to fill the 101th position of data1.
What are the correct Compiler options to accept that?
Probably something like this:
data1(1:100) = data_all(1:100)
If data1 is 100 elements then
data1 = data_all(1:100)
If you want others then:
data1 = data_all(istart:(istart + (SIZE(data1) - 1))

run time error '6' Overflow in visual basic 6.0

I am getting a run time error '6' Over Flow in vb 6
The "Overflow" error means that you are trying to put a number into a variable (or property etc), and the data type of the variable doesn't allow numbers that large.
Make sure that numbers used in calculations that are coerced into integers do not have results larger than integers.
What is the type of the data in the database?
My guess is that ADO returns it as either a String or a Decimal, and Decimal values only "fit into" a Variant in VB6.
VB6 has no syntax for a Decimal literal, however you can use something like:
CDec(111010114289#)
... inline, or declare a Const as in:
Private Const BigVal As Currency = 111010114289#
I you have to put a large number in a small variable, like C, check Remove integer bound check in project properties (if you are not compiling as PCode)

C++/CLI seems to skip a line of code and debugging does not show the variable declared and defined in that line

I have only been developing in C++/CLI and C++ for a few months now but it seems to me that the programming language should not matter regarding this issue.
In the following lines of code, double k = (yEnd - yStart) / (xEnd - xStart); appears to be not executed.
//double k = 1.0;
if (xEnd - xStart == 0)
{
selected = true;
return true;
}
// Checks if Y-coordinate corresponds to X-coordinate
else
{
// Calculating the slope of the line
double k = (yEnd - yStart) / (xEnd - xStart);
if (fabs(y - (yStart + k * (x - xStart))) < (double)selectionTolerance)
{
selected = true;
return true;
}
}
I have tried to debug it line by line with F11 and have also set breakpoints, though these breakpoints move when running the debugger from the said line to if (fabs(y - (yStart + k * (x - xStart))) < (double)selectionTolerance) after it.
I have checked in the options of Visual Studio not to skip properties/operations, but it also didn't help. When the debugger halts the program at the if, I can not see any value of k, but can see all the other ones without problems (with the exception of char selectionTolerance and bool selected, all of them are double as well).
Thank you for the help, I have searched the web and stackoverflow for a long time but could not find a problem with a line as simple (and probably general) as this.
Update:
Thanks to David Yaw and G K, I was able to see the value of k. I am still puzzled by an issue illustrated here:
http://i.imgur.com/MyVGTwJ.png (cannot yet post images)
Even though yEnd, yStart, xEnd, xStart are all of type double and have the values as seen in the image above, when the program halts at line 254 before executing k=ydif/xdif;, k equals 0.0000000000000000. I added the three lines
double ydif= (yEnd-YStart);
double xdif=xEnd-xStart;
k=ydif/xdif;
to see the if k would be calculated as wanted, but it got the same value after pressing F11 again (program halts at line 256).
I found a question which is related to the jumping breakpoint issue here: Visual Studio breakpoints being moved
What is the problem with calculating k the way I try it, and what would be the correct way to do it?
You didn't mention that the calculation was incorrect, just that the line of code wasn't getting hit. I'm assuming the calculation is correct.
The local variable was likely optimized out by the compiler. Since you only used k in one spot, it eliminated the local variable, and did the slope calculation inline, in the if statement.
I've seen the C++/CLI compiler do similar things with method calls: I've gotten exceptions where the stack trace lists a method I don't call: The method I call was inlined, and the stack trace pointed to the method that it called.
I am using the Visual Studio 10.0 C++ compiler. The debug configuration uses the following command line switches when debugging /Gm /Od /RTCs /Zi /LDd Sorry I do not remember what each does. You can run the compiler in CLI and get a listing of what all the command line switches do. Those basicly turn of all optimizations.

Invert assignment direction in Visual Studio [duplicate]

This question already has answers here:
How can I reverse code around an equal sign in Visual Studio?
(6 answers)
Closed 4 years ago.
I have a bunch of assignment operations in Visual Studio, and I want to reverse them:
i.e
i = j;
would become
j = i;
i.e. replacing everything before the equals with what's after the equals, and vice versa
Is there any easy way to do this, say something in the regular expression engine?
Select the lines you want to swap, Ctrl+H, then replace:
{:i}:b*=:b*{:i};
with:
\2 = \1;
with "Look in:" set to "Selection"
That only handles C/C++ style identifiers, though (via the ":i"). Replace that with:
{.*}:b*=:b*{.*};
to replace anything on either side of the "=".
Also, since you mentioned in a comment you use ReSharper, you can just highlight the "=", Alt+Enter, and "Reverse assignment".
Just a slight improvement on Chris's answer...
Ctrl+H, then replace:
{:b*}{[^:b]*}:b*=:b*{[^:b]*}:b*;
with:
\1\3 = \2;
(better handling of whitespace, esp. at beginning of line)
EDIT:
For Visual Studio 2012 and higher (I tried it on 2015):
Replace
(\s*)([^\s]+)\s*=\s*([^\s]+)\s*;
with:
$1$3 = $2;
In Visual Studio 2015+ after selecting code block press Ctrl + H (Find & Replace window) and check "Use Regular Expression" option, then:
Find: (\w+.\w+) = (\w+);
Replace: $2 = $1;
For example:
entity.CreateDate = CreateDate;
changes to:
CreateDate = entity.CreateDate;
Thank you #Nagesh and Revious, mentioned details added.
The robust way to do this is to use a refactoring tool. They know the syntax of the language, so they understand the concept of "assignment statement" and can correctly select the entire expression on either side of the assignment operator rather than be limited to a single identifier, which is what I think all the regular expressions so far have covered. Refactoring tools treat your code as structured code instead of just text. I found mention two Visual Studio add-ins that can do it:
ReSharper
MZ-Tools
(Inverting assignment isn't technically refactoring since it changes the behavior of the program, but most refactoring tools extend the meaning to include other generic code modifications like that.)
Please see this question: Is there a method to swap the left and right hand sides of a set of expressions in Visual Studio?
My answer to that question has a macro that you can use to swap the assignments for a block of code.
I've improved the expression a little.
Replace
(\t+)(\s*)(\S*) = (\S*);
with
$1$2$4 = $3;
The reason is, it will look for lines starting with tab (\t). It will skip the lines starting with definition. E.g.:
TestClass tc = new TestClass();
int a = 75;
int b = 76;
int c = 77;
a = tc.a;
b = tc.b;
a = tc.c;
Would ignore the int a, int b and int c and swap only the assignments.
what about replace all (CTRL-H)
you can replace for example "i = j;" by "j = i;"
you can use regular expressions in that dialog. I'm not so sure about how you should pop-up help about them however. In that dialog, press F1, then search that page for more information on regular expressions.
I like this dialog because it allows you to go through each replacement. Because the chance of breaking something is high, I think this is a more secure solution
You can do search and replace with regular expressions in Visual Studio, but it would be safer to just do a normal search and replace for each assignment you want to change rather than a bulk change.
Unfortunatly I don't have Visual Studio, so I can't try in the target environment, but if it uses standard regexps, you could probably do it like this:
Search for "(:Al) = (:Al);", and replace with "\2 = \1". (\1 and \2 are references to the first and second capture groups, in this case the parenthesises around the \w:s)
EDIT
Ok, not \w... But according to MSDN, we can instead use :Al. Edited above to use that instead.
Also, from the MSDN page I gather that it should work, as the references seem to work as usual.

Resources