Visual Basic 6 to .NET Function Equivalents
From Auzigog Wiki
The information provided here is intended to help Visual Basic 6 developers who are making the switch to Visual Basic .NET and who wish to learn how to accomplish tasks without the use of the Microsoft.VisualBasic namespace (which contains all of the legacy Visual Basic 6 functions). This chart sprang from a thread at VBForums.com.
Contents |
[edit] Introduction
Do not be mistaken; by using functions in the Microsoft.VisualBasic namespace, you are not using "old code," because all of those functions map to their new equivalents within the .NET framework. The main benefit of avoiding these functions is so you can familiarize yourself with the namespaces contained in the .NET framework.
If you would like to remove the Microsoft.VisualBasic namespace, you can do one of two things. First you can manually remove the import every time you start a new project. The other option is to create a project template that does not include the Microsoft.VisualBasic namespace.
To create a template, take look at these links:
Please feel free to edit this page and add anything you see fit.
[edit] Notes
- Some functions listed here may not be exact equivalents, but are the closest that are available.
- You are encouraged to use the Object Browser (F2) to explore the .NET namespaces yourself.
- Click on any of the .NET equivalent functions to visit MSDN and find out more information about that function.
[edit] Miscellaneous
| Visual Basic 6 | .NET Equivalent |
|---|---|
| App.Path | Application.StartupPath |
| CallByName | Type Object.InvokeMember |
| Circle | Graphics Object.DrawEllipse |
| Collection | Collections.Hashtable, Collections.Dictionary |
| Command | Environment.GetCommandLineArgs |
| DoEvents | Application.DoEvents |
| Environ | Environment.GetEnvironmentVariable |
| Err | Deprecated - Use Exception object and Try ... Catch ... End Try statement |
| Error | Exception Object.Message |
| GetSetting | Deprecated - Look into Configuration.ConfigurationSettings |
| IIf | Deprecated |
| InputBox | Deprecated - Make your own form |
| Len | Runtime.InteropServices.Marshal.SizeOf |
| MsgBox | MessageBox.Show |
| RGB | Color Object.FromArgb |
| SavePicture | Image Object.Save |
| SaveSetting | Deprecated - Look into Configuration.ConfigurationSettings |
| SendKeys | SendKeys.Send |
| Shell | Process.Start |
| Switch | Deprecated |
| TypeName | Any Object.GetType.ToString |
| Unload | Deprecated |
| VarType | Any Object.GetType |
[edit] Strings
[edit] Files & Directories
| Visual Basic 6 | .NET Equivalent |
|---|---|
| ChDir | IO.Directory.SetCurrentDirectory |
| CurDir | IO.Directory.GetCurrentDirectory |
| Dir | IO.Directory.GetFiles, IO.Directory.GetDirectories, IO.Directory.Exists, IO.File.Exists |
| EOF | IO.StreamReader.Peek = -1 |
| FileAttr | Deprecated - Use StreamReader or StreamWriter |
| FileCopy | IO.File.Copy |
| FileDateTime | IO.File.GetLastAccessTime, IO.File.GetCreationTime |
| FileLen | IO.FileStream Object.Length |
| GetAttr | IO.File.GetAttributes |
| Loc | IO.Stream Object.Position |
| LOF | IO.Stream Object.Length |
| MkDir | IO.Directory.CreateDirectory |
| RmDir | IO.Directory.Delete |
| SetAttr | IO.File.SetAttributes |
[edit] Arrays
| Visual Basic 6 | .NET Equivalent |
|---|---|
| Filter | Array.BinarySearch |
| UBound | Any Type of Array.GetUpperBound(0) |
[edit] Date & Time
| Visual Basic 6 | .NET Equivalent |
|---|---|
| DateAdd | Date Object.Add |
| DateDiff | Date Object.Subtract |
| Now | DateTime.Now |
[edit] Math
| Visual Basic 6 | .NET Equivalent |
|---|---|
| Abs | Math.Abs |
| Atn | Math.Atan |
| Cos | Math.Cos |
| Exp | Math.Exp |
| Fix | Math.Floor (for negative numbers), Math.Ceiling (for positive numbers) |
| Int | Math.Floor |
| Log | Math.Log |
| Randomize | Deprecated - The Random Object is automatically randomized when it is declared |
| Rnd | System.Random Object.Next |
| Round | Math.Round |
| Sgn | Math.Sign |
| Sin | Math.Sin |
| Sqr | Math.Sqrt |
| Tan | Math.Tan |
