Home » VB.Net

VB.Net equivalent of VB6 code which are obsolete.

Hi friends,
I am migrating VB6 project to VB.Net. I am stuck with these warnings for which I am unable to find solutions. I would be grateful if I get solutions to atleast some of the below warnings.
Need VB.Net equivalent for the below code as they are obsolete and have the same warning sign(***):
"Warning: 'Microsoft.VisualBasic.Compatibility.VB6.***' is obsolete: 'Microsoft.VisualBasic.Compatibility.* classes are obsolete."

-> VB6.ToPixelsUserX
Eg. pctSupport.Left = VB6.ToPixelsUserX(732, 0, 5451.19, 387)

-> VB6.ToPixelsUserY
Eg. pctSupport.Top = VB6.ToPixelsUserY(869, 0, 3209.51, 310)

-> VB6.ToPixelsUserHeight
Eg. pctSupport.Height = VB6.ToPixelsUserHeight(2205, 3209.51, 310)

-> VB6.ToPixelsUserWidth
Eg. pctSupport.Width = VB6.ToPixelsUserWidth(4465, 5451.19, 387)

-> VB6.GetItemData
Eg. HookupPipeRecord = VB6.GetItemData(lstPipe, lstPipe.SelectedIndex)

-> VB6.MouseButtonConstants
Eg. Button = VB6.MouseButtonConstants.RightButton

-> VB6.ListBoxItem
Eg. lstcategory.Items.Add(New VB6.ListBoxItem(Trim(category.Name), categoryRecord(N)))

-> VB6.DriveListBox
Eg. Public WithEvents Drive1 As New Microsoft.VisualBasic.Compatibility.VB6.DriveListBox

-> VB6.DirListBox
Eg. Public WithEvents Dir1 As New Microsoft.VisualBasic.Compatibility.VB6.DirListBox

-> VB6.FileListBox
Eg. Public WithEvents File1 As Microsoft.VisualBasic.Compatibility.VB6.FileListBox

-> BaseControlArray
Eg. <ProvideProperty("Index", GetType(LineShape))> Friend Class LineShapeArray
Inherits BaseControlArray
Implements IExtenderProvider

-> Error: 'PrintForm1' is not a member of 'System.Windows.Forms.Form'.
.PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)

-> Error: 'Me' is not valid within a Module.
"where 'Module GenSubs' is a class & not form."
Eg. Dim g As Graphics = Me.CreateGraphics()

Simran Kaur.

6 Answers Found


Answer 1

In .NET Framework version 4.0 there are no equivalents so the code  needs to be rewritten and controls need to be changed. For example, there is no DriveListBox, DirListBox or FileListBox controls so you would have to use OpenFileDialog/FolderBrowserDialog controls instead.


You can find  info about size and location properties below:


Below is info about the ListBox and ItemData:


I don't know how the right mouse button is being used in your application so context would be required.

The Visual Basic Power Packs forum can be found at the below link:


Also, for now you can target a previous version of the .NET Framework, probably 3.5, in order to support Microsoft.VisualBasic.Compatibility:



Answer 2

Hello Paul,
Thank You for your reply.
I am going through the links that you have sent and replacing the obsolete code  one by one.
I replaced VB6.MouseButtonConstants.RightButton with MouseButtons.Right .
I am trying to find  something to replace VB6.BaseControlArray in the below code which is obsolete  in VS 2010 Framework 4.
<ProvideProperty("Index", GetType(LineShape))> Friend Class LineShapeArray Inherits BaseControlArray Implements IExtenderProvider
I have posted the question in many forums but have not got any reply for it.
Also, I am trying to find solutions  for the below errors.
-> Error: 'PrintForm1' is not a member of 'System.Windows.Forms.Form'.
Eg:   PrintForm1.Print(frm, PowerPacks.Printing.PrintForm.PrintOption.CompatibleModeClientAreaOnly)
-> Error: 'Me' is not valid within a Module.
"where the below code is in 'Module GenSubs' which is a class & not a form."
Eg:  Dim g As Graphics = Me.CreateGraphics()
With what can I replace the "Me".
Hope someone can help me with these errors.
Simran Kaur.


Answer 3

I don't know how you are using control arrays in your code, but the below article describes how to implement them in .NET:


I've not used the PowerPacks and I would recommend posting your question to that forum:



Answer 4

Hello Paul,
Thank You for taking time & replying. You have been very helpful to me. I will go through the links & find  some solutions.
I will post the Powerpack question in that forum.
Simran Kaur.


Answer 5

I agree that most of the code  containing these methods will have to be massively rewritten.

However, I had a problem in that the sheer number of occurrences of these went over a thousand and made it difficult for me to work on the code.  I therefore wrote a class that had methods with the same name and then did a quick replace of VB6 with the name of my class containing the stubs.  I was able to go through pretty quickly with the Next button on Quick Replace. I wanted to quickly check each occurrence to make sure that I wasn't changing things that I shouldn't.



PrintForm1 is not a member of System.Windows.Forms.Form

The variable from which you are apparently referencing the property PrintForm1 (e.g. MyForm.PrintForm1) is probably defined as System.Windows.Forms.Form and you are setting the value of MyForm to the form that you are processing.  (Dim MyForm As System.Windows.Forms.Form)  You have to use the actual class of the form in the Dim statement to make the properties of the form visible or else cast it to the same class as the actual form using the CType statement.  I assume that PrintForm1 is some element of the form.



Dim g As Graphics = Me.CreateGraphics()

In the code setting up a form the variable Me is set to the id for the form itself.  If you are calling this from a module (code that is not part of a form), you have to replace Me with the id of the form.  One trick is to put the following line in the code for the form

Public Shared RemoteCall As System.Windows.Forms.Form

and then place a line in the handler for the load event that reads

RemoteCall = Me

You can then get the id of the form by knowing the class name of the form.


Answer 6

Hello Ross,
I posted the question about PrintForm1 again today as I had not seen ur post. I will try ur suggestions & post back the result. Thanks for ur suggestions.
Simran Kaur.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure