VSCode set shortcut "when" context to detect set breakpoints - debugging

I'm trying to set a keyboard shortcut for the command python.debugInTerminal on Visual Studio Code, but I would like it to run only when a breakpoint is created in the file. Inversely, if there are no set breakpoints in the file, this command should not run.
Is there a "when" context term to define this? For example, there is one called breakpointsFocused, but I dont think this is right.

There is a breakpointsExist true/false context key.
Open the Developer Tools/Console and then invoke the command
Developer: Inspect Context Keys
and click anywhere in vscode. Then in the Console open up the last object which should have a long list of available context keys. Search for breakpoint and there are a few.

Related

Assign VBS Script to a Keyboard Shortcut

I have a very basic VBS script that I plan on using frequently on my Windows 7 machine. Is there any way I can bind it to a keyboard shortcut so I don't have to navigate to it through Explorer obnoxiously.
I realize this question does not directly pertain to programming, or even scripting for that matter, but I could not find a straight answer online or through my own experimentation. I'm sure that there is a simple solution somewhere...
Thank you for taking the time to read, and hopefully respond to my inquiry.
Evin Ugur.
Windows does have built-in support for shell shortcut keys, where a keypress is used to invoke an *.lnk file that launches your VBScript (using either cscript or wscript).
Create a shortcut file, have it invoke your VBScript file directly or run cscript or wscript with the appropriate arguments, then save it and open its Properties sheet and set a keystroke in the "Shortcut key" field (I suggest something like Ctrl+Alt+K).
Like so:
Then, whenever you press Ctrl+Alt+K, regardless of the active application, your script will be invoked.
A more heavy-duty alternative is AutoHotKey: http://www.autohotkey.com/
Just as an FYI.
I tried this and I was not able to register the hotkey when I had the Icon in a costume folder. Even if I added the hotkey, it failed to work.
Once I moved the icon to the "C:\ProgramData\Microsoft\Windows\Start Menu\Programs", the hotkey started to work.

Using "open with" doesn't opens file in my application

I have OpenFileFialog realized in my Windows Forms application, but when I use Open With in file context menu, or add my item in context menu with command like "myapp.exe %1" it just opens application. Need I to do anything else to realize it?
This does nothing more than pass a filename as the first argument to your program. Just having an OpenFileDialog is completely irrelevant to that. You need to examine command-line arguments at startup and decide that you might want to open a file if one is given.

Keep focus in command window when debugging MATLAB

Often in MATLAB I turn on 'automatic' debugging with dbstop if error. When an error occurs, the function enters debug mode, and I am able to query the variables in the command window and see exactly what is going on. Very useful.
However, when this occurs, the focus switches to the editor. To me this seems counter-intuitive; we are in debug mode, so I want to find out what is going on, not look at the code (which I can already see in the adjacent window). I always immediately tab back to the command window.
So my first question is: Is there any point in accessing the editor at this point? What can I usefully do, when my script has crashed, in the editor?
And secondly: If I want to, can I change MATLAB's default behaviour to keep the focus in the command window?
To your second question:
If you use MATLAB's desktop environment, just deselect "Open Files when Debugging" in the "Debug" menu.
If you use MATLAB without the graphical desktop you can change this preference by modifying your matlab.prf file. This file stores preferences set from the GUI. The menu option described above makes the same changes as the manual process described below.
NOTE: Editing this file is entirely unsupported. Do so at your own risk.
Open the file from the MATLAB command prompt,
>> edit([prefdir '/matlab.prf'])
Or use the prefdir command in MATLAB to find the directory and then open the file in whatever editor you prefer.
Search for a line that says
EditorGraphicalDebugging=Btrue
Change it to read
EditorGraphicalDebugging=Bfalse
If the line doesn't exist, add it to the file.
Restart MATLAB.
You can use the invocation stack to see how you came about to the particular error position. Sure, you can use dbup and dbdown for this in the command window, but it's much easier in the editor.
Also, seeing the variables (and their values, using mouse hover) in the context of the code that caused the crash is far better for understanding the root cause of the error than just seeing the static values.
I can answer only your first question.
Things you can do in the editor:
Mouse hover a variable, which pops up a 'quick view' window.
Any action you can do when not in debug mode, treating the function as a script - running a line (highlight + F9), running a code block, etc.

Output a watched Visual Studio variable to a file

Is there a way in Visual Studio (2008 if it matters) that I can, in debug/break mode, write the contents of a variable to a text/XML file?
The scenario is that I have a long process running in debug and I have realised too late that I haven't logged enough detail about the events that the process has been monitoring, but fortunately a history is still available within a variable in the code.
I could trawl through the tens of thousands of items in this list, but it's not going to persist once I hit stop on the application ... there is no obvious context option for this, but is there any way, a better way than manual? Or is there no hope and I just need to hit stop, re-tool the logging function and run the thing again?
Aside from trying to hit a breakpoint, modify the code and re-write to make a better logger, is there a way of not losing that in-memory data?
One way to do it would be to use the immediate window (menu Debug -> Windows -> Immediate). In the window that appears you can use the "?" to query the value of a variable.
Assuming your history variable is a string you view its contents by typing the following in the immediate window:
?history
You could copy and paste the output from there into a text file or alternatively ask Visual Studio to log all command window output. To do this type:
>log "c:\test.log"
>? history
>log off
Log is an alias for Tools.LogCommandWindowOutput and accepts the following parameters:
Tools.LogCommandWindowOutput [filename] [/on|/off] [/overwrite]
Check out the MSDN article Log Command Window Output Command for more information.
 
I think that my answer is pretty much the same as JamesPickrell's, but from the Immediate Window you could also do something like this:
My.Computer.FileSystem.WriteAllText("c:\temp.txt",history,True)
This would output the content of the "history" variable to a file called c:\temp.txt.
Thanks to Richard's answer, this is working for me.
System.IO.File.WriteAllBytes(#"c:\Temp\temp.txt", myVar);
Make sure that C:\Temp exists.
The reason for writing to a folder and not to the root C:\ is to avoid UnauthorizedAccessException when not running Visual Studio as administrator.
I found useful/demonstrative/shareable to save the variable as a json string to the file. From Immediate Window enter the following:
string jsonedVariable = Newtonsoft.Json.JsonConvert.SerializeObject(VARIABLE);
System.IO.File.WriteAllText(#"C:\FILENAME.json", jsonedVariable);
Not sure from which version it's supported, but you can simply put it in the WATCH window, then right-click copy past wherever you want.

Passing command line parameters to VB6 IDE in console app

I have a VB6 console app and it uses command line parameters. For debugging, I would like to be able to start it from the IDE and ideally be able to pass it those parameters to see how it normally operates. I realize I could set a breakpoint at the appropraite place and use the Immediate window to set the values outside the command line, and I have used a couple of other workarounds in the past, but is there a way to do this as if I had actually started it as a console app?
Select Project | Properties, select the Make tab, enter the command line params in the Command Line Arguments text box. These will only apply when run in the IDE.

Resources