Conversion of String Variable to Form Object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vibhore agarwal
    New Member
    • Aug 2006
    • 2

    Conversion of String Variable to Form Object

    Hi all,

    i required help to solve the below problem,

    i have some forms with name "form1", form2", "form3" etc..
    and i want to load them on the request of user.. means
    if user enters the name "form1" in the text box of another form and click on the button. then form1 should load and appear on the screen. as so on..

    conditions are:
    conditional statements can not be utilized becaz quantity of forms may be dynamic so we i chage code again and again..

    fact is that, when a new form generated i have to desing and code the functionality of that form only, no need to modify other code..

    thanx...in advance

    regards
    vibhore
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi there,

    1st create a module file.. under the general declaration section add the below code segment..

    Code:
    Public Const FRM1 As String = "Form1"
    Public Const FRM2 As String = "Form2"
    Public Const FRM3 As String = "Form3"
    in your form, under your command click event add the following code segment..
    Code:
      If Text1.Text = "FRM1" Then
        Load From1
        Form1.Show
      ElseIf Text1.Text = "FRM2" Then
        Load From2
        Form2.Show
      ElseIf Text1.Text = "FRM3" Then
        Load From3
        Form3.Show
      End If

    Comment

    • vibhore agarwal
      New Member
      • Aug 2006
      • 2

      #3
      hi sashi,
      actually we dont want to use if or any other conditional blocks, because maintenance is not easy is this, suppose if we have 100 forms then we have to place 100 ifs. So we required that take a string from user or read from xml file in string form and then if it is possible then convert the value of string variable as form object and call show method.
      pls try in this respect, becaz of requirement
      do u know any method throgh which we can convert a string into form object....
      i m also searching..

      Regards
      vibhore

      Comment

      • BSOB
        New Member
        • Jul 2006
        • 77

        #4
        um... you need an object variable:
        module:
        global FormName as object
        click event:
        formname = text1.text
        'maybe this should be formname.name = text1.text, im not sure
        formname.show

        'poof!

        Comment

        • BSOB
          New Member
          • Jul 2006
          • 77

          #5
          after testing, i am inclined to withdraw my last post.
          and i will replace it with something that is likely just as useless:

          'module:
          global FormName(1 to 100) as object
          sub main
          formname(1) = form1
          formname(2) = form2
          formname(3) = form3
          ...
          formname(99) = form99
          end sub
          'click event:
          dim i as integer
          for i = 1 to 100
          if formname(i).nam e = text1.text then
          formname.show
          exit sub
          end if
          next i
          msgbox("im sorry, i must have mis-heard you.")

          this avoids conditional blocks, but you must still list your forms in the module which might not be dinamic enough for your purpose. i dont know if there is a way to automatically list all the forms into an array. something like <create list of all form objects and put in array> but... not. someone else might see that and be able to give you a suggestion on it.

          Comment

          Working...