How can I execute VB code entered in a textbox [duplicate] - vb.net

This question already has answers here:
Vb.net Run Script inside Textbox
(2 answers)
Closed 2 years ago.
How can I have a button execute VB code I entered in a text box?
E.g. when I wrote this in text box:
form1.Show()
and the button is clicked, form1 will be shown.

What you're looking for is like eval() for javascript or PHP.
.Net (including the VB, C#, and F# languages) is a general purpose platform, where javascript and PHP are intended for more specialized situations (javascript is usually in a browser with limited APIs, and PHP was originally a web CGI platform only).
It's okay for a specialized language, which can be sandboxed and API-limited, to include an eval() feature. But for a generalized language, which needs access to all of APIs in a system, this is extremely dangerous. There are MASSIVE security implications. As a result, this kind of thing is not impossible (there's CodeDOM, Roslyn, compile+Reflection.Load, etc), but none of them are quick or simple to do. There's not a simple eval() function out of the box. And that's a good thing.

Related

Is there a way to “compile” a list of VBA functions into a DLL file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
We have some customized VBA functions in a script inside an app (not Excel) and they are called by other scripts in this app. We are sharing the scripts but would rather not expose the single script with the functions. The app only calls an embedded macro or a dll, so I’m thinking somewhat “compile” these functions into a dll file, and the project is small so we try to avoid buying stuffs. Maybe transfer into VB.Net? Any idea is welcome!
You could do that in Office 2000 Developer Edition... since then, there's no way to compile VBA code into a .DLL, VBA is embedded in the host document.
You can port your VBA code to .NET - I'd warmly recommend C# over VB.NET, because the VB.NET syntax might look like it's "so close" to what works in VBA that you could be tempted to think it could "just work", but it's very deceptive and you wouldn't be writing VB.NET, but glorified VB6.
To name a few, implicit late binding, implicit/undeclared variables, global functions; all are things VBA seamlessly handles, that you absolutely do not want in .NET code. Default/implicit access modifiers are reversed (VBA: Public, .NET: Private), implicit ByRef becomes implicit ByVal, ...and so many other little things make grabbing VBA code and compiling it in VB.NET a very frustrating experience.
I'd recommend thoroughly unit-testing the existing VBA code, and then porting these unit tests over to a new .NET solution, and writing whatever code is necessary (from scratch) to get the tests to pass in .NET.
If the VBA code has too many hard-wired dependencies and can't be reliably unit-tested, then it needs to be refactored to allow proper test coverage first: a full suite of unit tests documenting every behavior and edge case of the functionality is the only way to reliably ensure that both the original code and the new code are doing exactly the same thing.
Or you could cowboy it and just port the VBA code to .NET.
Mind, COM interop brings its own set of "fun" problems. Good luck!

VB.Net Formatting Output

I'm converting a project which started life as a PHP application to a Windows Forms Application in VB.Net, and am not sure how to go about formatting my output. The original, of course, simply outputs in HTML, and I've thought of using a WebBrowser control, but is there a better/more standard/any other way to display formatted output?
I'm new to Visual Studio, and Windows application programming in general. I've done a fair amount of work with VBA, so I'm familiar with the basics of the language, but still trying to figure out a lot of things. I think my question is beyond asking how to display output in VB.NET, as I'm familiar with the various form controls, such as label and textbox, but I googled extensively before posting here, and could not find what I was looking for. VB tutorials I've found are along the lines of "A variable is...." which I don't need. This site, while pretty basic, does have some interesting stuff, and is where I came across the WebBrowser control, but I'm just wondering if that's the best or only way to do what I want.

Should i go with vb.net or VBA? Mostly working with excel files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm starting a new job - my first - as a financial controller. The job will mean working a lot with excel files, for example formatting a document so that it can be imported and understood by other financial programs like SAP, or creating charts with the data in a document. There might be many specific tasks where vb.net/vba can come useful so I would really to be good at it.
My question is, should I do vb.net through visual studio or vba via Excel? My understanding is that you can achieve basically the same things with both in terms of excel-files, but perhaps vba is quicker and easier to learn and use. Vb.net on the other hand has a much better IDE through visual studio and learning it will give me a knowledge which can also be more useful elsewhere. Is this correct? Instead of trying one of them only to find out after some time that I should have gone with the other, I hope to get it right from the start.
I use both VBA and VB.Net so I would recommend learning both.
Learning VBA is easier than learning VB.Net because there is so much less to learn. I find VBA tutorials easier to master mainly because most VB.Net tutorials seem to be more concerned with demonstrating the amazing functionality of VB.net than teaching you the basics of the language. Once you have VBA under your belt the learning curve to VB.Net is not too steep.
You access Excel workbooks from VB.Net using an interop which can read and write from any Excel version from 2003 onwards. It may be able to access earlier versions but I do not know any one who uses earlier versions so cannot test. The interop is slow. If your program is doing nothing but manipulate Excel worksheets, you are probably better using VBA.
VB.Net's forms have far more controls than VBA's. If you are trying to create an attractive, flexible, adjustable user interface then VB.Net is the one to choose.
VB.Net is compiled to an immediate language which is then compiled to machine code at runtime to take advantage of the capabilities of the machine it is running on. VBA compiles to an immediate language which is interpreted at runtime. For heavy processing, VB.Net programs can be thousands of time faster than VBA macros.
VB.Net creates executable programs (MyProgram.exe) which can run on any Windows machine making them easy to distribute if necessary. VBA macros run within Excel so the user need to have and open Excel to run them.
To summarise: start with VBA but then try VB.Net once you have mastered the syntax.
Incorrect. VBA is far faster has it runs in process. All calls are marshalled into network protocols to be sent cross process.
Plus you have to load COM with VBA. To use Excel you have to load COM. To use VB.NET with Excel you load COM and .NET - a far bigger resource load.
The code would be almost identical.

