I have a project in visual studio 2013, using vb.net and I'd like to know how to import code directly from a text file and run it as code in the program.
I know this seems odd but it needs to be this way. Also I can't use a string builder and as i'm using vs it has a compiler built in.
Any help is appreciated
thanks in advance.
Open the text file in notepad
Create a new solution or open a .vb file in Visual Studio
If you create a new forms solution, press F7 to switch to code
view
Copy and paste the code from Notepad into the code editor
Run it and the code is auto-saved.
Why don't you let us see your code?
Related
enter image description here
I was working on my project about 4 hours and after I am done with it I saved it and try to rename the form name bu mouse right click ! after that it gave me like that error even I cant open my source code :( is there any why that can I save my codes at least.
in addition : when I press build it builds with no problem and I can use it.
I guess there was an visualstudio error, It changed the form name but didn't update successfully to the .csproj file. You can fix this issue by opening the .csproj file and edit it (by notepad or any text editor) or unload project and edit it, find the name of Form and mame sure the path to the form and form name is correct
Hope this helps!
Is there a way to write VBA Code in Visual Studio. If not is there any other alternatives?
The best you can do is bend the office Visual Basic Editor (VBE) tool to your liking. If you stay in it's native environment you get the full power of error detection, Intellisense, live code running, etc.
My tips...
In the VBE go to Tools > Options > Editor tab.
Turn off 'Auto Syntax Check'. You still get code highlighted errors but no annoying popups.
Go to the Editor Format tab and change the Font to Consolas (Western), Size 11.
For code indenting install the awesome, free, Code Manager. It adds some sick keyboard shortcuts.
Make the Edit toolbar easily accessible for code commenting/uncommenting.
Use Rubberduck to add unit testing, source control, code inspections and refactoring functionality.
With those simple changes you end up with a half way decent, useful, and keyboard friendly environment to write your visually appealing code. :-D
VBA code for Excel can only be written inside Excel using the VBA IDE. VBA projects are stored as part of the Excel file and cannot be loaded into Visual Studio.
However, you can write VSTO (Visual Studio Tools for Office) managed add-ins for Excel using Visual Studio. The following MSDN page covers both developing with VBA and VSTO.
Excel for developers
You could also use the interop features of VBA to consume a (COM) object written in Visual Studio from your VBA code.
I've been looking for an answer to this question myself.
Best I've found myself is the option of exporting a Module ect from Excel with the code you've already written (or blank) and load that up in the Visual Studio Environment.
It doesn't offer much, but the highlighted text and auto indenting is nice and makes it much easier to read compared to the standard VBA environment.
Then once you're done just import it back into Excel.
There is a VSCode extension to do this.
It allows you to write code in VSCode and export it to Excel.
This extension is very useful when you develop in VBA.
Here's the link to download the XVBA extension
Edit :
As Peter Macej said in comment, this solution only works for Visual Studio Code not for Visual Studio
You can certainly add and edit a VBA file (.vb) in your Visual Studio solution, but the intellisense will be worthless/screwed up.
This extension for VScode would probably provide a much better experience: https://marketplace.visualstudio.com/items?itemName=spences10.VBA
If your goal is have your VBA code exposed to source control so you can track changes, then it's still worth it to include in your Visual Studio solution, but just store that VBA code in a plain text file and then use the Excel interop to load it into the appropriate module within the excel workbook, e.g.:
xlWorkbook.VBProject.VBComponents["ThisWorkbook"].CodeModule.AddFromFile(#"C:\PathToYour\VBAcode.txt");
And there are other methods to delete/replace code lines, etc....
You can try xlWings package for python and use it with VS Code https://youtu.be/xoO-Fx0fTpM
What is a standard way to open the Designer (automatically generated) code for a VB file?
As a workaround, I can get to it by searching the entire solution for some keyword that is usually only found in those files: Global, Partial, etc.
Open the Solution Explorer. Along the toolbar at the top there is a tool Show All Files (it is the 2nd from the left on my version of visual studio). Click on that tool. All of your Form files will now have an arrow beside them. click on that arrow to expand. Look for the code file named FormName.designer.vb. Double-click on it to open.
You have to click the "show all files"-Button. Then you can also see the Designer.vb-files.
Note: For C# and VS 2008, but the same applies to VB in VS 2010.
http://peterkellner.net/2007/12/31/visualstudioshowallfiles/
http://blog.brianhartsock.com/2009/09/14/visual-studio-tip-show-all-file/
Keyboard shortcut for Show All Files
Show All Files is a useful little button in the Visual Studio solution explorer to give us a full view of the directory structure our project files are sitting in. When it is off, we only see the files that are explicitly included in the project, but when it is on, we see everything. This makes it very easy to explicitly opt a file into the project without doing an add -> existing item -> find existing item in directory structure and add to project.
The default when creating a new Visual Basic application in Visual Studio is to not show all files, and unfortunatly there is no setting you can adjust to change that.
Open the code file, and in the top-right corner of the code window is a drop-down containing all methods. Open this and select "InitializeComponent".
A screenshot from a newer version. Visual Studio 2015 and 2017 will look like this.
I have to copy files, make a new folder and then paste those files into the new folder so often.
I wonder if we can make a batch file or vbscript file to perform this task? Just select the files and choose "Group to New Folder" from the context menu. That'll be awesome!
I've found a solution in .NET 4.0
http://blogs.msdn.com/b/codefx/archive/2010/09/14/writing-windows-shell-extension-with-net-framework-4-c-vb-net-part-1.aspx
What you want to do is write an HTA application. You could have a selection listbox that could be auto-populated with the current folders files when you first launch the hta. Then just have a simple button than will prompt you for a folder path/name to create when selected and a simple sub to just move the selected files over, maybe through results to the screen or something. Obviously with error trapping and all that's a little bit much code to just paste in here, but it should be pretty easy to do.
If you're looking for help getting started with the hta interface, I recommend you check out the "HTA Helpomatic" which you can use to get the basic GUI, as well as selection box code. Obviously you can write the script subs to do the real work.
I'm doing VB coding using Visual Studio 2008.
How to import a .dll file into my program?
Can anyone help me please.
Thank you.
Add the reference (From your menu Project->Add Reference and browse for the dll file)
Put Imports DLL.Namespace at the top of your code.
You need to add a reference to the DLL...
Right click references in the project explorer
Click on the browse tab
Browse to your dll
Add a using statement in your code which points to said DLL