Open a form in code

Post

Posted
Rating:
#1 (In Topic #1287)
Regular
bill-lancaster is in the usergroup ‘Regular’
If I have only the name of a form(as a string) how can I open the form?

This doesn't work.

Code

 
      Dim hForm As New Form["FMain"]

I hope this isn't a daft question!
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Not daft.
I assume you have a set of different forms, "ThisForm", "ThatForm" etc.
You also have a set of criteria for deciding which form you want….

The way I have always done this is along the lines of

Code (gambas)

  1. Select criteria
  2.     Case "the carkeys are in the fridge"
  3.        Dim hForm as New FKeysInFridge
  4.     Case "no cheesecake"
  5.        Dim hForm as New FBuyCheesecake
  6.     Case Else
  7.        Message.Confused("I have no idea what you want!)
  8.    End Select

Have a nice weekend 8-)

b

Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
 Thanks Bruce
the project has about 20 forms and which may change/increase/decrease with time, also I'm logging form usage in an sql database.
 
The forms are opened from a menu event so: "MyMenus_Click()" allows me to retrieve the name of the form to be opened.  If I could the open that form using the string returned from the database  the code would be greatly simplified.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Maybe

Code (gambas)

  1. theForm=Object.New(theFormName)
? Haven't tried it.
b

Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
bill-lancaster is in the usergroup ‘Regular’
 That works just fine.
Enjoy the whisky.
Bill
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’
If you created many sub-Forms, you could do this:

Code (gambas)

  1. Public Sub Menu2_Click()
  2.  
  3.   With SubForm1
  4.     .Center
  5.     .W = 200
  6.     .H = 100
  7.     .Show      '  ...or even like this: .Raise()
  8.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Regular
bill-lancaster is in the usergroup ‘Regular’

Code

theForm=Object.New(theFormName)
has been working fine.

Would it be possible to open a given form (knowing only the form's name) from a library?
At the moment I get the error "Cannot load class 'form name'. File or directory does not exist.

Any ideas would be appreciated

Thanks
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Guru
cogier is in the usergroup ‘Guru’
Does this help?

Code (gambas)

  1. Public TheForm As Form
  2.  
  3. Public Sub Form_Open()
  4.  
  5.  
  6.   With TheForm = New Form As "TheForm"
  7.     .H = 300
  8.     .W = 300
  9.     .Background = Color.Blue
  10.     .Center
  11.     .Show
  12.  
  13.   Wait 3
  14.   TheForm.Hide
  15.   Wait 3
  16.   TheForm.Show
  17.   Wait 3
  18.   TheForm.Close
  19.  
  20.  
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
bill-lancaster is in the usergroup ‘Regular’
 Thank you cogier, not sure if it helps at the moment.  I have several projects which use a library (say MyLib).  I wish to have a function in MyLib which will open an existing form in the project.  Hope that makes sense.
Bill
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Guru
cogier is in the usergroup ‘Guru’
 Sorry Bill, but I don't understand. Can you post some code we can look at.
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Hi Bill,
I use this subroutine to open all but the main form in all of my projects.
I declare it in the a project module where all the generic subroutines & functions are called from.
It 'should' work from your MyLib but obviously testing is required…

Code (gambas)

  1. Public Sub DisplaySubForm(InTitle As String, CanResize As Boolean, ShowOnly As Boolean, ByRef InForm As Form)
  2.  
  3.   InForm.SkipTaskbar = True
  4.   InForm.Title = Application.Title & " - " & InTitle
  5.   InForm.Resizable = CanResize
  6.   InForm.Center
  7.   If ShowOnly Then
  8.     InForm.Show
  9.     InForm.Stacking = Window.Above
  10.   Else
  11.     InForm.ShowModal
  12.  

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
bill-lancaster is in the usergroup ‘Regular’
 Thanks Quin, that'll do nicely.
Regards
Online now: No Back to the top
1 guest and 0 members have just viewed this.