-
RE:Declaring Global Variable
hi good day...is it possible to declare a variable to be access on all my forms..and is it possible to make a function that can also be access to all my forms?like in php...if module is the answer how do i declare it and access it in my forms..tried it but i failed...im try to make my program more simple
-
Which language are you using? If you're using VB, add a Module to your project. Public variables in a Module are visible throughout the application:
Code:
Module Globals
Public MyGlobalVariable As String
End Module
Class MyForm
Public Sub SomeMethod()
Dim LocalString As String = Globals.MyGlobalVariable
End Sub
End Class
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
im using VB...
Class MyForm
Public Sub SomeMethod()
Dim LocalString As String = Globals.MyGlobalVariable
End Sub
End Class
is this declared together with the module or its an example on how will i access it in my form
-
It's an example of how to access the variable from your form. Access the variable using <ModuleName>.<VariableName>.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Module Global
Public MyString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\posdb.mdb"
Public MyConn As New Oledb.OledbConnection(MyString)
Public MyCmd As Oledb.OledbCommand
End Module
is this possible?i think its not working...
-
Try
Code:
Public MyString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\posdb.mdb"
Public MyConn As OleDb.OleDbConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyConn = New OleDbConnection(MyString)
MyConn.Open()
End Sub
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
thanks hack working fine..thank you also phil..
btw is it possible to make functions that can be access globally?
-
Yes, same method as above: declare the functions as public within a module, then call them using <ModuleName>.<FunctionName>.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
 Originally Posted by chokies12
btw is it possible to make functions that can be access globally?
Sure....just like variables, make 'em Public.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
can you give me a example on how to define and access it?
-
Code:
Module Globals
Public Function MyFunction(ByVal MyParameter As String) As String
Dim SomeValue As String = "blah"
Return SomeValue
End Function
End Module
Class MyForm
Public Sub SomeMethod()
Dim ReturnValue As String = Globals.MyFunction("Foo")
End Sub
End Class
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Similar Threads
-
By yvette.renee in forum Database
Replies: 5
Last Post: 04-17-2008, 01:29 PM
-
By hkwan in forum ASP.NET
Replies: 0
Last Post: 08-28-2001, 03:18 AM
-
Replies: 0
Last Post: 07-09-2001, 04:16 PM
-
By Michael Shutt in forum Database
Replies: 2
Last Post: 03-29-2001, 02:34 PM
-
By Roberto Marques in forum Web
Replies: 0
Last Post: 06-08-2000, 10:36 AM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks