I want to watch specific variable in visual studio 2010.
For example,
string stringVar = "blablabla";
I want to know when this variable is created? when modified or when assigned something to it.
--
In my application, one of variable value changing abruptly and I can not figure out why and I dont want to debug whole code.
You could convert your variable into a property and set a breakpoint in the setter?
string _stringVar = "blablablba";
string stringVar {
get
{
return _stringVar;
}
set
{
_stringVar = value;
}
}
You could always swap it back after you solve your issue
How about a break point with condition specified to has changed
Choose Has changed if you want to break when the value of the
expression has changed.
Related
I've come across a minor issue (for this time) which is the following:
When I debug my code in Visual Studio Community 2017 and edit anything while it's inside a foreach, then all variables in that scope, including the variable being iterated, are set to null.
foreach (var bFile in baseCache) {
var file = lastFolder + "\\" + bFile.Value.relPath;
if (!lastCache.ContainsKey(file)) {
if (file.Length > 255) { continue; }
// TODO: do stuff when the file isn't present in the last backup
}
var lFile = lastCache[file];
var comp = bFile.Value.compare(lFile);
if (!comp.HasFlag(FileData.CompareFlags.CRC32 & FileData.CompareFlags.Size)) {
}
}
In this part for example, I had a breakpoint at the 4th line, where it goes if "lastCache" doesn't contain the key that's represented by "file" at that time.
At that time there was just the continue; sitting at that spot and I changed it as it is shown now, and when I pressed F10 to step further because I wanted to verify this issue at that point, all variables shown in the snippet went 'null'.
Can someone explain to me why this is happening and how I can hopefully avoid this?
Currently this is just a minor bother when I'm changing things, but if this happens later in a bigger project it will be a real problem...
Edit: here's a link to the whole code, it's just a console app so luckily, that's easily done
https://www.pastiebin.com/5cf3e7dfa2985
The scope of variables declared in the body of the loop is this very loop body. When you are entering the loop body they are not yet defined. E.g. lFile and comp will not have a value until the assignments have been executed.
If you want to preserve the value over several loops, then declare the variables before the loop.
A note to using dictionaries. it is more efficient to test the presence of a key and to get the value at once with TryGetValue
if (lastCache.TryGetValue(file, out string lFile)) {
// do something with lFile.
} else {
// file is missing
}
The current solution that works is
gameObject.GetComponent<ParticleSystem>().startSize = 1
but VStudio 2017 reports that startSize is obsolete and should be replaced with main.startSize. But when I do that, I get an error:
Cannon modify the return value of ParticleSystem.main because it is not a variable.
So how should I set the start size value?
ParticleSystem.main returns a struct, not a class. Struct's are value types, in that when you move them around their values are copied into a new object. You have to first store the returned value in a variable then modify it.
var main = particleSystem.main;
main.startSize = 1;
I need a Text field of my program to be treated as a LONG type variable and be processed in a mathematical operation. The value of this variable needs to be specified every time by the user and I want the program to treat this value not as an integer but as a long indeed.
I have treated other fields as integer and they work fine with this kind of code:
HourField.IntValue
now notice that .IntValue that obviously says to the program to take the content of the HourField whatever is in it and treat it as an integer.
But unfortunately there is no equivalent for the long type in fact if I try to write .LongValue, C# just doesn't recognise this function....there are other similar functions like .FloatValue or .DoubleValue etc. but there is no such thing as .LongValue.
However I even tried to use this kind of syntax:
Convert.ToInt64(FileSizeBytesField);
or something like that and in theory the compiler doesn't give me any error for the compilation etc. but if I try to actually make the calculation by pressing the button the program crashes and Visual Studio tells me that the type of casting is invalid.
Please please pease help me with this. It's the last thing I need to actually finish my program!!!
P.s. I am posting some screenshots of what I got and of my source code. Thanks
program's source code
Debugging error in Visual Studio after program crash
I guess the FileSizeBytesField you are trying to take a value from is an instance of NSTextField or another subclass of NSControl. In that case, you can take the value of control using properties like IntValue or StringValue. So, to convert the value to long type try this:
Convert.ToInt64(FileSizeBytesField.StringValue)
Or, using more common approach already suggested by Hooman Bahreini:
long fileSizeBytes;
if (long.TryParse(FileSizeBytesField.StringValue, out fileSizeBytes))
{
// use fileSizeBytes
}
You can use Parse, to convert the string value to long
long l = long.Parse("453216");
If you want to ensure that your input is a valid number, you can use tryParse
if (long.TryParse("45263572", out l) == true)
{
// use long value
}
else
{
// input is not a valid long value... handle the situation here
}
I want to set value to the Test Variable using Custom Code.
Can you tell me how to do it as i am not able to access the variable from code.
I need to access the User Variable URL in my custom code and set the value.
Please help me if you know how to do it using Custom Code.
Thanks,
Madhan
Based on your question:
1. Click on File menu and then Settings, it will open Properties pane.
2. Click on "+" to add user variable and give a name.
3. In your custom code, type below code:
string s = "https://www.google.com/";
this.Context.TestProfile.SetVariableValue("NameOfYourVariable",s);
To retrieve the value of given variable:
string ss = this.Context.TestProfile.GetVariableValue("NameOfYourVariable");
CodeActivity5.Report("Variable is : ", ss); //(This line will print your variable value)
answer provided here is valid when the need is to set string values. The "SetVariableValue" method takes two "String" type parameters. This limits the ability to set Int32 type variables. Obviously, C# throws an error when trying to set an integer value.
Now, an integer value is particularly useful while setting values for loop iterations. I am not sure whether this is a limitation of the tool or whether my lack of knowledge. So, to work around this, i used the output property of custom code activity. To do this, create a custom code activity and create an output property of the desired type, say Int. Now, assign a value to this output property using the line:
this.ActivityName.Output.property name = property value
This is available in UFT help and can be useful while trying to pass values other than string between different activities in a flow.
Before I used to point on the variables and they used to show their values. strong textut after I installed Visual Studio 2010 full version, I can't see variables anymore.
Sometimes I would have to do something like that to see te variable:
String var1 = "test";
var1=var1;
Please note, I check variable value after it has been initialized and after the value has been assigned.
The name 'buyCategory' does not exist in the current context
Change to debug compilation and disable compiler optimisation.
Looks like your break point is on the line that inits the variable. YOu need to execute that line ( F10 / Debug->Step Over ) before that variable will come into existence
In the screenshot, buyCategory hasn't yet been initialized or assigned. Press F10 and try again.
It's possible you are in a different thread as the variable you are trying to see in the Locals menu.
Open Solution Explorer -> Right Click on Solution -> Select Properties.
After selecting Properties, you will get one Popup window. In the window change configuration Type to Debug and then click Ok.