|
-
Jul 1st, 2005, 10:23 AM
#1
Thread Starter
Lively Member
Can I call a method of an object in runtime by "object name" string?
Private Sub FormShow(FormName as string)
dim f as Form
f = FormName //?????
load f
f.show 1
End Sub
Can I reference to an object by help of its name (string) in runtime?
-
Jul 1st, 2005, 10:29 AM
#2
Re: Can I call a method of an object in runtime by "object name" string?
 Originally Posted by ultra2
Private Sub FormShow(FormName as string)
dim f as Form
f = FormName //?????
load f
f.show 1
End Sub
Can I reference to an object by help of its name (string) in runtime?
In order to reference an object...
VB Code:
Dim f As Form
Set f = Form2
f.Show
-
Jul 1st, 2005, 10:31 AM
#3
Re: Can I call a method of an object in runtime by "object name" string?
Why not just do
Private Sub FormShow(FormName as Form)
FormName.Show
End Sub
-
Jul 1st, 2005, 10:35 AM
#4
Re: Can I call a method of an object in runtime by "object name" string?
For that matter, why the sub at all. Form1.Show is less typing than creating the sub and typing FormShow Form1
-
Jul 1st, 2005, 03:50 PM
#5
Thread Starter
Lively Member
Re: Can I call a method of an object in runtime by "object name" string?
The form name is a string and I get it from a database field IN RUN TIME.
It could work, but I have 200 form in my app so I need a more generally solution than this:
Private Sub FormShow(FormName as string)
if From1.name = FormName then From1.show
if From2.name = FormName then From2.show
if From3.name = FormName then From3.show
...
End Sub
-
Jul 1st, 2005, 05:14 PM
#6
Re: Can I call a method of an object in runtime by "object name" string?
Why would you need 200 forms? if you dont mind me asking.
It seems a little too much.
-
Jul 1st, 2005, 07:06 PM
#7
Junior Member
Re: Can I call a method of an object in runtime by "object name" string?
I don't know of any way to open a form in the way you want. If you want to open a form, use a select case statment:
VB Code:
Select Case FormName
Case "Form1"
Form1.show
Case "Form2"
...
End Select
This may not be easy, but I know of no other way (and it is easier than 200 if ... then statments)
-
Jul 1st, 2005, 07:37 PM
#8
Thread Starter
Lively Member
Re: Can I call a method of an object in runtime by "object name" string?
I also could use the "Forms" array, but it only consist of the loaded forms and I dont want to load all the forms of my App.
Any other way to loop through all the forms of the app?
-
Jul 2nd, 2005, 12:56 AM
#9
Re: Can I call a method of an object in runtime by "object name" string?
No, sorry. Only way apart from the Forms collection is to use a Select Case as Mikewitt posted.
VB Code:
Dim frm As Form
For Each frm In Forms
If frm.Name = strName Then frm.Show
Next frm
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
|