|
Hiya,
I was just wondering how (if possible) to add a windows form to a DLL in Vb.net? I have searched on the internet for examples but havent found anything useful
Thanks,
Lloyd
P.S. May take me a while to reply, Im away for a while.
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" - ALbert Einstein
I look at Microsoft, and turn to my poster on the wall saying: "Bang head here in case of stress".
|
|
|
|
|
You set the project as a dll assembly, and then create forms in the dll. Then make reference to that dll to use the forms. You will have to create the forms in the new project through code references to the dll assembly.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
You certainly can, however your entry point will be a class and not the form. I have a logon DLL that is used by all our apps for authentication, the whole thing (2 forms, 3 classes) is wrapped in a DLL. Works perfectly.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
On the memory side of things, is it better to use the second example versus the first one, or does it not really matter in the end?
How is memory allocated in the two situations? Will the first one create a ton of objects that get cleaned up after they drop out of scope? Will this affect memory and garbage collection?
For i As Integer = 0 To costTable.Rows.Count - 1
Dim row As DataRow = costTable.Rows(i)
'use the data in the row
Next
Dim row As DataRow = Nothing
For i As Integer = 0 To costTable.Rows.Count - 1
row = costTable.Rows(i)
'use the data in the row
Next
modified on Saturday, August 23, 2008 2:08 PM
|
|
|
|
|
I'm not sure, but I think that it doesn't matter ... That they're the same ...
|
|
|
|
|
The generated code for the both examples will be exactly the same, except that the variable will be assigned a null value before the loop in the second example.
The variable is allocated on the stack, which is very cheap. No objects are created, so there is no garbage collection involved at all. The scope of the variable differs between the examples, but that only matters to the compiler. All local variables are always allocated when the stack frame for the method is created, regardless of where in the method the variables are declared.
Unless you need the counter variable for something else, I would recommend that you use ForEach instead:
ForEach row As DataRow in costTable.Rows
'use the data in the row
Next
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the excellent explanation.
I understand there are certain precautions to using a foreach, sometimes it can create overhead from an enumerator. Is there an easy way to know the difference?
|
|
|
|
|
The ForEach loop uses an enumerator, however the enumerator is usually a struct so it's allocated on the stack.
The performance difference between a ForEach loop and using a counter is quite small, and it depends on the situation whichever is faster. Unless you have an actual performace problem, you should just use the one that best fits your needs.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Monday, August 25, 2008 6:21 PM
|
|
|
|
|
Hey,
I'm trying to get my program to launch from a file with an associated extension and have the program immediately load that file.
I've already figured out how to register the extensions thanks to the article at http://www.codeproject.com/KB/vb/VBFileAssociation.aspx[^]. If I doubleclick the external file, my app does successfully launch, but I'm having difficulty getting it to actually load the external file.
So far I think my best bet is to use Application.CommandLineArgs, but I'm not having any luck implementing it. I've tried using the following code, but haven't had any success:
Friend myArgument As String = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
myArgument = My.Application.CommandLineArgs(0)
Catch ex As Exception
If myArgument <> "" Then
InputFile(myArgument)
End If
End Try
...
Does anyone have any ideas? Thanks a bunch!
|
|
|
|
|
Why do you have the InputFile() in the Catch block? Just check to see if there is an argument, and if there is get it:
If My.Application.CommandLineArgs.Count > 0 Then
Dim file As String = My.Application.CommandLineArgs(0)
MsgBox(file)
End If
Then you can do whatever you want with it.
|
|
|
|
|
Hello,
How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location.
Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database?
John,
|
|
|
|
|
you can set connection string in ur web config file
|
|
|
|
|
If only this was for ASP.NET...
|
|
|
|
|
John,
Maybe you should check out SQL Server Compact Edition[^]. "SQL Server Compact is a free, easy-to-use embedded database engine that lets developers build robust Windows Desktop and mobile applications that run on all Windows platforms including Windows XP, Vista, Pocket PC, and Smartphone."
You can also use SQL Server Express Edition (on localhost) and use a connection string that attaches the database each time you want to connect:
Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
|
|
|
|
|
Check the following link out it would be helpful for you:
Secure Connection and Easy transaction Handling^
In the above link the connection string is read through DBConfig.ini and when you change the database location just change it in the ini file and would work perfectly for your web or desktop applications.
|
|
|
|
|
I'd do something different from the other suggestions listed. I'd create a UDL file within your application directory. Your program will read the UDL for the connect string. If you run your app on another computer/domain, you can easily update the connect string through the UDL's GUI (eliminates the possibility of manually entering in the connectstring in a file and making a mistake).
Right click on your desktop and create a .txt file. Rename the file to something like test.udl. Double click it and you'll see what I'm getting at.
There's numerous articles on how to read a udl if you need help.
Cheers!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
|
|
|
|
|
Store your connection string in the application settings and set all connection objects to the application setting
To store an app setting:
Right click your project > properties > settings > add your connection string
Alexei Rodriguez
|
|
|
|
|
Under is some code of C#, i would like all of you to show me how can to VB.net because i don't know C# at all and i don't know this code as well.
Thanks for your help...
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
allStands = new List[] { Stand1plates, Stand2plates, Stand3plates };
// Stand2plates.Add(3);
}
List[] allStands;
List Stand1plates = new List();
List Stand2plates = new List();
List Stand3plates = new List();
private void MoveFromTo(int source, int dest)
{
int top = allStands[source-1][allStands[source-1].Count - 1];
allStands[source - 1].Remove(top);
allStands[dest-1].Add(top);
RedrawPanels();
}
=================================
I change it to VB.net as bellow:
Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
' Stand2plates.Add(3);
allStands = New List() {Stand1plates, Stand2plates, Stand3plates}
End Sub
Private allStands As List(Of Integer)
Private Stand1plates As New List(Of Integer)
Private Stand2plates As New List(Of Integer)
Private Stand3plates As New List(Of Integer)
Private Sub MoveFromTo(ByVal source As Integer, ByVal dest As Integer)
Dim top As Integer = allStands(source - 1)(allStands(source - 1).Count - 1)
allStands(source - 1).Remove(top)
allStands(dest - 1).Add(top)
RedrawPanels()
End Sub
End Sub
but it has error where underline. what's problem ? How do i change it ?
VB.Net
|
|
|
|
|
Sovann wrote: error where underline
What underline?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
sorry it's not show the underline i put tag but it not show.
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
allStands = new List[] { Stand1plates, Stand2plates, Stand3plates };
// Stand2plates.Add(3);
}
List[] allStands;
List Stand1plates = new List();
List Stand2plates = new List();
List Stand3plates = new List();
private void MoveFromTo(int source, int dest)
{
int top = allStands[source-1][allStands[source-1].Count - 1];
allStands[source - 1].Remove(top);
allStands[dest-1].Add(top);
RedrawPanels();
}
=================================
I change it to VB.net as bellow:
Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
' Stand2plates.Add(3);
allStands = New List() {Stand1plates, Stand2plates, Stand3plates}
End Sub
Private allStands As List(Of Integer)
Private Stand1plates As New List(Of Integer)
Private Stand2plates As New List(Of Integer)
Private Stand3plates As New List(Of Integer)
Private Sub MoveFromTo(ByVal source As Integer, ByVal dest As Integer)
Dim top As Integer = allStands(source - 1)(allStands(source - 1).Count - 1)
allStands(source - 1).Remove(top)
allStands(dest - 1).Add(top)
RedrawPanels()
End Sub
End Sub
VB.Net
|
|
|
|
|
I am trying to develop a ambitious program, that moves a telescope and much more. I need to access the ascom interface. It is accessible with vbscript 5. I understand I need to call a vbscript from within my vb2005 program and have the control return back to the program. I understand this is done using a thread.
Can someone point me in the right direction?
modified on Friday, August 22, 2008 11:15 PM
|
|
|
|
|
Do you have the script to run as a .vbs file? You can run the .vbs file by executing cscript.exe and passing the name of the .vbs file as an argument. Check out the System.Diagnostics.Process class. Also, that class has a WaitForExit() method which will allow the .vbs script to finish executing before returning control to your VB program.
|
|
|
|
|
I am working with VB.Net 2005 and I am re-writing a small program that was in VB6 format. I currently have a Dataset looking at my Access database. In the old code it used these statements to look at the database.
Public dbComp As DAO.Database
Dim qdf As DAO.QueryDef
Dim tdf As DAO.TableDef
The routine that I am working with looks at the database (dbComp) and it deletes quries and creates them and then populates them.
I am hoping that I can use my existing Dataset that I created instead of using these DAO connections. Can anyone help me out with this? I just need to know what I can use in .Net in place of those commands above.
Thank you in advance for any help you can provide!
|
|
|
|
|
You can certainly use ADO.Net and OLEDB via DataSets and DataViews to retrieve, update, insert or delete records in an Access database from .Net.
However, you can not use ADO.Net to create an Access database, or any of the objects (tables, queries, etc.) in an Access database. One way to create an Access database and table objects from .Net would be to first create references to, and corresponding InterOps for, Microsoft ActiveX Data Objects. I imagine that a google will turn up lots of examples on creating Access databases and tables from .Net after making the proper references to ActiveX Data Objects.
Good luck with your project.
|
|
|
|
|
Another way to create an Access database without all of that hassle:
If you know the basic structure of the Access Database, then you create the basic 'template' in Access and then embed the database into your application. Then through the use of File.IO and Reflection you can stream the template to a local file for alteration. (It is simpler than it may sound).
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|