954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB6 create form

I need to create a form using code.

Is there a way to do this.

like in the code i need to create a form with a name, caption and text box in it.

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

u can get idea from the attach file.

Attachments Create_control_in_runtime.zip (2.07KB)
abu taher
Practically a Posting Shark
845 posts since Jul 2008
Reputation Points: 14
Solved Threads: 78
 

ye thanks that will come in handy

but i need to make a form like form1 or form2

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 
dim f1 as new form
dim f2 as new Form1  'u must have this form in project

f1.show
f2.show
omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

try this

Dim f1 As New Form1

  '  Dim f2 As New Form1 'u must have this form in project
    

      
Private Sub Command1_Click()
f1.Show
    '  f2.Show
End Sub
abu taher
Practically a Posting Shark
845 posts since Jul 2008
Reputation Points: 14
Solved Threads: 78
 

this is great

But i need something like this:

Private Sub menuName_Click()
Dim f1 As String
f1 = Int(100000 * rnd() + 1)
Dim f1 As New frm_New
f1.Show
End Sub
drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This was discussed before. Please refer to the link below which will explain quite a lot about your question as well as more links to follow. http://www.daniweb.com/forums/thread96518.html

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

sorry thats not helping ether

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Try the following. Is this what you required help on?

Option Explicit

Private newCtrl As Control


Private Sub menuName_Click()

Dim frmNew As New Form1
With frmNew
    .Show
    .Caption = "My New Form"
    .menuName.Visible = False 'You only want one instance of a form
End With

Set newCtrl = Form1.Controls.Add("vb.textbox", "txtTextBox", Form1)

newCtrl.Visible = True
newCtrl.Move 2000, 500, 1500, 250 'Change placement to whatever you need

menuName.Visible = False 'You only want one instance of a form
Call txtBoxName(Form1) 'Add random number to textbox
End Sub

Private Sub txtBoxName(frm As Form)

Dim strCount As String
Dim Control As Control

strCount = Int(100000 * Rnd() + 1)

 For Each Control In frm.Controls
        If TypeOf Control Is TextBox Then
            Control.Text = strCount
        End If
       
    Next Control
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

yes and no

yes i need to make a form like that(but i already have the form made).

no i want multiple of the forms open

ill post all my code and what im doing.

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Ok, so you need more than one form with one textbox added to each form, but you get an error that the textbox already exists?

How many textboxes do you need on each form and how many forms do you need to create?

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

I'm making a text editor like notepad but better because i'm using an mdiform so you can have multiple files open at once.

This is the code i got.

MDIForm:

Private Sub menuAbout_Click()
frm_About.Show
End Sub

Private Sub menuName_Click()
frm_New.Show
End Sub

Private Sub menuOpen_Click()
frm_open.Show
End Sub

Private Sub menuSave_Click()

' loads save as box
    MDIForm1.CommonDialog1.ShowSave
    On Error GoTo error
    filelocation = MDIForm1.CommonDialog1.FileName
    Me.ActiveForm.Caption = MDIForm1.CommonDialog1.FileTitle
' append saves over file if it assists
    Open filelocation For Output As #1
    Close #1
    Open filelocation For Append As #1
        Print #1, Me.ActiveForm.Text1.Text
    Close #1
GoTo endload
    
error:
errorreport (0)

endload:
End Sub

Function errorreport(error)
Dim intResponse As Integer
intResponse = MsgBox("There was an Error wile trying to load", vbExclamation, "Quit")
End Function


frm_open:

Private Sub Form_Load()
MDIForm1.CommonDialog1.ShowOpen
Me.Caption = MDIForm1.CommonDialog1.FileTitle
FileName = MDIForm1.CommonDialog1.FileName
On Error GoTo error

Open FileName For Input As #1
    
Do Until EOF(1)

        Input #1, Data
        Me.Text1.Text = Me.Text1.Text + Data + vbCrLf
    EOF (1)
    Loop
    Close #1
    FileName = ""
GoTo endload
    
error:
errorreport (0)

endload:
End Sub
Function errorreport(error)
Dim intResponse As Integer
intResponse = MsgBox("There was an Error wile trying to load", vbExclamation, "Quit")
End Function

Private Sub Form_Resize()
Text1.Height = Me.ScaleHeight
Text1.Width = Me.ScaleWidth
End Sub


frm_new:

Private Sub Form_Load()
Me.Caption = "text.txt"
End Sub

Private Sub Form_Resize()
Text1.Height = Me.ScaleHeight
Text1.Width = Me.ScaleWidth
End Sub


I've also got an about form but i don't think you need that.

So i need one text box on each form and up to 100 forms or so open at once (ill make a new version if someone needs more than that open at once).

If you want some screen shots just ask.

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

say me what do u want to do for creating form by code.
maybe ur way is wrong!

omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

it properly is i only just started teaching myself this year.
But how else am i going to do it

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

u must create form template and create new from from this
like form2
dim a as new form2
form2.show

omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

i have a template

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

ok
so use this
dim f as new yourtemplateformname

then
f.show

or change any prop
like f.tag
f.picture
,....

omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

thanks i was wrong about it not working

sorry for wasting your time if.

thanks everyone
thanks so so mutch

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

check my sample
if you want create window on the fly you must use window api like
createwindowex,....

thanks i was wrong about it not working

sorry for wasting your time if.

thanks everyone thanks so so mutch

Attachments FormNew.zip (1.75KB)
omoridi
Junior Poster in Training
72 posts since Sep 2009
Reputation Points: 10
Solved Threads: 10
 

thanks ill look at that

drabsch
Light Poster
36 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: