Public properties from another class in vb.net - 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

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

Finding the definition of an object in a VB web-user-control

I have an ascx.vb file with a function that starts off like this:
Sub buildlist()
repcaldatelist.Visible = True
...
End Sub
I'm just trying to figure out what repcaldatelist is. When I use VS's "Go To Definition", it gives me a popup saying "The definition of the object is hidden." Using "Go To Implementation" does nothing.
I see the corresponding .ascx file with this line:
<asp:repeater ID="repcaldatelist" runat="server">
and I see how repcaldatelist is databound to it, so that page can display its data.
But what I'm trying to understand is, where does repcaldatelist come from? I want to see where it's initialized and what its type is.
I know this is probably really basic but I'm new to VB / Web User Controls and haven't had any luck searching for this online thus far. Please enlighten me.
ID="repcaldatelist" means that's the ID of the Repeater control. So in your .vb file, repcaldatelist is an object of type Repeater - the ID in the ascx/html translates into a variable name in the VB. If you hover over the variable in the .vb file in Visual Studio it should tell you the type as well.
Go To Definition / Implementation don't work because the Repeater class is part of the .NET framework, and it's closed-source - just a DLL on your machine. Therefore there's no source code or definition you can view. You just have access to its public API as defined by the docs (and should be available in intellisense as well).

Best practice for using main form controls

So lets say I have a form1 that opens on startup. Form1 contains a textbox named textbox1 and a button named button1. When I click button1 this is code that is called:
Class form1
Sub CapLetters () 'buttons click event
Dim myObj as new MyObject
MyObj.CapAllLetters
Textbox1.text = MyObj.GetThoseCapLetters
End sub
End class
Now, I know this is kinda dumb, but my main question is, since im creating a new object, the textbox1 will not be available in my object unless I specifically call it like:
Form1.textbox1.text
Is this good practice or is there a better way? Now in my program I have about 10 textbox and comboboxs I need my object to use. I know i could do something like this:
MyObj.CapAllLetters (textbox1.text)
But that doesn't seem like a good idea to pass that many values in a method.
I think I need a way for my object to gather all the info upon initating it?
Thoughts?
You basically seem to be asking whether it's OK to use the default instance of a form. The answer is yes. In recent versions of VB, each form that has a parameterless constructor also has a default instance, which is a single instance that can be accessed anywhere and at any time via the class name. This feature exists because it makes it easier for beginners to access forms from different places in a project without having to worry about passing references to forms around that project.
In the case of the startup form in a project, it is always the default instance of its type, assuming that you haven't disabled the application framework. That means that you can always access your startup form anywhere in your project using the default instance of its type.
Now, you'll find that experienced developers rarely use default instances. That's because they are never required and rarely add value if you know what you're doing. That means that you can always access your application's startup form is reasonable locations throughout your project without using the default instance.

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

VB.NET UserControl

I am trying to create a UserControl in VB.net, under VS2010. I have the code for the UserControl and I would like to add it to a form. My problem is that, according to every book and forum I have seen, after I build the UserControl, it should show up in the Toolbox. It doesn't. I even downloaded code from a book, the code executes perfectly, but their TrafficLight control doesn't go in the Toolbox (even though the book says it should - and that the only way to set its properties and to add it to the form is through the Control properties). I have tried to add the control to the form manually, by declaring it
Dim myObj As New SomeClass.SomeControl
and in the Designer.vb, identical with the buttons on the form:
Friend WithEvents myObj As SomeClass.SomeControl
With both, I get an error saying
'myObj' is already declared as 'Friend WithEvents myObj As SomeControl' in this class.
And either way, I get an error when I try to look at the design:
Could not find type 'SomeClass.SomeControl'. Please make sure that the assembly that contains this type is referenced. If this type is part of your development project, make sure the project has been successfully built using settings for your current platform or AnyCPU.
The control by itself builds and shows up in design view (not in the Toolbox though, even though it Imports System.ComponentModel and Inherits System.Windows.Forms.UserControl and... what else ? I tried to build it in a separate project, to see if I creating a separate dll will make a difference, though I really want it in the same project.
Please help ! (BTW I have reinstalled VS2010 and it did no good)
Thank you.
Look in Tools / Options / Windows Forms Designer and set "AutoToolboxPopulate" to True (but note that this can take a noticeable amount of time if you haver many (i.e. dozens) of user controls.