Pardon Our DustThe 7 Steps of Software Development - Revisited

3 Quick Examples: Temp File, Topmost Form and Current User Name

July 13th, 2007

In this article I revisit 3 of my VB6 API based functions.3 Quick Examples

In VB6 there were many times where a programmer had to resort to API calls to get things done. However, the .NET Framework has simplified many of these calls to a line or two. Let’s look at three examples: Temp File Name, Form on Top, and Current User Name of the Current User.

Getting a Temp File NameThis function on my VB6 Notebook Archive Site shows the API’s that you use to get a temporary file name. Here’s how you would do it in VB.NET:

Dim TempFile As String = My.Computer.FileSystem.GetTempFileName()

This function returns a uniquely named file in the current user’s temp folder structure. It is generally safer to write to this location than it is a fixed location or a application specific location, such as the current path. If you did want to use the a different path, you could add this line to your code:

TempFile = MyTempPath & My.Computer.FileSystem.GetFileInfo(TempFile).Name

This would extract the base temp file name. Also, if you do this, make sure you delete the zero length temp file in the temp folder as well.

Form on Top
This function on my VB6 Notebook Archive Site shows the API’s that you use to make a form topmost. Here’s how you would do it in VB.NET:

MyForm.TopMost = True

And that’s it. Just make sure that you use Me rather than the form name if you make this call from the form itself.

Current User Name

This function on my VB6 Notebook Archive Site shows the API’s that you use to get the name of the current user. Here’s how you would do it in VB.NET:

UserName = My.User.Name

And that’s all there is to it. Note that the returned value will be [domain_name]\[user_name] so if you only want the name itself you can use the following code:

UserName = My.User.Name.Substring(My.User.Name.LastIndexOf("\") + 1)

Share This Article: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Technorati
  • DotNetKicks
  • DZone

Entry Filed under: VB6 To VB.NET


Rate This Article:

Not That GoodCould Be BetterOKGoodGreat (2 votes, average: 4.5 out of 5)
Loading ... Loading ...

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Visit Me At My New Site, Programming In C#

Most Popular Articles

Highest Rated Articles

Categories

Most Recent Articles

Feeds

 Subscribe in a reader

To subscribe by e-mail
Enter your address here

Delivered by FeedBurner

VB Opportunities

Archives