The visual studio F# interactive window keeps not opening in current directory - visual-studio

So I want to work a little bit in the interactive window in visual studio, to take a look at some F#.
Now View>other windows>F# interactive
In order to load my file I then type
>#load "Distance.fs";;
It is important to mention that Distance.fs is the current file that I am standing on.
however now, I get this error:
It looks like it keeps looking in the wrong directory, and it keeps doing this across different files and projects. Why does this happen? Is there any way I can configure VS to always open the interactive windows on the currently open directory

FSI defaults its current directory to whatever %TEMP% is and just needs a little help. Create a scratch script (as #TheQuickBrownFox suggested), and put your #load statement in there. Above that, add
open System
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
Highlight those two lines and press Alt-Enter to tell FSI to change to the script's current directory, then your #load statement should work (if needed, adjust your path, for example if you create a separate scripts folder, then maybe you now need #load "../Distance.fs", etc.

Related

Pathway to directory lost in R studio

I am relatively new to R studio, I am attempting to import a .RNK file to run on GSEA. However, the pathway to my working directory is lost and I keep receiving a file, "rt" warning message.
When comparing my working directory with my usual windows explorer file, the files themselves are absent from the working directory.
I have attempted to change the Default text encoding to UTF-8 but this has had no effect. I would be grateful for any suggestions to help with this problem?
That is a very common problem!
You have four options to select the correct file and path! Hope at least one can work well.
Manually without code, you can go to the top and choose Session->Set Working Directory -> Choose Directory... and then select the file.
You can just use the function file. choose() and look for the file on your computer and select it.
You can look for the file path on your computer and write it in R. Look in the local search engine for your computer and search for the file. For example: setwd("~/Desktop/University/Homework")
You can use getwd() in the console to know where the script is working and saving the files and then look for the files there!
PD: the best way to work in R and R-Studio/Posit for me is by creating a project. Doing so, you will have everything related to the script in one folder (new and old files!). It is similar to setwd()but better!

How to manage files with a batchscript via "Send To"?

I want to improve my file managent and need some help to get started.
For this specific script, my idea is the following:
while in Explorer
rightclick a file -> Send To -> "Apps[.bat]"
Then the script starts and does the following:
moves the whole directory (and subfolders) of the selected file to a specified location (in my case C:\Users\Name\Desktop\Apps\Files)
so sending Name\Downloads\Coolportableapplication\Coolapp.exe to the batch results in Name\Desktop\Apps\Files\Coolportableapplication\Coolapp.exe
creates a shortcut of C:\Users\Name\Desktop\Apps\Files\Coolportableapplication\Coolapp.exe in C:\Users\Name\Desktop\Apps
Is this generally possible with a batchscript?
This isn't my first batch but I've never dealt with unspecified files and English isn't my native language so I couldn't really find anything useful for my cause, though I am sure my little script won't be too much of a problem for you. Based on that batch, I want to create similar scripts but I just have no idea how to begin with that one.
Thanks a lot!
No need for a batch file but anyway.
1: Type shell:sendto into your explorer window and copy the shortcut to your directory "C:\Users\Name\Desktop\Apps\Files". This directory will now show as default in your Send To options.

How to call a function when opening program from file?

I made a project in visual studio 2010 (maybe a bit outdated but I like it this way).
With that project I made a separate project that handles the setup file for the installation. In this setup project I assigned a file type to my project so that the program can be started by double-clicking the file.
Now all of this works, the file gets a icon similar to the program and when I double-click it, the program opens. The only problem is that it doesn't open the file that was clicked.
I think I need to change something in the 'command' that is seen in the file type properties. As it is, I just have it set to "Primary output form Project 1". How can I make it so that it doesn't just open the program, but also calls a function that loads the data inside the file?
I'm sorry if this question has been asked before. I searched for it but I couldn't find a similar question. I'm also pretty new to the whole programming thing.
Thank you in advance!
You want to pass the filename to your program as a command line argument.
Add %1 to the end of the command you have associated with the file extension.
For example: "C:\path\to\MyProgram" "%1"

Configure launch command in Code::Blocks

I recently discovered Emscripten, and after downloading it, I decided to see if I could get it to work with Code::Blocks, so that I could easily test my applications to see how they performed when running as JavaScript.
I created a new compiler configuration, and set up all of the toolchain executables, except for the resource compiler (which doesn't seem to give me any problems), and the debugger. I wasn't really sure what to put in the debugger, because I remembered the debugger field as being a text-box. But when I looked, all that was there was a drop-down menu.
I managed to find a "Debugger" menu in the "Settings" menu, and when I opened it, there was a button called "Create config".
I created a new configuration, and pointed the executable path to "node.exe" (which runs .js files). I then went back to the compiler settings, and chose my new debugger in the drop-down.
I then tried to build and run a simple hello world application. But once it finished building, it gave me the message Execution of '[my file] ' in '[my project folder] 'failed. The actual build seemed to be successful, so I decided to manually run node.exe from the command line to see if I had configured the debugger incorrectly. And as I expected, it ran successfully.
While I was glad that I had successfully configured the compiler, I still was confused as to why the app didn't want to run. I also set Emscripten to create HTML files instead, to see if Code::Blocks would somehow recognize the appropriate program, and open it in the web browser instead. Of course that didn't work either.
What I am trying to figure out, is how I configure Code::Blocks' run command. Perhaps the debugger isn't even the right place to be looking. But I really need someone to help me figure out how I can configure this in Code::Blocks, as this is currently the only thing that is really giving me any trouble.
Thanks.
Possible but less ideal solution:
After some time, I was able to come up with a solution. However, I am sure that there are better alternatives.
To use this method:
Create a new build target called RunScript.
Set the compiler to No Compiler.
In the project properties, set the type to Console application.
Uncheck Auto-generate filename extension, and set the output filename to RunButton.bat.
Create a new file called RunButton.bat (or whatever you entered as the output filename).
Whatever you put in RunButton.bat will now be executed when you click the run button.
I also created a new virtual target that contained my RunScript target, and my main target, so that I don't have to switch targets whenever I want to test my application.
Problems with this method:
While this method does work, it is not ideal, as it requires you to have two extra targets (including the virtual target that I made for convenience). I would rather be able to just have everything contained in one target.
Slightly better solution:
A new solution that I decided to use, is to simply use the configure tools menu to create a tool that points to a batch file that runs my compiled programs.
To use this method:
Go to Tools>Configure Tools...>Add.
Fill in the name, and point the executable to the script that you want to run when this tool is used.
Fill in any needed parameters. You can use the built in ${TARGET_OUTPUT_FILE} macro to pass your output application as a parameter.
You can now use your tool by going to Tools>{My tool}, but you can set a hotkey by going to Settings>Editor...>Keyboard shortcuts.
Click the plus button by Tools, and click on your tool to set a shortcut for you tool.
Problems with this method:
While this method does eliminate the extra build targets, it doesn't let you run your script or run non-executable files by clicking the run button; which was the original intent. On top of this, you have to create a new tool anytime you want to add a new script.
I am hoping that someone else will be able to show me a better way of doing this, but for now this will work.
Might be a little late, but I was able to get the codeblocks run button to run any command by using a few post-build steps. The reason I need this is because my laptop has nvidia "optimus" and in order for my output program to see the discreet graphics card, I have to run it with the optirun prefix. So I added the following to the post-build steps in build options:
mv $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE)_bin
echo #!/bin/sh > $(TARGET_OUTPUT_FILE)
echo optirun $(TARGET_OUTPUT_FILE)_bin >> $(TARGET_OUTPUT_FILE)
chmod +x $(TARGET_OUTPUT_FILE)
It basically renames the output binary and creates a script replacing the original output binary name. When pressing the run button, the script is executed instead of the output.
On windows, you might have an issue running an exe extensioned file as a batch script so what if you generate the output file with a bat extension like in your first method, but with compilation and then rename it to exe in the post-build like this:
move $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).bat $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).exe
echo [WHATEVER YOU NEED TO RUN] > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).bat

