Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I made a little form I would like to use in other projects. Would that be Inheritance?

It seems to be necessary to have it in DLL to do that

VB.net standard IDE seems to only do it in EXE

There doesn't seem to be a dll option

 

If I try to do it in the command line with vbc it won't do it ... complains about design mode.

 

how do you compile it as a dll?

Does it need to be in a DLL to use it in other projects?

thanks

Edited by realolman
Posted
I made a little form I would like to use in other projects. Would that be Inheritance?

It seems to be necessary to have it in DLL to do that

VB.net standard IDE seems to only do it in EXE

There doesn't seem to be a dll option

 

Just set your project to a "Library" in the project properties.

 

If I try to do it in the command line with vbc it won't do it ... complains about design mode.

 

with vbc just use /TARGET:Library

 

how do you compile it as a dll?

Does it need to be in a DLL to use it in other projects?

 

Yes, you can reference only dll.

Try this, maybe it works :) : compile it as an exe and then rename the file as .dll (dll and exe have the same structure).

Or just compile it via vbc

> NeoDataType.net <

Try my Free .Net Reporting Tool!

Posted

Thanks but I don't understand.

 

Ther doesn't seem to be any options to set project as a library.This is VB.net standard 2003

 

 

If I try to use vbc in command window it gives me

 

"The expression cannot be evaluated while in design mode."

 

Do I have to go to MSDOS command prompt and then type in a path for vbc and another path for the file I want to compile?

Posted
Try this' date=' maybe it works :) : compile it as an exe and then rename the file as .dll (dll and exe have the same structure).[/quote'] I heard someone try this and it worked. I was fairly shocked... but at the same time it sort of made sense.

 

Realolman, It's probably more comfortable, though, I think, to change the un-compiled project solution to be a "Class Library" -- but VS Standard Ed. does not have this option, as you found out. :(

 

Fortunately it's very easy to change a Project from "WinExe" to "Library" using a Notepad, or Derek Stone's templates. You can follow the directions here: http://www.xtremedotnettalk.com/showthread.php?t=90321.

 

:),

Mike

Posting Guidelines

 

Avatar by Lebb

Posted (edited)

I made the changes with notepad .. now it won't open the original project

 

Says it expects "build" but finds "settings"

 

And it still doesn't work to try to use the form in another project.

Edited by realolman
Posted

You tried it manually using a Notepad.exe or Derek's templates? Assuming you used the Notepad, I don't know... I've done this before and it has worked fine.

 

Is this for VB.Net or C#? Let me know which one and I can attach a sample, blank DLL project here that you can use. :)

Posting Guidelines

 

Avatar by Lebb

Posted

No problem...

 

All you need to do is click on the 'vbBlankClassLibrary.sln' file. That will get you going. :)

 

(You could also double click on the 'vbBlankClassLibrary.vbproj' file within the vbBlankClassLibrary folder.)

 

After that, add your code, and then hit 'Build'. (You can Build in Debug or Release Modes.) After that you will now have a DLL file at "..\vbBlankClassLibrary\bin\vbBlankClassLibrary.dll".

 

At that point you could make a new EXE Project (which your Standard Edition can produce natively) and choose Alt|Project|References... and then hit the <Browse> button and browse until you find your file at "..\vbBlankClassLibrary\bin\vbBlankClassLibrary.dll".

 

From that point on, you can then reference your vbBlankClassLibrary.Class1, etc. from within your EXE. :)

 

I hope this was clear?

-- Mike

Posting Guidelines

 

Avatar by Lebb

Posted

Man, it seem like this .net is determined to not let me do anything...

 

now it says it's "not fully trusted by the runtime" and I "may recieve unexpected security exceptions"

 

I went ahead anyway.. and I have an instance of the IDE with nothing in it.I put in a form with a couple buttons and it doesn't like that either.

 

I think I'm just gonna give up. I thought the reason for this whole thing was to let you reuse code and forms.

 

Why does it make it so damn difficult to do that?

Posted

Oh, I'm sorry...

 

(1) Ignore the "security warning" in this case. It just means that this project did not originate on your own PC. (Which you knew. :))

 

