Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. creating an object of a form at runtime using its name as string

creating an object of a form at runtime using its name as string

Scheduled Pinned Locked Moved Visual Basic
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    panalprasad
    wrote on last edited by
    #1

    Hi There is a form named "Form1" and a function for creating its object. the form name is passed to the function and creates an object public function CreateObj(p_sformName as string) as object dim obj as object ' create the object of a form. The form's name is passed from the calling place set obj = new p_sformname end sub Is it possible Thank you in advance Panal prasad

    T D 2 Replies Last reply
    0
    • P panalprasad

      Hi There is a form named "Form1" and a function for creating its object. the form name is passed to the function and creates an object public function CreateObj(p_sformName as string) as object dim obj as object ' create the object of a form. The form's name is passed from the calling place set obj = new p_sformname end sub Is it possible Thank you in advance Panal prasad

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      panalprasad wrote: set obj = new p_sformname the syntax is incorrect. as you wrote it, you try to new an object which type is p_sformName. replace it with obj = new String(p_sformname) this will create a new string which content is identical to the parameter passed to the CreateObj() function. now, if you want to create an object with another type than String, you must use a constructor that gets a String as parameter ; if it doesn't exist, you'll have to create it certainly... but i cannot help you more as your post is a bit too vague for me to know what you're looking for exactly


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      P 1 Reply Last reply
      0
      • T toxcct

        panalprasad wrote: set obj = new p_sformname the syntax is incorrect. as you wrote it, you try to new an object which type is p_sformName. replace it with obj = new String(p_sformname) this will create a new string which content is identical to the parameter passed to the CreateObj() function. now, if you want to create an object with another type than String, you must use a constructor that gets a String as parameter ; if it doesn't exist, you'll have to create it certainly... but i cannot help you more as your post is a bit too vague for me to know what you're looking for exactly


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        P Offline
        P Offline
        panalprasad
        wrote on last edited by
        #3

        The obj variable is needed for seting the form object. and the name of the form is p_sformname. so if p_sformname="Form1" then obj will assaign an object of Form1

        1 Reply Last reply
        0
        • P panalprasad

          Hi There is a form named "Form1" and a function for creating its object. the form name is passed to the function and creates an object public function CreateObj(p_sformName as string) as object dim obj as object ' create the object of a form. The form's name is passed from the calling place set obj = new p_sformname end sub Is it possible Thank you in advance Panal prasad

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          By your use of the Set statement, I take it your using VB6. VB6 can't do what you want. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups