Regarding vba classes coded in Visual Studio VB.net - vb.net

I'm trying to start coding my macros for Excel in Visual Studio, it needs changing some things but I think I'm ok as for normal modules go.
My question is, how do I code classes there?
When I try to code a new class it forces me an argument called Of:
Public Class FNMT(Of)
Public Sub TratarDatos(arr As Object, Dict As Object)
End Sub
End Class
And says it's expecting an identifier. How would classes work in Visual Studio? I couldn't use properties neither, it was saying that I can't use the Let/Get.
Can't find anything about this either here nor in google. Any insights?
This is how I'm writting the code:

Related

put the code in a different file and then "include" it?

In my vb.net project, there are tons of buttons and various items. I would like to keep this code in the form1.vb file. One specific button tough, executes a very long piece of code. What I would like to do is put this code in a different file and then "include" it inside the button. I was thinking of a class, but it looses the connection to all the global variables and the stuff needed for that code. I do not really NEED to put this in a different file, its just something that sits there, that i will not look at again and being so long its in the way. Is there a way to put this in a different file and then include it sort of like it is done in php? I am on visual studio 2015 community edition
Use a partial class such as this:
Partial Public Class Form1
Private Sub doStuff()
Windows.Forms.MessageBox.Show("This is where your long code should go")
End Sub
End Class
Partial classes add more functionality to your class but they can be contained in a seperate file.
http://visualbasic.about.com/od/usingvbnet/a/partclses.htm

stimulsoft report add my function with vb.net

we can add our function with this way
https://www.youtube.com/watch?v=TEYuQmia9IY
but it in c#
i want the way in vb.net
the problem in using namspacing in vb.net
thanks
In the video posted there are some critical steps missing. It seems that they are given for granted but without it you could not achieve a successful reference to your code from the Report Designer.
First: To clarify the problem between VB.NET and C#. If you want to use VB as scripting language for your report you need to set it in the Report Properties. You will find the ScriptLanguage property in the same property grid for the report where they set the reference to your application. Changing this property is not required because this property refers to the code written inside the report not the code in which you have written your app.
Second: In your VB.NET app your code that defines the function should be as this
Namespace MyFunc
Public Class Main
Public Shared Sub ShowMessage(text As String)
MessageBox.Show(text)
End Sub
End Class
End Namespace
Usually in VB.NET you don't define explicitily a namespace (everything is inside the main namespace defined in the project properties) but if you want a separate namespace there is nothing to stop you.
Third: In the Report Code Page you write
Imports WindowsFormApplication2.MyFunc
Fourth: After completing the design of your report remember to save it in the same folder where the application is created. (Usually Project\BIN\DEBUG) Otherwise the reference to your executable will fail.
Fifth: The Stimulsoft assemblies are installed in the GAC, but to be sure that they are found when you run the report don't forget to set their references to Copy Local = True when you run your app inside Visual Studio

Use Form(Of T) on VS Designer

I'm using vb.net (vs2010). I'm moving some winforms to a dll. I have a form that inherits from the one which has some subs and functions (like a test app).
My original form is: (.designer)
Partial Class Form1(Of T)
Inherits System.Windows.Forms.Form
....
End Class
Form itself contains code and a toolbar.
My test form is: (.designer)
Partial Class TestForm
Inherits Form1(Of Class1)
I get "Cannot create an instance of Form1`1[T] because Type.ContainsGenericParameters is true" when VS try to load the designer. App is usable. I can build and run the project without errors, but I need to add controls and some code to each new form.
I tried many ways:
Visual Studio 2008 Winform designer fails to load Form which inherits from generic class
How can I get Visual Studio 2008 Windows Forms designer to render a Form that implements an abstract base class?
http://www.codeproject.com/Questions/419770/Csharp-reflection-GetValue-from-a-field-in-generic
http://madprops.org/blog/Designing-Generic-Forms/
All examples are for C#, and I don't know if I'm missing something...
Is this a bad design ? I know this is a VS bug but still it seems everyone fixed it by these links.
EDIT:
I'm building a DLL. Form1 is on this DLL and TestForm is in a new project. Those links works if I'm in the same project (a.k.a. the dll).
Thanks!
Is this a bad design ? I know this is a VS bug
Bad design, not a VS bug. What you are trying to do is fundamentally incompatible with the way the Winforms designer works. It has strong WYSIWYG support, the designer creates an instance of the form's base class and allows code in that base class to run at design time. Which is why, for example, you can set the BackgroundImage property and it is immediately visible in the designer. The Form.OnPaintBackground() method paints it. The designer is not involved at all, it just sets the property.
To make that work, it must be able to create the base class object. It can't in your code, it doesn't know what kind of T to use. Not an issue when you design Form1, the T isn't needed yet since it derives from Form and creating an instance of Form is not a problem. Big issue when you design TestForm.
You'd probably argue that it should use Class1 as the T. It doesn't, the odds that it can use Reflection to discover the generic type argument from TestForm are exceedingly low. That requires the type to be compiled first. That's a chicken-and-egg problem at design time, the TestForm class gets compiled after you design it, not before or while you design.
It's not like you completely cannot use your approach. It builds and runs just fine. You just have to live without design time support for TestForm. That's usually a deal breaker, you have to re-consider your design.