(2) Yes, a DLL "Class Library" does not include Forms support by default. It can be added however. (Sorry I forgot to add this in the original attachment.)

 

You can add it by going to Alt|Project|References... and then clicking on the '.NET' Tab. Then scroll down until you find "System.Windows.Forms.dll". Select it and then click <OK>.

 

After that, you should be able to add Forms and Controls no problem. :)

 

(3) Or use the new-project that I've now attached below, where I've added that Reference for you.

 

-- Mike

vbBlankClassLibrary.zip

Posting Guidelines

 

Avatar by Lebb

Posted (edited)

Mike you are really a swell guy. I truly appreciate it.

 

Now.. I put a form with a button ... It won't let me run it ???

I would hate to have to compile anything of any size just to have to test it.

Edited by realolman
Posted (edited)

Heh, ok, thanks :)

 

As for your current issue... Well, you can't run a DLL directly, right? If you want this to run directly, you should really make an EXE! I guess you got the following error message?

A project with an Output Type of Class Library cannot be started directly. In order to debug this project...

 

What you need to do is add another Project that acts as the EXE calling your DLL:

 

(1) Within the Solution Explorer, right-click on the very top entry: "Solution 'vbBlankClassLibrary' (1 project)". Choose "Add" and then "New Project..."

 

(2) This Startup Project needs to be an EXE, so choose a "Windows Application" project. Give it an appropriate Name and Path Location and then click <OK>.

 

(3) If you didn't rename it from the default, the added project will now be seen within the Solution Explorer under the name "WindowsApplication1". We need to do two things with this new Project:

 

(a) Right click on the "WindowsApplication" Icon and choose "Set As Startup Project". (This is roughly in the middle of a rather long list of choices.) If you did this correctly, then your 'vbBlankClassLibrary' will no longer be in bold and 'WindowsApplication1' will now be the startup project and will show up is bold.

 

(b) We need to add a reference to your 'WindowsApplication1' Project to your 'vbBlankClassLibrary'. Under 'WindowsApplication1', right click on 'References'. Choose "Add Reference...". Then click on the 'Projects' tab and you will see your 'vbBlankClassLibrary' there. :) Double-click it and then click <OK>.

 

At this point you can now add code within your WindowsApplication1, referring to your DLL. In other words, you can now add code like:

Dim oClass1 As vbBlankClassLibrary.Class1 = New vbBlankClassLibrary.Class1
MessageBox.Show(oClass1.ToString) ' <-- Returns "vbBlankClassLibrary.Class1"

Hope this makes sense!

Mike

 

(Again, see attached project... :))

vbBlankClassLibrary.zip

Edited by PlausiblyDamp

Posting Guidelines

 

Avatar by Lebb

  • Leaders
Posted

Just a note about VB.Net standard:

 

It has no library (DLL) project templates or project settings. You can only use VB.Net standard for libraries if you have an existing library project (or modify the project file manually). Try sharpdevelop... it is a free .NET IDE that comes with more templates for VB/C#/C++ projects than microsoft's standard versions. And its free. Can't go wrong with free.

[sIGPIC]e[/sIGPIC]
Posted

I really feel stupid here.

 

What I want to do is make a form with some buttoms and a text box for the purpose of gathering input.

 

It would look like a calculator and when the enter button is hit would make the number in the display available as a variable or something.

 

I would like to reuse this in various situations.

 

I imagine people are groaning at the simplicity of this, but it's what I want to do. I think that it should be much easier to do than it is, but I've already exhausted that spiel, and promised not to complain any more.

 

I appreciate all you and the other guys have done, but I still don't understand. I don't feel right having to be spoon fed everything. You didn't take me to raise.

 

I have never had to do this sort of thing before. I was always able to figure things out myself... buy a book or something... keep on plugging.

 

Back to the present...

Am I supposed to make the form in the instance of the IDE you sent and then compile it? I can't try to run it ( or whatever else I would make ) in Debug unless I compile it? Also, it doesn't seem to give me an opportunity to make a form.

 

I tried to change the extension of a form file with one button to.DLL from .EXE. with explorer. The form appeared in the IDE and was available to the inheritance picker, but the button didn't appear when run.

