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.
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)
Entry Filed under: VB6 To VB.NET
Rate This Article:









(1 votes, average: 4 out of 5)
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed