-
Please Help Create A VB6 to .NET Function Conversion Chart [Completed]
Visual Basic 6 to .NET Function Equivalents (Updated 3/19/2006)
EDIT: Moved the page to my wiki. Now anyone can edit it as they see fit.
While learning .NET, I realized that the main obstacle was finding out what the .NET equivalent was to every VB 6 function. I have created this chart to help people in my situation. Follow the link above to see the chart. Email me at the link provided there, or post here to give feedback or to tell me about errors.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
There are only a few left compared to original list. I would be very thankful for any and all help.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
I know the rest but i'm going to bed now, 2am lol. During the day tomorrow I will complete it and post it.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Quote:
Originally Posted by eyeRmonkey
There are only a few left compared to original list. I would be very thankful for any and all help.
Which are left?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Quote:
Originally Posted by Vektor
I know the rest but i'm going to bed now, 2am lol. During the day tomorrow I will complete it and post it.
Thanks. I would really appriciate that.
Wild Bill, the list in the main post is all that is left. The original list was a lot longer though. I made that comment because I thought the reason no one was replying was because they saw how long the original list was.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Shell - Process.Start
MsgBox - MessageBox.Show
Randomize - Random Class
SavePicture - Image.Save BitMap.Save, etc
Of course, I dont really have much VB6 knowledge, just thought I would throw those in since I had nothing better to do...
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
I actually had Shell and MsgBox already and forgot to remove them.
Randomize doesn't exist in the Random class as far as I can tell. Is it even necessary? Or can you just call [System.Random Obejct].Next without the Randomize .NET equivelant (if it exists)?
Thanks for SavePicture.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Randomize shouldnt be necessary at all if you use the random class, and Random.Next...
Refer to this thread when I got in trouble for suggesting it :p
http://www.vbforums.com/showthread.php?t=363148
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Cool. I will list it as depricated.
I was trying to figure out how to find a simple of to accomplish StrReverse in .NET and the best thing that I can come up with is way to long and looks like this:
VB Code:
Dim MyString As String = "test"
Dim MyArray As System.Array
MyArray = MyString.ToCharArray
Array.Reverse(MyArray)
MyString = Convert.ToString(MyArray)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
You can simply loop the chars of the string, and just append it to the front of the result string, like below:
VB Code:
Dim MyString As String = "ReverseMe"
Dim ReverseString As String = ""
For Each Letter As Char In MyString
ReverseString = Letter & ReverseString
Next
MessageBox.Show(ReverseString)
Its the same code length (since you didnt put a messagebox displaying the variable above), but doesn't require converting them to an array, or temp array, etc...
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
I was trying to put this all in a spreadsheet and I don't want to put 5 lines of code. I suppose I could just put "use a loop" or something.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
hehe well Im not sure if there is a shorter way without using the runtime function, you can always do this if needed:
VB Code:
For Each Letter As Char In MyString : ReverseString = Letter & ReverseString : Next
That enables you to put everything in one line in the IDE (seperating them with a colon), and gives you one line to put in your spreadsheet....
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
How about these: ChDir, ChDrive, CurDir. Directories don't even work that way in .NET do they? In VB6 your kind of had a directory that it was "focused" on and whenever you did any directory actions, it would automatically happen to that directory. In .NET you need have the whole directory class. Any idea how to convert those?
Oh, I just found these one:
CurDir = [IO.Directory Object].GetCurrentDirectory
ChDir = [IO.Directory Object].SetCurrentDirectory
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Heres DIR Folders
VB Code:
For Each Dir As String In IO.Directory.GetDirectories("C:\")
Debug.Print(Dir)
Next
Heres DIR Files
VB Code:
For Each Dir As String In IO.Directory.GetFiles("C:\")
Debug.Print(Dir)
Next
File Exists
VB Code:
If IO.File.Exists("C:\a.bat") = True Then
Debug.Print("True")
End If
Len = String.Length
Easy Read/Write
VB Code:
My.Computer.FileSystem.ReadAllText("C:\a.txt")
My.Computer.FileSystem.WriteAllText("C:\a.txt", "Today", False)
About all I got that could interest you
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Thanks Remix!
How about Len when used with data types? It tells you the number of bytes that object/type takes up.
My keyword is only in .NET 2005. I would like to keep this more universal. I like the ability to read/write a file in one line though! Is there anyway to do it in one line in other versions of .NET.
Anyone have any idea how to do Hex or Oct (or Binary even though it didn't exist in VB6) using .NET? I get the feeling they might not exist anymore.
Also, what is the difference between Fix and Int in VB6? And what is the best way to do that in .NET? All I could come up with is Convert.ToInt32 or Math.Round.
Does InputBox exist anymore?
PS - It is Debug.Write or Debug.WriteLine. Debug.Print was so two years ago! :wave:
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Windows.Forms.Application.DoEvents() 'DoEvents
Convert.ToChar(26) 'EOF
Int32.ToString("x") 'Hex
String.Join("", s()) 'Join
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Thanks Wild Bill. The only one that doesn't work is EOF. In VB6 EOF returned a boolean value telling you if a specified file had reach the end of the file or not. I know VB .NETs setup for files is totally different, but can we find something similar?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
I think I will just list EOF as "[StreamReader Object].Peek = -1"
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Try,
VB Code:
Debug.Print(Int16.MaxValue.ToString)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
something like this might work
VB Code:
Const EOF As String = Nothing
Dim sr As New IO.StreamReader("c:\temp\test.txt")
Dim line As String = sr.ReadLine
While line <> EOF
line = sr.ReadLine
End While
sr.Close()
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Quote:
Originally Posted by |2eM!x
Try,
VB Code:
Debug.Print(Int16.MaxValue.ToString)
Len told you how many bytes something was. Plus its main use was for Objects that you created yourself. For example, if you made your own class and had an instance of it, you could figure out how many bytes the structure took up. Should I list it as depricated?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
No idea..Never used/needed it, sorry.
edit* cant you get the number I gave you, /2 and get the bytes?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
You can, but that only applies to objects/data types that have a MaxValue property.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
The equivelent of Len is Marshal.SizeOf() I believe. Atleast in some cases. That is what I have replaced Len with when woking with APIs.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Yeah, I totally told you so.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Environ is now Environment
Reflection replaces CallByName According to this
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
I don't really know how CallByName worked in VB6, but can you point mew towards to a specific part of the Reflection class?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Here's an example
VB Code:
Dim t As Type = GetType (TestClass)
' BindingFlags has three bitor'ed elements. Default indicates that
' default binding rules should be applied.
t.InvokeMember ("SayHello", _
BindingFlags.Default BitOr BindingFlags.InvokeMethod _
BitOr BindingFlags.Static, nothing, _
nothing, new object () {})
This calls a method named SayHello.
You have to import system.Reflection then Call InvokeMethod on a type.
I got the example from here.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
So would It be fair to list CallByName like this?
[Type Object].InvokeMember
I plan to link each line of the chart to a good example or page on MSDN so I think that will be enough info. Do you agree?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
I think that might be the only way to show it nicely, and complete.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
(I just edited it. Do you still agree that is the best way to post it? As long as I link it to and example.)
That only leaves Oct. I did Hex like this: [Integer Object].ToString("x") but I don't know how to do that with Oct.
Also I need to find a good way of listing all the depricated functions. I want to put a comment next to every depricated function that at least gives some info about it or points the user in a good direction if that is what they are looking for.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Current way is better. Maybe have an astrics with a note at the bottom that says may require importing a namespace. Check MSDN for requirements? Something tlike that? Because another one that requires an imports statement is marshal.SizeOf.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart
Oddly, neither of those require a reference for me. The following work without references:
VB Code:
Runtime.InteropServices.Marshal.SizeOf
' AND ...
Dim t as Type = GetType(MyType)
t.InvokeMember
Well they don't WORK, but they pop up form Intellisense. I havn't actually tried either of them though. I only have the default imports set up.
Everything will be linked to MSDN so that should suffice for this one.
Does anyone have any ideas for Oct or for the ones I have listed as depricated? Like I said, I want to put a note next to each depricated one that gives the user an idea of where to head. For example, next to Err I put "(Depricated - Use Try ... Catch ... Finally statement and Exception object instead)." I need help finding things like that for all the depricated functions.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
Here is a rough draft. Almost everything is linked to MSDN. I would really appriciate it if everyone could skim over it and make sure everything is valid.
EDIT: I moved the link to the first post.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
What Depricated means? :confused:
About StrReverse, why to loop in .Net if it still works as in VB6?
Or you don't want nothing from Microsoft.VisualBasic?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
Deprecated ;)
SendKeys = Application.SendKeys
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
Quote:
Originally Posted by jcis
What Depricated means? :confused:
About StrReverse, why to loop in .Net if it still works as in VB6?
Or you don't want nothing from Microsoft.VisualBasic?
Deprecated (as Penagate pointed out) means out of date and obselete.
As far as StrReverse, the whole point of this table is to help people avoid using the Microsoft.VisualBasic namespace. The idea is to help people get out of their old "VB 6 habbits" and into a more object oreiented approach.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
There's nothing wrong with the Microsoft.VisualBasic namespace.
:p
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
Technically that is true, but you have to agree that an OO approach is better than being stuck to your old VB6 habbits.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
Okay, the most recent version is linked in the first post. If no one else has any comments I will polish it up and give you guys the final link. Hopefully a few people will be willing to link to it in their signatures and we can help people stop using the Microsoft.VisualBasic namespace.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
Oct?
Convert.ToString(New Integer, 8)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
Quote:
Originally Posted by eyeRmonkey
Technically that is true, but you have to agree that an OO approach is better than being stuck to your old VB6 habbits.
I don't like using Runtime functions if there is a better alternative but this is not a valid argument. VB.NET is a 100% OO language. It is not possible to do anything in VB.NET that is not OO. Using a Runtime function is no different to using a Shared member of a class.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
There is no possible replacement for IIf in VB.NET except a full If...Then...Else...End If block.
I don't know how SendKeys works in VB6 but I'd assume that the SendKeys class provides the equivalent functionality and probably more.
Quote:
Originally Posted by penagate
SendKeys = Application.SendKeys
I think you just made that up. :)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
Yes, it looks very much as though I did. :blush:
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Almost Done]
Quote:
Originally Posted by jmcilhinney
I don't like using Runtime functions if there is a better alternative but this is not a valid argument. VB.NET is a 100% OO language. It is not possible to do anything in VB.NET that is not OO. Using a Runtime function is no different to using a Shared member of a class.
I knew someone would dispute me on that one. I don't know how to phrase it so it is "technically correct," but I think you know what I mean. Why use VB6 functions (even though they are now part of the .NET framework) when there is a .NET approach.
Yeah, I figured out what you meant Penagate. ;) SendKeys.Send() functions does the job. :)
Thanks everyone. I will be posting a new version in a few minutes.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
I absolutely hate using SendKeys in either VB6 or VB.NET. It should have never been invented. The most flakey of all methods of all time! :D
Use unmanaged code (APIs) to do it reliably. :thumb:
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available
Quote:
Originally Posted by RobDog888
I absolutely hate using SendKeys in either VB6 or VB.NET. It should have never been invented. The most flakey of all methods of all time! :D
Use unmanaged code (APIs) to do it reliably. :thumb:
I'm with you Rob. Given that SendKeys acts on the control that currently has focus and that there is no way to guarantee what the active control is at any time, the result of SendKeys cannot be predicted with an acceptable level of certainty.
I don't use Runtime functions if I can avoid it for the following reasons:
1. They are often (although not always) less efficient than System-based alternatives.
2. They often call the very members that you would normally use to replace them (e.g. MsgBox and MessageBox.Show) so why add the extra layer? This is also a contributor to reason 1.
3. Their behaviour is sometimes what I would consider idiosyncratic, e.g. Val().
4. They are often abominably named. Who would know what Fix() does without looking it up? The naming conventions in the .NET Framework make a lot of code self-documenting.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
Sorry EM, but this guy has done what your doing but for VB6 > VB.NET & C#. Good stuff too. :)
http://www.codeproject.com/dotnet/vb...difference.asp
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
Quote:
Originally Posted by RobDog888
I don't see the VB6 part :)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available]
:blush: neither do I :lol:
Nevermind, but it is a helpful link for VB to C# :D
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Rouch Draft Available
Quote:
Originally Posted by RobDog888
:blush: neither do I :lol:
Nevermind, but it is a helpful link for VB to C# :D
Thanks for the helpful vb to c# link then RD :wave: :p
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
Good link anyway RD. Thanks.
Okay, the updated (and hopefully near final) version is posted. Enjoy. :)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
I read your final list and I want to point out that CStr, CInt, etc. are NOT members of the Microsoft.Visualbasic namespace. Notice that they turn blue in the IDE, indicating that they are VB.NET keywords. They are part of the VB.NET language itself, so I for one certainly do not equate their use with the use of Runtime functions.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
Hmmm. I didn't know that. So what are they then? Okay, I know I started a thread on this subject already and I know it goes back to casting and what not. Is that the reason they exist in two similar forms? One for casting and one for doing it the other way?
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
CInt, CStr, etc. existed in VB6 and earlier and behaved a certain way. I believe they still behave that same way, but they are VB.NET keywords and are compiled inline rather than creating a function call. Their functionality includes some of what C-style casting provides, which didn't exist in VB6, and some of what the Convert class and similar things provide, although they do not necessarily work the same way. This is the reason I like to use them for casting and Convert or the like for actually converting objects. That is a matter of personal preference but I believe that it helps to keep things more consistent, particularly if you also use C# where you will use a genuine cast where appropriate and a conversion otherwise.
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
Well, I still don't understand the whole concept of casting, but that isn't the topic of this thread, so I will remove them from the list because they are all fairly obvious and because you have a point. Thanks. :)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
If you guys wouldn't mind, I think it would be helpful to link to either this thread or the table in your signatures. I think it will solve a lot of simple problems that people run into when switching from VB6 to .NET. Thanks. :)
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
I've noticed some erros in the section including FormatDateTime and the like. If you want to use the String.Format method then you do NOT call it on a String object because it is a Shared method. The old Format function is replaced by String.Format where you call it on the class, not an instance. As for the others, you could use String.Format but it would be more correct to do as follows:
FormatCurrency => myNumber.ToString("c")
FormatDateTime => myDate.ToLongDateString, .ToShortDateString, .ToLongTimeString, .ToShortDateString, .ToString(formatString)
FormatNumber => myNumber.ToString(formatString)
FormatPercent => myNumber.ToString("p")
Take a look at these links to see what sort of values formatString can take.
Standard DateTime Formats
Standard Number Formats
Custom Number Formats
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
Quote:
Originally Posted by eyeRmonkey
If you guys wouldn't mind, I think it would be helpful to link to either this thread or the table in your signatures. I think it will solve a lot of simple problems that people run into when switching from VB6 to .NET. Thanks. :)
I must insist that you fix the appalling Word-generated HTML code! :eek:
-
Re: Please Help Create A VB6 to .NET Function Conversion Chart [Final Draft]
Quote:
Originally Posted by penagate
I must insist that you fix the appalling Word-generated HTML code! :eek:
Shhhhhhhhh!
I was feeling lazy. I moved it to appalling FrontPage-generated HTML code. ;)
JMC, could you explain how/when/why I would call format on a class? I'm not sure I follow you on that one.
EDIT: I updated the page. Does it look more correct JMC?