|
-
Dec 27th, 2002, 08:40 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Public variable in standalone exe
I have a standalone executable that will connect to a database and perform various operations and immediately release the connection. At the beginning of the application at want to prompt the user for userid, password, database etc. and build a connect string that I want all class modules to share. In VB6 I would have used a public variable to store the connect string.
How do I achieve the same behaviour in VB.NET?
I've read things about singletones etc. but that would imply that I'd have to store the string in a file and pick it up each time I need it isn't it ?
Thanks
Last edited by Mr.No; Dec 27th, 2002 at 02:44 PM.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Dec 27th, 2002, 09:11 AM
#2
Thread Starter
Fanatic Member
OK, I think I have a clue now and I can use a Shared variable. This is how I want to do it, if anybody has any ideas please share it in the forum. I think I'll read a little bit more on shared/readonly variables.
VB Code:
Class MainDriver
Public Shared Sub Main()
' The actual connect string will be built by a call to a login form
Dim dummy as New MyConn("provider=sqloledb;database=....")
End Sub
End Class
Class AnotherClass
Public Sub DoQuery()
dim connstring = MyConn.ConnectString
End Sub
End Class
Class MyConn
Public Sub New(ByVal value As String)
Me.ConnectString = value
End Sub
Public Shared ConnectString As String
End Class
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Dec 27th, 2002, 10:32 AM
#3
PowerPoster
You should just be able to do this in a module. It is basically a static class, then you just refer to module.variablename to get the string into any class that is in the project.
-
Dec 27th, 2002, 02:27 PM
#4
Thread Starter
Fanatic Member
Thanks hellswraith. In fact I was trying to avoid a module, I dont know I kind of feel that using modules doesn't seem fully object oriented. I might be wrong ....
As a matter of comparison, would the module.variablename method work in C# ?
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Dec 27th, 2002, 02:31 PM
#5
PowerPoster
If you are using VB.net, then go ahead and use a module, that is what they are there for. If you really want, you can accomplish the same thing by creating a static class.
-
Dec 27th, 2002, 02:44 PM
#6
Thread Starter
Fanatic Member
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|