Results 1 to 6 of 6

Thread: [RESOLVED] Public variable in standalone exe

  1. #1

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651

    [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 ...

  2. #2

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    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:
    1. Class MainDriver
    2.   Public Shared Sub Main()
    3.      ' The actual connect string will be built by a call to a login form
    4.      Dim dummy as New MyConn("provider=sqloledb;database=....")
    5.   End Sub
    6. End Class
    7. Class AnotherClass
    8.    Public Sub DoQuery()
    9.       dim connstring = MyConn.ConnectString
    10.    End Sub
    11. End Class
    12. Class MyConn
    13.     Public Sub New(ByVal value As String)
    14.         Me.ConnectString = value
    15.     End Sub
    16.     Public Shared ConnectString As String
    17.  
    18. 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 ...

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  4. #4

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    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 ...

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  6. #6

    Thread Starter
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Thanks hellswraith
    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
  •  



Click Here to Expand Forum to Full Width