Welcome Guest!
Create Account | Login
Locator+ Code:

Search:
FTPOnline
Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Free Trial Issue of Visual Studio Magazine

email article
printer friendly
get the code
more resources

Evaluate Strings and Convert Data in .NET
These VB.NET methods let you evaluate strings as Basic expressions and convert data to and from readable forms.
by Edward G. Nilges

Technology Toolbox: VB.NET

When you heft the Visual Studio .NET box, it's hard to believe anything could be missing. But Microsoft left five useful VB.NET methods out of the box. I'll delve into the three most critical ones here, and you can read about two others in the sidebar, "Convert Strings to Objects and Vice Versa". These methods will help your code evaluate logical, mathematical, or string expressions; convert Unicode strings to and from open notation (one method for each direction); convert any object to a string; and convert many objects (including all value objects) from a string.

I've packaged these missing methods as a stateless VB.NET utilities object, and I have thrown in a topFive.exe you can use to try these methods. The EXE displays a form allowing you to evaluate each method (see Figure 1). You can deploy this functionality by grabbing utilities.dll from the supplied code, referencing it in your project, and declaring a stateless utilities object:

Dim objUtilities As utilities.utilities

Figure 1. String Along With This Converter.

Don't declare the object As New, because it only contains code. It lacks a "state" in the form of private variables that occupy storage. Stateless objects can create and destroy value objects in the stack and reference objects in the heap, yet they don't take up room in the dynamic heap; they represent one less problem for the .NET garbage collectors. But you should avoid stateless objects when the object needs to remember a state (obviously) and your code is saying, "Object, now you are in state X," by means of parameters. Code by "all stateless all the time" programmers often bristles with parameters representing the actual state of the real object. This kludge is concealed by the overtly stateless style.

Back to top














Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home