Solved

VB 4.0 How to load a form by VarName

Posted on 1998-12-10
5
130 Views
Last Modified: 2011-09-20
I want to read the name of the last loaded form out or a .ini-file. Then I want to load the form.

For example:
the last form was 'frmTest'. I read the name into gsForm.
Now I want to load the form 'frmText'.

I can't use the code
 For x = 0 to Forms.Count-1
    ...
 Next x

because it only works with the forms already loaded.
What's to do?
0
Comment
Question by:koz2355
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 1449256
Before I can answer your question, I would like to have a bit more information.

1 - Do you refer to your form frmTest by its design time name?
    for example
    frmTest.Show vbModal
2 - Do you instantiate your form through object variables?
    for example
    Dim myForm As frmTest
    Set myForm = New frmTest
    myForm.Show vbModal
3 - Do you wish to re-display a form with its old contents or do you intend to create a new instance of the form?


0
 

Author Comment

by:koz2355
ID: 1449257
Hi caraf_g,

frmTest was an example. the formname could be any form in my application the user can work with. For better understanding:
dim gsForm as string
gsForm = "frmTest"
gsForm.Show <- something like this

greetings
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1449258
Sorry, not possible. The only thing that you can do is have an switch statement and test on the name and make an instance of this form.
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 20 total points
ID: 1449259
Having only used VB5 myself I can't guarantee that the following will work. I hope it is possible in VB4 to Dim variables As Object, and that you can use the Set keyword in VB4.

If you can, this might work for you:

Dim gobjForm As Object
Dim gsForm As String

Select Case gsForm
Case "frmTest"
    Set gobjForm = New frmTest
Case "<other form>"
    Set gobjForm =.... and so on
.
End Select

All the best, and good luck
0
 

Author Comment

by:koz2355
ID: 1449260
Hi caraf_g,
it works. Thank you very much.
greetings
koz2355
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now