Public properties from another class in vb.net

I've tried searching... a lot for the answer, but as I'm not too sure what exactly I'm trying to do I can't seem to find anything.
I'm trying to write a dll in order to handle errors thrown from a vb.net app. In the dll I need several forms (I'm not totally sure if they can have forms - I'm a bit of a newbie when it comes to dll's) for which the user can type in their message about the error and submit it.
I need to be able to pass strings to the form and for the form to be able to access public subs in the class file.
For instance I have a public sub called Emailer, which I want, when the submit button is clicked from the form to be run.
Or, lets say I have a public string:
Public strName as string = nothing
why cant I, from the class file just do this:
frmFormName.strName = "abc"
Not sure if I've explained that very well, but like I said I'm a bit of a newbie with this stuff.
1) You can have froms in a DLL it just does not have a entry point you will need a exe for this this. Which it sounds like you have
2) You will need to add a project reference to a dll from your exe
ok not sure how this will work but try to download this Example project let me know if you have more questions

MyProject.MyClass - vb.NET custom controls

In a Visual Basic project, I created a homemade TabControl in order to fix a visual bug. The control works properly, however whenever I modify the form using my tab, Visual Studio adds MyProject in front of the control in its declaration:
Me.tabMenu = New MyProject.MyClass 'Gives a BC30002 compile error
If I remove the MyProject., the project compiles properly.
MyClass is in a separate file MyClass.vb and looks mostly like this:
Public Class MyClass
Inherits System.Windows.Forms.TabControl
Public Sub New()
InitializeComponent()
MyBase.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
//OnDrawItem code
End Sub
Private Sub My_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles Me.DrawItem
//My_DrawItem code
End Sub
End Class
I tried removing the file and adding it again, copy and pasting the class inside MyForm.designer.vb, adding MyProject. to the class name, but nothing stopped Visual Studio from adding this so-hated MyProject.
Edit regarding this answer:
I understand the thing about the namespace, however my problem is mostly that the compiler does not recognize the class with the project name appended but still adds it everytime.
What is the actual compile error you are getting? Is it possable that the VB compiler is interpreting MyProject as something other than a namespace identifier? You could also try changing the default namespace for the project, then see what it does, it might give you a hint as to what the actual problem is.
You could also try changing the offending line to
Me.tabMenu = New Global.MyProject.MyClass
then let us know what the results are.
I've seen this before when you have a public module with the same name as your default namespace (project name). If that's the case, either rename the module or the default namespace and the problem should go away,.
By default, Visual Basic .NET assigned a default namespace to your project. (I believe the default is, in fact, MyProject.)
This is what's being prepended, and it's being done to explicitly identify your class in the designer.
No matter what your default namespace is for your project, the WinForms designer will add the namespace name to the .designer.vb file.
To change the default namespace, go to your project properties; it should appear on the first tab.
Also, generally, don't modify the .designer.vb files if you can avoid it. Those files get completely blown away and rebuilt by Visual Studio often, so your changes will more likely than not be eliminated.