Auto Complete Box in VB [duplicate]

This question already has answers here:
A New and Full Implementation of Generic Intellisense
(2 answers)
Closed 9 years ago.
I am making a simple application and I would like to perform an action that suggests code as you type, just like other programming languages do. Examples of where this has been used is within programming language software such as ... visual basic, Xcode, Small Basic, etc. My application would evolve around a RichTextBox and as you type, a box would appear below showing suggestion's of words. If you are still confused with my question see images below, showing examples from Visual Basic and Small Basic
Small Basic
Visual Basic
.
These drop down suggestion box can also be accessed with CTRL + SPACE
I know this is quite a complicated and longwinded question but any suggestions on how I can create this would be great.
I found a solution. However the project is programmed in c# instead of vb.net so I simply followed the instructions online you can find the solution here

Alternative IDE for VB6 and VBA [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I've been spoiled by Visual studio 2008 and Eclipse and have to do a little maintainence work on a VB6 app.
Does anyone know of an alternative/ updated IDE for VB6?
A rewrite is not an option I'm just fixing a couple of bugs and it's a big codebase.
I have never heard of an alternative IDE for Vb6. However, these two (free) VB6 add-ins are indispensable and will make your life easier - especially if there is a lot of code. They are equally effective for VBA in Microsoft Office.
MZ-Tools: provides a superb collection of IDE tools - finding unused variables, unused methods, a great "search all", code snippets. Written by Carlos J. Quintero, to whom I now owe hours and hours of time.
http://www.mztools.com/v3/mztools3.aspx
And SmartIndenter, which takes care of all the auto-indenting. It does one thing and it does it well.
http://www.oaltd.co.uk/Indenter/Default.htm
Some time ago I did some research and nothing came up. I don't believe you have have any real alternatives...
But you could consider checking this out:
http://www.axtools.com/products/cs2k3vb_screenshots.htm
It looks quite promising.
Addin for Visual Basic 6.0 packing more than 50 professional tools and
assistants. The Code View Assistant
enriches the standard VB6 code editor
with branch lines for conditional
statements, end-of-line details, and
hotspots. Moreover, the Code Analyzer
pinpoints dead and slow code, the
SmartComplete and AutoText tools help
you write code with a proficiency you
never dreamed of, while the Enhanced
Project Explorer with expanding code
and Code Flow View can make accessing
a code location the speedy action you
always needed. Other tools: Extended
Find, Find References, Designer
Explorer, Code Formatter, TabOrder
Designer (with auto-order), HotKey
Designer, Error Handlers Inserter,
Exception Protection, Spelling
Checker, Strings Reviewer, Comments
Conformity Checker, Task List Manager,
Code Snippets Manager, Naming
Standards Manager.Version 2007 adds
Designer Analyzer, User Interface
Standard Properties Manager, Library
Explorer including Designer Snippets,
many enhancements in most subsystems.
Because the VB6 IDE does not detect file changes made outside of the IDE, it can be quite difficult to develop code outside of the VB6 IDE, without running the risk of loosing code changes.
But it is possible to run a VB6 project build from the command line so it is possible to do simple VB development using any text editor/IDE capable of running a command an capture it's output.
But for things like GUI changes and debugging there is really no choice but to revert back to the VB6 IDE.
Here is the commands needed to run the build from the DOS prompt:
set PATH="d:\Program Files\Microsoft Visual Studio\VB98\";%PATH%
vb6.exe /out ErrorFile.txt /make MyProject.vbp
FWIW the Zeus IDE has the ability to import a VB Project file and display the project details into project/workspace tree. It will also run the build an capture the output.
Visual Basic Tools For Visual Studio lets you open vb6 project in visual studio 2012/2013, with basic outlining, syntax coloring, and a few more things.
Its a work in progress, but if like me you have some living dead vb6 programs to maintain, it's... intriguing.
Except there's no GUI editor, no debugging. I fear these points (especially debugging) are deal breakers. (Of course, I understand that not everything is possible).
Yeah, no alternative IDEs to VB6 afaik. But one indispensable add-in I used was CodeHelp. It gives you tabs! for the windows, easy tab ordering, fullscreen switcher and maybe a mousewheel add-in. Check it out from the Planet Source Code page. And be sure to check the comments for a download to a setup file as I had problems with the source code and the author's site.
CodeHelp Add-In 2.2 Amazing VB6 plugin to help organize and coding.
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=62468&lngWId=1
I used Visual Assist X while programming in VB6. It's a code coloring add-in.
A must have, once you got used to VS2005+
I don't know if VB6 is still supported in current version, so you should take a look and see for yourself (and perhaps get an older version)
DoyleSoft BASIC alternative visual basic
jabaco compiler too-