Saturday, August 27, 2005

Converting VB.NET to VB6?

I've just hit an interesting situation for the first time.

I wrote a new program several months ago in VB.Net. Now, I have to update a legacy Visual Basic 6 program and need some routines from that VB.Net program.

There has been a lot of attention on how to best convert from VB6 to VB.Net, but now I am facing the opposite situation. I have to believe that this will be more common as time goes on, as legacy code can take a long time to truly fade away.

I know I can use COM Interop to use the VB.Net code directly from VB6, but I don't want to require that the .Net Framework be installed for users of the VB6 application. The best solution is modify the code to work in VB6. It's going to be interesting, I'll keep you posted...

Joe Kunk

Monday, August 22, 2005

Getting the volume label in .Net

To get the volume label of a particular drive, use the Dir method in the VisualBasic namespace. Note that you can ONLY use the Volume fileattribute if you want to get the volume name. Use of any other attribute will prevent the volume label from being returned. On my system, the DVD drive is my E:\, so the following statement successfully returned the volume label for me:

'Get the CD/DVD volume label
Dim VolumeLabel As String = _
Microsoft.VisualBasic.Dir("E:\", FileAttribute.Volume)


Joe Kunk

Sunday, August 21, 2005

Please feel free to comment on my posts

I just changed the settings on this blog to allow comments by anyone, not just members of blogger.com. I want to encourage comments. If you read one of my posts and have anything to add, please do so. I look forward to the dialog.

Joe Kunk

Using IO.Directory.GetFiles with a filename wildcard

I got an "Illegal characters in path" error on the following statement:
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp\*.txt")
and from the documentation it was not clear to me why I was getting the error.

Turns out that you must use the second overload version of the GetFiles method with two strings if you want to include a wildcard.

In the example above, the two possible correct versions of the GetFiles method include:

Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp")
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp","*.txt")

The second statement provides the desired result of returning a string array of all filenames with a txt extension in the c:\temp folder. The first statement returns all files in the c:\temp folder which can be scanned with a loop for further processing.

Note that the single string overload verison of GetFiles can only accept a directory name.

I hope this helps clarify a point that managed to confuse me. As usual, it's obvious once you know the answer!

Joe Kunk

Saturday, August 20, 2005

How to set the Xceed LicenseKey property in a class

I have been playing with the capabilities of the Xceed FTP control. I ran into a point of confusion and I wish to share the solution. Note that there was no problem or bug with Xceed's FTP control, I just wasn't clear on how to set the needed LicenseKey property in a class rather than in a form.

All of the Xceed controls require a LicenseKey property be set with a valid license code in order to function. The example on their web site assume that you are using the component(s) on a form and show how to set the LicenseKey property just before the call to InitializeComponent(). I confirmed that this works fine on a form.

I want to write a wrapper class around the FTP control so that I can hide some of the complexity of its feature-rich interface and provide a more user-friendly interface, exposing only those capabilities that I need. Since there is no form, setting the LicenseKey needs to be slightly different and I could not find an example.

Below is what I found to work:

Public Class FTP_Example
Private FTP As Xceed.Ftp.AsyncFtpClient
Public Sub New(ByVal FTPSite As String)
Xceed.Ftp.Licenser.LicenseKey = "My License Key Goes Here"
FTP = New Xceed.Ftp.AsyncFtpClient
End Sub
End Class

I hope you find this tip useful.

Joe Kunk

Xceed is a registered trademark of Xceed Software Inc. http://www.xceedsoft.com/

Friday, August 19, 2005

GLUGnet Presentation 08-18-05

Last night I gave the feature presentation to GLUGnet, the Greater Lansing User Group for .Net. The topic was language enhancements and conversion recommendations for Visual Basic 2005. The Powerpoint presentation is available for free download at http://portal.artemis-solutions.com/glugnet/go/iris/3373/en-US/DesktopDefault.aspx. Download the file named, "GLUGnet August 18, 2005.zip".

There was an error on the example for the CONTINUE statement which has been corrected.

The Internet web address for all the sites I mentioned at the GLUGnet meeting were added as the last slide of the presentation.

Thank you to GLUGnet for allowing me to give this presentation. I learned a lot by doing the research for the presentation and I really enjoyed the experience. GLUGnet is a great user group and I'm very proud to be a part of it.

If you find yourself in the East Lansing Michigan area on the third Thursday of the month, please feel free to join us for free food and drinks and an educational meeting. See the web site http://www.glugnet.org for more information.

Joe Kunk

Thursday, August 11, 2005

Two VB.NET blogs you don't want to miss

Today I ran across two blogs about Visual Basic that are awesome resources.

The first is the blog from the Visual Basic .Net IDE team. From their introduction, "This blog is hosted by the program managers, developers, and testers who work on the Visual Basic Integrated Development Environment (VB IDE). " This blog has an awesome FAQ and further tips on the cool new feature of Code Snippets. Other topics include code generation for overrides, a snippet editor, refactoring tool, new debugger features, and an awesome list of the 10 best new features in Visual Basic 2005. It can be found at http://blogs.msdn.com/vbide/default.aspx

The second is "Don't be Iffy" by Julie Lerman. This is a extensive informal blog by a self-employed programmer who clearly loves programming and Visual Basic.Net. Her personality really comes through on her blog. I think you will find it both informative and enjoyable. http://www.thedatafarm.com/blog/

Joe Kunk