Posted

Ok, we can get you going, taking it to the next step is not hard at all... However, before going forward with how to make a Form, etc., we need to know if the existing Project is running as intended. If not, then we may need to change some settings, or references, etc...

 

So please confirm this first: If you download the latest attachment (in post #16) and then (1) Open the 'vbBlankClassLibrary.sln' and then (2) Hit the 'Start' button (or the <F5> Key), do you get a MessageBox that reports "vbBlankClassLibrary.Class1"?

 

If you got that going, then we can take it to the next level, which is not hard at all. So confirm at least that it's running right as is... If not, tell us what happens, or what error message you get.

 

:),

Mike

Posting Guidelines

 

Avatar by Lebb

Posted (edited)

It's no disgrace to be stupid , but it's unhandy.

 

I did not have the attachment from post 16. I do now.

 

Yes, it shows the MSgBox that you described

Edited by realolman
Posted (edited)

Ok... no trouble, just glad it's working so far. :)

 

Now I just added a new Form by right-clicking on the 'vbBlankClassLibrary' in the Solution Explorer window, then choosing 'Add' and then 'Add Windows Form' and then choosing 'Windows Form'.

 

I then renamed the name of the Class to be "FormDLL1". I then added some code, which is not that important. It's just some basic starter code with one TextBox and one Label.

 

How we call this form is what is important. We now shift over to the 'Form1' within 'WindowsApplication1' and add place the following code:

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private Sub Button1_Click(ByVal sender As System.Object, _
                             ByVal e As System.EventArgs) _
                             Handles Button1.Click
       Dim dllForm1 As New vbBlankClassLibrary.FormDLL1
       dllForm1.Show()
   End Sub
End Class

This is all we need. When you click 'Button1' on the 'WindowsApplication1.Form1' the Sub Button1_Click() gets called. The code within that does the following:

  1. Dim's a new 'dllForm1' variable and sets it to a New 'vbBlankClassLibrary.FormDLL1'.
     
  2. Calls dllForm1.Show()

That's enough to get you going, try it! (And yes, the new version is attached below. :))

 

(Note that to open a Form in "Modal" mode, instead of "Modeless" as the above does, you would instead call 'DllForm1.ShowDialog()', which also returns a result showing how the Form was closed).

 

You're probably close to being out of the woods I think at this point... However, as you are seeing first hand, .Net is not a "jump right in" environment as was VB6. I think it's really important that you pick up a good .Net book. For a general listing, you can see this Forum's listing of Samples, Books, and Tutorials. However in your case, you really could use a good VB.Net book in particular, so you should probably have a look at XDNT's listing: Visual Basic .Net Books.

 

But don't hesitate to re-post here! I don't mind at all walking you through this.... But you should try to understand how the current version is working. If you don't quite "get it" then just ask!

 

:),

Mike

vbBlankClassLibrary.zip

Edited by Mike_R

Posting Guidelines

 

Avatar by Lebb

Posted

I'll have to look this thing over.

I ran it. Thank you for all your trouble.

 

This "FormDll1" would be the equivalent of the one I said I wanted to reuse. is that right?

 

I used the inheritance Picker to try to use the form in another project.

 

Why was it named "FormDLL1" originally, but when looked for it in the directory to pick it, it showed up "as "vbBlankClassLibrary.dll" ?

 

Then in the inheritance picker it was called:

 

Component name: "FormDLL1"

 

Namespace: "vbBlankClass library"

 

I was looking for "FormDLL1" and it wasn't there . How do you know what you're looking for?

 

Also the "Form1" from the original Windows application did not seem to be available to be picked. Not that I wanted it, but why is that?....

 

Why is it that your download saved forms in a manner that could be inherited, but mine did not?

 

I have 6 books, I've read the majority of them . It seems like its either simple stuff that I understand easily, or it's nuts stuff. As if there's a big hunk of intermediate stuff missing. I don't know why, but it just ain't clickin'

 

I've been doing Basic and VB for a long time and this .net thing has about got me stumped. Nothing makes any sense to me.

 

Anywho... thank you!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...