Finding what you need in the Microsoft® Visual Studio® 2005 documentation, which has over 200,000 topics, can be a daunting task. The Doc Detective is here to help, utilizing his investigative skills to probe the depths of the documentation.

Can’t find what you’re looking for? Just ask - if it’s in there, I’ll find it for you; if it isn’t, I’ll let you know that as well (and tell you where else you might go to find it).

Have a question for the Doc? Send your questions for future columns to me at docdetec@microsoft.com.

Dear Doc Detective,

I’ve got one here I’m just not figuring out. What I have is a Visual Basic application that makes a "shell" call to a Cygwin shell. While in that shell a multi-line file is generated and saved. The application then leaves the Cygwin shell and opens the created file for some string manipulation.

However, since the file was created in a pseudo-Unix environment, the <Ctrl>M line feeds at the end of the lines don’t convert when opening the file in Visual Basic-I just get one continuous line.

I’ve been told to use the Replace function, which I’m totally unfamiliar with-I can’t figure out how to represent "<CtrlM>" in order to replace it. Can you offer any assistance on this?

- Frustrated in Fredricksburg

Dear Frustrated,

Unix? The Doc doesn’t do Unix! Seriously though, the source of your problem is that Unix and Windows represent line breaks in text files differently. Unix uses a single carriage-return character code; Windows uses both a carriage-return character code and a linefeed character code.

If you look at a table of ASCII character codes, you will see that the <CtrlM> character is the same as the ASCII Chr(13), represented in Visual Basic by the constant vbCr. The linefeed character (Chr(10)) is represented by the constant vbLf, and the constant vbCrLf will insert a carriage-return/linefeed combination, which is what you want.

The following code, using the Replace function, should do what you want:

Dim fileContents As String
fileContents =
My.Computer.FileSystem.ReadAllText(
"MyUnixFile.txt")
fileContents = Replace(fileContents, vbCr, vbCrLf)

To learn more about character codes and constants, look for the topics “ASCII Character Codes Chart 1” and “Print and Display Constants” in the MSDN Library. The topic “Replace Function (Visual Basic)” explains the syntax for the replace function.

- Doc D

Dear Doc Detective,

I recently installed the Visual Basic Express Edition, and while it meets most of my development needs, there is one big problem. When looking at the available project types, I was surprised to see that there is no Windows Control Library project.

I need to be able to create controls, but I’m an impoverished college student and I can’t afford to shell out the big bucks for the full version of Visual Studio. Please tell me it isn’t so, doc?

--Bowled over in Boulder

Dear Bowled,

I have some bad news, and I have some good news. The bad new is that you are correct-there is no Windows Control template in the Express Edition. The good news is... it doesn’t matter!

The Windows Control Library project template is actually just a plain old Class Library project with a User Control template. You can indeed create controls with the Express Edition by opening a Class Library project and adding your own User Control template.

The topic “Understanding the User Control Designer” provides step-by-step instructions for creating controls without using the Windows Control Library template. So, in answer to your question-it isn’t so!

- Doctor D

Dear Doc Detective,

The Windows application that I am developing in Visual Basic needs to be restricted to a single instance per user. If the user tries to launch a second instance, I want to display a message and then activate the first instance.

I’ve found an example of how to do this online, but the example contains over 400 lines of code, much of which I don’t understand. Surely there must be a simpler way to do this.

- Overwhelmed in Oakland

Dear Overwhelmed,

You’re right-400 lines of code for creating a single-instance application is a bit overwhelming, and also unnecessary. Would you believe you can do it with a single line of code? You can, if you’re using Visual Basic 2005!

Windows Application projects now have a property that eliminates the need for all that messy code. Check the “Make single instance application” checkbox in the Project designer, and it just works. For more information, see the topic “How to: Specify Instancing Behavior for an Application” in the MSDN Library.

If you want to display a message to the user, you can do so using the My.Application.StartupNextInstance event, also new in Visual Basic 2005. Just add one line of code:

MsgBox("Whoa dude! It's already running!")

The topic “My.Application.StartupNextInstance Event” provides more information about this event.

As for activating the first instance of the application, you don’t need to do anything; it will automatically bring the application to the foreground whenever a user tries to launch a second instance. It couldn’t get any easier than that!

- the Doc

Doc’s Doc Tip of the Day

Ever try to save a favorite topic so that you can easily find it again later? Frustrated by the fact that Visual Studio Help favorites end up in your Internet Explorer Favorites list? Here’s a tip for you.

The new version of Document Explorer in Visual Studio 2005 includes a Help Favorites window where you can store links to your favorite topics independent of Internet Explorer. Simply right-click on any topic and choose “Add to Help Favorites.” The topic will be added to the list in the Help Favorites window; click on the tab next to Contents and Index to access it.

You can also save searches and reuse them later. Just perform a search in the Search window then click the “Save Search” button on the ToolBar; the search criteria will be saved to the Help Favorites window. Clicking the link in the Help Favorites window will run the search again; any new topics that have been added since your last search will be added to the results.

You can change the order of links in the Help Favorites window, and you can also rename links to something more meaningful. Moving to a new computer? You can even export your favorites and import them on another computer-see the topic “How to: Copy Help Favorites to Another Computer.”

Found a topic in Help that doesn’t help? Tell the Visual Studio documentation team about it at vsdocs@microsoft.com.

URLs

http://msdn2.microsoft.com/en-us/library/60ecse8t(en-US,VS.80).aspx

http://msdn2.microsoft.com/en-us/library/f63200h0

http://msdn2.microsoft.com/en-us/library/bt3szac5(en-US,VS.80).aspx

http://msdn2.microsoft.com/en-us/library/114xc3e5(en-US,VS.80).aspx

http://msdn2.microsoft.com/en-us/library/8fz4ssw2(en-US,VS.80).aspx

http://msdn2.microsoft.com/en-us/library/b9z4eyh8(en-US,VS.80).aspx