1

I have a legacy VB5 desktop application which I'm upgrading to VB.Net in Visual Studio 2008. In bulit VBUW in 2008 did the upgrade partially. But still having thousands of errors which needs manual fix. Most of the error is related to a form access controls from another form. Error says "S_CRSMANU' is not a member of 'Form'. cs. Is there any tool that can do this upgrade or what is the manual fix needed.

enter image description here

I tried to create public property for the controls but still not getting rid of error.

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
Sri Abbai
  • 11
  • 2
  • 1
    `Error says "S_CRSMANU' is not a member of 'Form'. cs.`. The problem is you're using the GENERIC FORM class to reference a specific type of Form. The statement is true; there is no "S_CRSMANU" in the generic Form class. That thing exists in a specific kind of Form, like "Form1" or "frmMain", or whatever the name of that form actually is. If you change the DATA TYPE of that Form reference from `Form` to the correct, specific form type, then the error will go away (assuming that "thing" is publicly accessible, which they are by default in VB.Net). – Idle_Mind Feb 03 '23 at 15:43
  • 1
    The old-school Visual Basic environments allowed for this kind of loose, run-time accessing of elements. If "S_CRSMANU" exists on the object you are referencing, then it would just work. If it doesn't, then you'd get a run-time error. The newer VB.Net language is more restrictive, adhering to stronger Object Oriented Programming Principles. This is to try to get you to write safer and more well designed code. See [Early / Late Binding](https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/early-late-binding/)... – Idle_Mind Feb 03 '23 at 15:48
  • 4
    Last thing, then I'll stop with all the comments. Unless you have a REALLY GOOD REASON, 99% of the time it's simply better to re-write the VB5 program FROM SCRATCH as a new VB.Net program. Why? Because the "converted" program is going to use techniques and approaches that only exist for the sole purpose of converting an old program and "making it work" in a newer language/framework. If you were to write the same program from scratch using VB.Net, then the techniques and approaches would be COMPLETELY DIFFERENT. – Idle_Mind Feb 03 '23 at 15:52
  • I have the code 'If Not G_CHECK_MENU(g_form.S_CRSMANU, "", "N") Then' Could you please give me an example for this - "If you change the DATA TYPE of that Form reference from Form to the correct, specific form type, then the error will go away (assuming that "thing" is publicly accessible, " – Sri Abbai Feb 03 '23 at 15:56
  • What was `g_form` declared as? Was it `Dim g_form As Form`?...or did it possibly come back as a generic `Form` reference as the result of a call to some other code. To fix it, you'd have to change `Form` to the actual form type: `Dim g_form As frmSomething` – Idle_Mind Feb 03 '23 at 16:03
  • this if how the g_form is declared in the code 'Public g_form As System.Windows.Forms.Form' – Sri Abbai Feb 03 '23 at 16:06
  • Exactly. The generic `System.Windows.Forms.Form` class does NOT have a `S_CRSMANU` thing in it. You need to change `Form` to the specific type of Form that has `S_CRSMANU`. If the purpose of `g_Form` is to represent and reference different types of forms using the generic Form reference, then you'd need to approach the problem very differently. – Idle_Mind Feb 03 '23 at 16:18
  • correct, in my case g_form is referencing different forms across the application. it's used as a generic form – Sri Abbai Feb 03 '23 at 16:24
  • 2
    So now you need to make a MAJOR DECISION. You can "fix" this by turning [Option Strict Off](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-strict-statement) so that late-binding will work again as it did in VB5/VB6. Your other option is to use Object Oriented Programming principles and use an [Interfaces](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/interfaces) so that you can ask multiple, different forms to perform an action or access some kind of element that they have in "common". – Idle_Mind Feb 03 '23 at 16:56
  • To avoid `Option Strict Off` (but always a good idea to not use `Option Strict Off`), and if you don't want to create interfaces (probably a good idea to do it this way), you can avoid the compile error by defining `g_Form` as object: `Public g_Form As Object`, or casting the usage to object: `If Not G_CHECK_MENU(Ctype(g_Form, Object).S_CRSMANU, "", "N") Then`. But be aware that this may be just changing your compile error to a runtime error, if whatever g_Form is referencing doesn't have a member named `S_CRSMANU`. – MarkL Feb 03 '23 at 17:41
  • Turning Option Strict Off isn't working, I will have to try other option. Thanks for the suggestion – Sri Abbai Feb 03 '23 at 17:59
  • The Object comment @MarkL should work then! – Idle_Mind Feb 03 '23 at 18:03
  • Regarding whether to convert vs rewrite - I've had a lot of success with first converting VB6 code using VS2008, and then cleaning it up. I'm sure there are also cases where a rewrite could be more productive but that is far from obvious as a general conclusion. For one thing, if you first convert you have the benefit of working in the newer tools even if much refactoring is still needed. – StayOnTarget Feb 04 '23 at 14:26
  • 1
    You could use a paid tool like VB Migration Partner. Or do what we did, and use the tool you're using and fix the errors manually. BTW you'd be well advised to convert the code to VB6 first before converting it to VB.NET. – R.J. Dunnill Feb 07 '23 at 01:14

0 Answers0