ActivePerl. .pl files no longer execute but open in Notepad instead

I have perl scripts which were running in Windows 7 just fine as of this morning. I made the mistake of using NotePad as the default for opening/editng my .pl files. Now, when I attempt to run the unedited .pl files from a DOS prompt, the script does not execute but opens the associated source code file in Windows Explorer. This is the same for all my .pl files no matter the complexity (including classic "hello world".
I have been researching changes need to the registry - it all looks fine. Tried assoc and ftype changes - nothing. Tried reinstalling ActivePerl - no solution.
You don't need to go into the Registry.
Go into Windows Explorer.
Find a file that ends in a *.pl suffix.
Right click on it and bring up the Context menu.
Select "Open With" (It might just be Open... with an ellipse after it. I don't have a Windows machine at the moment to verify this). This will bring up a dialog box with all the various programs. NOTE: Perl may not be listed in the initial set of programs. No worry, just navigate to it.
On the bottom of the dialog box is a checkbox (Something like open all extensions with this program). Make sure that checkbox is checked.
After this, all files that end with *.pl will open with Perl instead of Notepad.
It is highly likely that someone did this with a Perl script in order to edit it, and messed up the file association.
However, who ever did this should be doped slap -- not for messing up the file association, but for editing a program with Notepad. Bad Developer! No doughnuts for you!
Programs should be opened with a Program Editor. If you're a real he-man, you can use VIM. VIM is a fast, and powerful program editor, but you will need to spend an internship at the feet of a VIM Ninja master in order to learn how to use it. Your first three to six months with VIM will be What a idiotic program! This is awful. Who wrote this crap?. Then, one day, you will understand its power and efficiency. You will be one with the program.
If you aren't brave or fearless or don't have six months to waste learning a programming editor, you can use Notepad++. Compared to VIM Notepad++ is like driving a Minivan. It's safe, it's practical, and it gets the job done.
Both editors do Syntax Highlighting which can help you find issues. Both, (VIM can -- I think Notepad++ can too) offer help with syntax and usage. Both can edit a file without messing up the line endings (They'll both detect whether a file has Unix or Windows line endings and keep those or allow you to convert them). Both will number your lines, have extensive cut/paste buffers, powerful search and replace features. And will not mess up your file encoding. Both offer visual diffing between files and do automatic backups when you edit a file.
Finally, these two editors will embed themselves into the context menu you get when you right click on a file. You can edit a file by clicking on it, and selecting VIM or Notepad++ directly from the context menu. No need to select "Open with..." and possibly mess up the file suffix association.
Never ever use Notepad to edit a program.
Sounds like your .pl extention association is now set to Notepad rather than perl.exe. If you are too busy to fix that, just type "perl yourscript.pl" in a command promot window to start the perl interpreter and to send your script to it to run.
See this answer to fix the association:
File Type .pl Association and Using cmd.exe to Run the Script
I have the same problem. None of the method mentioned above solve the problem. The problem actually came from Windows 7! Windows 7 Doesn't allow you to associate .pl to perl.exe in c:\Perl64 directory, for whatever reason.
Here is the solution:
If you look at c:\Perl64\Bin directory (or the path where your ActivePerl binary installed), you'll see another file: Perl5.14.2.exe. This is the same file as perl.exe in same directory but with version number attached as postfix in the name.
You can associate .pl file to that Perl5.14.2.exe instead of perl.exe. Bingo, it works now.

Resources