|
-
Nov 7th, 2001, 07:13 AM
#1
Thread Starter
Lively Member
call variable from different form
i got a multiple form in my project
i have to call the variable from the different form
the variable is not public declared
can i do it
all the from are loaded
with Regards
sameer Mulgaonkar

-
Nov 7th, 2001, 07:15 AM
#2
Addicted Member
You could have the variable as a public property of your form.
example:
VB Code:
'Private variable in form1
Private m_myVar as string
'Public property Read/Write
Public Property Get myVar() As String
myVar = m_myVar
End Property
Public Property Let myVar(ByVal RHS As String)
m_myVar = RHS
End Property
'You can then call from anywhere like
Form1.myVar = "Test"
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 07:15 AM
#3
Retired VBF Adm1nistrator
Or add a module, and make the variable public there.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 7th, 2001, 07:16 AM
#4
Thread Starter
Lively Member
i dont want to declare the variable public of a reson
i just want to know can we do it this way
with Regards
sameer Mulgaonkar

-
Nov 7th, 2001, 07:17 AM
#5
Retired VBF Adm1nistrator
Okay, if you dont want to declare it Public, then declare it Global
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 7th, 2001, 07:19 AM
#6
Addicted Member
The variable will not be publicly declared if you do it as a property of the form.
It will only be accessible through the form in which you place it.
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 07:19 AM
#7
Thread Starter
Lively Member
no public no global just priavte for the form
and the form is loaded
can i call them from different form
with Regards
sameer Mulgaonkar

-
Nov 7th, 2001, 07:21 AM
#8
Addicted Member
the only other alternative is create a method on the form that alters the variable.
It has to be public somewhere if you want to change it from anywhere other than the form
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Nov 7th, 2001, 07:29 AM
#9
PowerPoster
Wow strict rules!! 
You could also create a public (scared to use that word ) function in the form and call it from the other form like this...
VB Code:
'Form1------------------------
Private Sub Command1_Click()
Form2.Show
Debug.Print Form2.PassVar
End Sub
'Form2------------------------------
Option Explicit
Dim MyPrivVar As Integer
Private Sub Form_Load()
MyPrivVar = 2
End Sub
Function PassVar() As Integer
PassVar = MyPrivVar
End Function
-
Nov 7th, 2001, 07:33 AM
#10
Retired VBF Adm1nistrator
I think people just have a thing against public variables and functions ...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 7th, 2001, 07:37 AM
#11
PowerPoster
Yeah
but i'd much rather use a module with public variable than a form level variable or function. Cos then u have to cater for the form load events that can fire when u didnt want them to.
Bah!
-
Nov 7th, 2001, 07:39 AM
#12
-
Nov 7th, 2001, 07:41 AM
#13
Retired VBF Adm1nistrator
I like modules because they're totally independant.
Though the only downside is that when you use a variable or function from a module, the entire module is then loaded into memory
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 7th, 2001, 08:19 AM
#14
Conquistador
can you not store your info in the form.tag property?
-
Nov 9th, 2001, 04:26 AM
#15
Retired VBF Adm1nistrator
Performance wise storing something in the .Tag property is like pulling a loaded trailer up a steep hill in a ten year old skoda.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 9th, 2001, 05:09 AM
#16
Conquistador
-
Nov 9th, 2001, 05:15 AM
#17
Retired VBF Adm1nistrator
All properties in VB are far far far slower than a variable.
VB Code:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private strTag As String
Private Sub Form_Load()
Dim time1 As Long, time2 As Long
Dim i As Long
Tag = "I 0wnz"
strTag = "I 0wnz"
time1 = GetTickCount
For i = 0 To 100000
If Tag = "I 0wnz" Then
End If
Next
time1 = GetTickCount - time1
time2 = GetTickCount
For i = 0 To 100000
If strTag = "I 0wnz" Then
End If
Next
time2 = GetTickCount - time2
MsgBox time1 & vbCrLf & time2
End Sub
144 v 35 in favour of variables
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 9th, 2001, 05:29 AM
#18
Conquistador
You wrote a function to prove that ehh
-
Nov 9th, 2001, 05:32 AM
#19
PowerPoster
Where Jamie works they always give him things like that to do so that the secretaries dont sue for constant sexual harrassment
-
Nov 9th, 2001, 05:54 AM
#20
Retired VBF Adm1nistrator
Nah I just like code optimization.
Gotten into a real routine now. When I come up with a different way of doing something, I click on the little VB6 icon in my taskbar thingy, new project, then click the Show Desktop button on my taskbar, double click the shortcut to win32api. Hit CTRL-F and type in GetTickCount and hit find next twice.
Copy the line. Alt-tab into VB. Right click on form and do View Code. Type Private and then hit CTRL-V
Then double click on form to create the on load code, declare the 2 time variables and a counter. Then compare, msgbox, and write down the results
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 9th, 2001, 06:36 AM
#21
Conquistador
-
Nov 9th, 2001, 06:39 AM
#22
Retired VBF Adm1nistrator
Ah shag off.
Not my fault I ownz is it
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 9th, 2001, 06:47 AM
#23
Conquistador
But do you....
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
|