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
Printable View
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
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"
Or add a module, and make the variable public there.
i dont want to declare the variable public of a reson
i just want to know can we do it this way
Okay, if you dont want to declare it Public, then declare it Global :D
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.
no public no global just priavte for the form
and the form is loaded
can i call them from different form
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
:confused:
Wow strict rules!! :D
You could also create a public (scared to use that word :p ) 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
I think people just have a thing against public variables and functions ...
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! :D
:rolleyes:
Strange. I actually prefer the method of accessing them from properties on the form.
Each to their own I suppose :D :p
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
can you not store your info in the form.tag property?
Performance wise storing something in the .Tag property is like pulling a loaded trailer up a steep hill in a ten year old skoda.
how come?
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
You wrote a function to prove that ehh :p
Where Jamie works they always give him things like that to do so that the secretaries dont sue for constant sexual harrassment :D
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 :)
ooo
:eek:
I wanna be like you jamie :p
I will start comparing code :D with others'
Ah shag off.
Not my fault I ownz is it :)
But do you.... :p