|
-
Aug 25th, 2004, 02:46 PM
#1
Thread Starter
New Member
Pointers
Dear all,
I would like to pass a string as parameter to a form that would modify it. Then, as a result, I would like, when finish the form, to change this variable.
Observe that the I will need to access the parameter in many subs and functions before it is ready to be returned.
I am thinking use pointers to this string to have how to modify it?
How can I do it?
If I pass a Label.Caption as parameter, could I modify it on a function?
Thanks in advance,
Nizam
-
Aug 25th, 2004, 03:20 PM
#2
You can pass objects through forms. Here is a small sample project:
VB Code:
'Form1:
Option Explicit
Private Sub Command1_Click()
Form2.SetLabel Label1
Form2.Show vbModal
End Sub
VB Code:
'Form2:
Option Explicit
Dim MyLabel As Label
Public Sub SetLabel(ByRef TheLabel As Label)
Set MyLabel = TheLabel
End Sub
Private Sub Command1_Click()
MyLabel.Caption = MyLabel.Caption & " Changed content"
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set MyLabel = Nothing
End Sub
Hope this helps
-
Aug 25th, 2004, 03:24 PM
#3
You may certainly pass label's caption as parameter anywhere in your project.
It will, however, be beneficial for you (and your program) if you create a Public Property directly on your form that processing this value so you may access it regadless of form being loaded into a memory.
Let me know if you need more help on this subject.
Best regards.
-
Aug 25th, 2004, 03:42 PM
#4
Thread Starter
New Member
But I would like to change the string that I passed as parameter and I would not be able to do this working with a form property. How do I implement an event to observe this new property changes?
With the object label worked because I pointed the both objects to the same address. How could I do this with strings?
-
Aug 25th, 2004, 04:27 PM
#5
... many ways ...
- one (not the best but will work for you) is to use timer and every once often update your label's caption:
Label1.Caption = frmProcess.SomeProperty
- another is to set label's caption directly from that form every time property is changed:
frmMain.Label1.Caption = SomeProperty
... and so on ...
-
Aug 25th, 2004, 04:35 PM
#6
Thread Starter
New Member
BTW, how can I create a new label?
Set Label1 = New Label
is note working...
-
Aug 26th, 2004, 02:10 AM
#7
If you really really need to do it with strings, you need to use CopyMemory to edit the variable's address. I have never done this: you should find out where the variable's location is stored in memory and then change it to point to the new location in memory. Imo not worth it (because it is probably different in compiled program).
Just declare a public string in a module and then use it on both forms.
-
Aug 27th, 2004, 01:17 PM
#8
Originally posted by nizam
BTW, how can I create a new label?
Set Label1 = New Label
is note working...
In VB6 there are two ways to create a new control at run time:
1. Control Arrays.
2. Controls collection.
If you want to create a brand new instance then use method 2:
VB Code:
Dim lbl As Label
Set lbl = Me.Controls.Add("VB.Label", "Label1")
lbl.Move 300, 300
lbl.Caption = "Label1"
lbl.Autosize = True
lbl.Visible = True
... to remove control from controls collection use Remove method:
VB Code:
Me.Controls.Remove "Label1"
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
|