Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Add Control In Form At Runtime - No Control Array


Hi Dear Programmers,

Some of you wanna know How to add a picturebox or textbox in a form at runtime. Here is two answer -

1. You can use control array. But in this way you must have at least one same control in your form to initialize the array (with index = 0) and you cannot unload any control that you placed in design time.

2. Another way is to use the control collection of the form you want to add a control at runtime. In this way you need not to use the control array - no need to place any instance of that control in design time. Even in this way - you can use the event of that control if yoy declare it with withevent keyword. This is done in following manner. Place the following code in a form. This code add a command button in runtime. )


'***************************
'Code Starts Here

Dim WithEvents cmd As CommandButton

Private Sub cmd_Click()
MsgBox "Hello"
End Sub

Private Sub Form_Load()
Set cmd = Me.Controls.Add("vb.commandbutton", "cmd")
cmd.Top = 1000
cmd.Left = 1000
cmd.Height = 400
cmd.Width = 1600
cmd.Caption = "EvelinDev"
cmd.Visible = True
End Sub

'Code Ends Here
'****************************


# The thing is that if you want to want to add a picturebox then inside the add method of control collection of a form - use vb.picturebox instead of vb.commandbutton.

You can use any kind of VisualBasic Intrinsic Control at runtime in this way.



Hasin Hayder
Lead Programmer
EvelinDev




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Add Control In Form At Runtime - No Control Array
Quote:Originally Posted by HasinHi Dear Programmers,

Some of you wanna know How to add a picturebox or textbox in a form at runtime. Here is two answer -

1. You can use control array. But in this way you must have at least one same control in your form to initialize the array (with index = 0) and you cannot unload any control that you placed in design time.

2. Another way is to use the control collection of the form you want to add a control at runtime. In this way you need not to use the control array - no need to place any instance of that control in design time. Even in this way - you can use the event of that control if yoy declare it with withevent keyword. This is done in following manner. Place the following code in a form. This code add a command button in runtime. )


'***************************
'Code Starts Here

Dim WithEvents cmd As CommandButton

Private Sub cmd_Click()
MsgBox "Hello"
End Sub

Private Sub Form_Load()
Set cmd = Me.Controls.Add("vb.commandbutton", "cmd")
cmd.Top = 1000
cmd.Left = 1000
cmd.Height = 400
cmd.Width = 1600
cmd.Caption = "EvelinDev"
cmd.Visible = True
End Sub

'Code Ends Here
'****************************


# The thing is that if you want to want to add a picturebox then inside the add method of control collection of a form - use vb.picturebox instead of vb.commandbutton.

You can use any kind of VisualBasic Intrinsic Control at runtime in this way.



Hasin Hayder
Lead Programmer
EvelinDev


How would I incorporate this code into a form where I don't want to use a command button to add a new label? What I want to do is when I update a sql table with a new record the form automatically adds two new labels in a row on the form reflecting the added information. Would I need to use sometype of Do while loop?

Here is the code I am using now that will not update the form:

Private Sub GetNew214Info()
' Get info from new Carrier214 table
'
Dim rsNew As ADODB.Recordset
Dim sSQL As String
Dim i As Integer
'
On Error GoTo GetNew214Info_Err
'
' Setup SQL statement
sSQL = "SELECT SCAC, Enabled, LastFeed, NumberFeeds " & _
"From CarrierTable " & _
"Where (Enabled = 1) " & _
"ORDER BY LastFeed DESC "

'
' Open Recordset
If Open_ADORS(cnShipStatDB, rsNew, sSQL) = True Then
'
' Check Record Count to inture there were records found
If rsNew.RecordCount > 0 Then


' Records found
'
rsNew.MoveFirst
i = 0

' Loop through records and insert information into form labels
Do While rsNew.EOF = False

'frmWatch.lblNewSCAC(i).Caption = rsNew.Fields("SCAC")
'frmWatch.lblLastEntry(i).Caption = rsNew.Fields("LastFeed")
'frmWatch.lblNumber(i).Caption = rsNew.Fields("NumberFeeds")

i = i + 1
rsNew.MoveNext

DoEvents
Loop

Else
' no records in RS
MsgBox "No records found in Recordset.", vbOKOnly
End If

' Close Recordset
Call Close_ADORS(rsNew)

End If
'
Exit Sub
'
GetNew214Info_Err:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
'
End Sub

Setting A Control's Container To A Member Of A Control Array At Runtime
Apologies for making two threads in the same day, but it's obviously just not my day. =

I'm trying to set the container of an ADODC to one of any number of frames in a control array. The array is named frmDataEntry, the ADODC is dbcShop. The code is as follows-
Code:
Set dbcShop.Container = frmDataEntry(0)
That's it. It will be used later with a variable for the index, but that's the essence of it. The problem I'm getting is that it's setting dbcShop.Container to frmDataEntry(0).Caption instead of just frmDataEntry(0) as a Frame. I tried making a bridge variable, doing
Code:
Dim frmContain as Frame
Set frmContain = frmDataEntry(0)
Set dbcShop.Container = frmContain
But I get the same problem. Any suggestions? From what I know I'm trying the right approach, but I may be overlooking something.

Ad Control Array At Runtime
I need to get controls at runtime in my project. Just some picturboxes, buth they have to be in a array. I use these pictureboxes for drag and drop on a form. Sofar...so good.

I can get 1 picturebox on the form with the controls.Add and i can even get picture2 to IFUCANCOUNTLETMEKNOW. buth i want a controll-array.

Otherwise i have to do a million picture1 through pictureIFUCANCOUNTLETMEKNOW_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

This is my source code sofar....can anybody help me out please???

Set Picture1 = frmDoc.Controls.Add("VB.PictureBox", "Picture1")

With Picture1
.DragMode = 0
.Visible = True
.BorderStyle = 0
.Left = 120
.Top = 240
.AutoSize = True
.Picture = LoadPicture(App.Path & "myPic.jpg")

End With

Runtime Control Array
I'm using VB6 and want to create a set of text boxes dynamically at run-time. I've looked at the "controls.add" method, and I've dug through the help references on control arrays until I'm blue in the face and I've tried everything I can think of. For FORMS, I have no trouble creating dynamic arrays at runtime, but for TextBoxs I just can't get anything to work. Suggestions?

Thanks for your time.

Runtime Control Array
I am dyamically filling a frame with textboxs on a tabstrip based on a file which indicates #rows and #columns and #Pages. A page will be a tab. If I have 6 rows and 3 colums and 3 pagesI will create 18 textboxes on each frame1(x). This is working for texbox1(1)-(18). I need to continue the control array for #pages ie. text1(19)-text1(36) on frame1(2) then text1(37) - text1(54) on frame(3). I am unable to continue the textbox control array onto the other frames.

Thank you,

Brandon

How To Re-size A Control-array At Runtime?
trying to resize a control-array at runtime, could use some help. when i say resize i mean more instances of it, not the actual size of the control.

Control Array Runtime Problems.
Hi guys ! (and girls of course).

My problem is that I have a control Array (ListView) and if I unload my form and then, reload it I have the "Element x does not exists".

This bug seems to appear randomly. Sometimes, it works just fine, and some other, it pops the error. I do not try to access my controls before the Form_Activate event.

Does anyone have encounter the problem before ? And is there any solutions that you can think of ?


Thanks a lot !


Ultraman

Deleting From A Control Array At Runtime
I have a control array of images that I can add to at runtime. I am trying to get the delete button to get rid of the selected control.

Is there a way to actually delete an object? Right now I am just setting the object to nothing, and decrementing the index. When I try and add another image, using the same index as the one that was deleted, I get an error saying the image has already been loaded. No doubt it is because the object is still on the form but is not visible.

So is there a way I can actually delete the object from the form at runtime?

I can't find anything in the VB books I have or on this site. Can I suggest a FAQ on control arrays (ie. adding deleting objects at design and run time, etc..)

Phil

Create Control Array At Runtime
Hy,
Has anybody an Idea how its possible to create a Control Array at Runtime.
For example i want create a Frame as "Parent" and a Button on it as "Child", and all this at Runtime.
Thank you for your help.
Bye

Create Controlers On Runtime In Control Array.
so i do know how to create controls but i dont know how to creat them as one
control array

here is mycode:
Z = varibal in while.
W() = array that contain varibals from the start
L() = array that contain varibals from the start


Code:
Dim Picutrebox As PictureBox

Me.ScaleMode = vbPixels

Set PictureBox = Me.Controls.Add("VB.Picturebox", "Picturebox" & z)
Set PictureBox.Container = Frame3
With PictureBox

.Left = 1080 + 255 * z
.Top = 5040
.Width = W(z) * 2
.Height = L(z) * 2
.Visible = True
.Appearance = 0
.BackColor = &H80000003
End With

Control Array, Adding New Elements At Runtime.
I assume this is posible but I can't seem to figure out how you add new objects to a control array at runtime.

What I'm trying to do is have a control array of PictureBoxes but I want to have an unlimited amoun tof them. I have the code for positioning them and everything all I need to do is create more of them as the user needs them.

Can anyone give me a hand please

Declaring A Label Control Array At Runtime.
The problem I have is that I want to add 25 labels to a form, and I want to do that using only code and declaring a control array. Can this be done? If so How? I have declared an array called Label(24) but when I use the For Next loop to assign values to the array, the SET statement is nested in the For Next loop, but there is always an error whenever I try to execute the statement.

The SET statement looks like this:

Set Label(intCounter) = Form1.Controls.Add("Label", "lblDynamic" & intCounter)

and the error issued is:

Run-time error '711':

Invalid class string.
Looking for object with ProgID: Label

Furthermore there is no help topic associated with the error in MSDN so I am stuck. I will be very grateful if you can tell me how to declare and add 25 Labels using a control array, during runtime.

Thank you in advance.

Creating Textbox Control Array At Runtime
How to make a textbox array at Runtime ?
ie, I want to make some textboxes in arrays (say txtNAME(i) )

I tried this method

Set txtNAME1 = Controls.Add("VB.textbox", "txtNAME1"), it works.

But when I give

FOR I = 1 TO 10
Set txtNAME(i) = Controls.Add("VB.textbox", "txtno(i)")
NEXT

It gives “Not a legal object Name” error message

Anyone with a helping hand ?
Thanks in advance

Add Event To Control Array Created At Runtime
Hello everyone,

I've created a form with multiple buttons created at runtime.  I cannot seem to attach events to the buttons as they are in a control array.  Any ideas?
CODEOption Explicit
Const btnSize = 225
Const spacer = 100

Private Sub btn_Click(Index As Integer)
    'only works with button I've created pre runtime
    MsgBox (Index)
End Sub

Private Sub cb0_click()
    MsgBox ("doesn't work")
End Sub

Private Sub Form_Load()
    Dim x As Integer
    Dim y As Integer
    Dim rowTop As Integer
    Dim colLeft As Integer
    Dim btnNum As Integer
    Dim rowNum As Integer
    Dim colNum As Integer
    Dim btnTop As Integer
    Dim btnLeft As Integer
    Dim frameNum As Integer
    
    Dim btn(728) As Control
    
    frameNum = -1
    rowTop = 200
    colLeft = 50
    rowNum = 0
    colNum = 0
    
    For y = 0 To 728
        If y Mod 81 = 0 Then
            frameNum = frameNum + 1
            rowNum = 0
            colNum = 0
        End If
        
        If y Mod 27 = 0 Then
            'whole new column
            colNum = colNum + 1
            rowNum = 1
            btnNum = 1
            btnTop = rowTop
            btnLeft = spacer + (colNum - 1) * ((btnSize * 3) + spacer)
        ElseIf y Mod 9 = 0 Then
            'new set of numbers
            btnNum = 1
            rowNum = rowNum + 1
            btnTop = btnTop + btnSize + 50
            btnLeft = spacer + (colNum - 1) * ((btnSize * 3) + spacer)
        ElseIf y Mod 3 = 0 Then
            'same numbers down 1 btnSize
            btnTop = btnTop + btnSize
            btnLeft = spacer + (colNum - 1) * ((btnSize * 3) + spacer)
        Else
            'just move over 1 btnSize
            btnLeft = btnLeft + btnSize
        End If
        
        Set btn(y) = Form1.Controls.Add("VB.commandButton", "cb" & y, Frame1(frameNum))
        With btn(y)
            .Visible = True
            .Height = btnSize
            .Width = btnSize
            .Top = btnTop
            .Left = btnLeft
            .Caption = btnNum
        End With
        btnNum = btnNum + 1
    Next
End Sub

How Do I Unload An Item From A Control Array Of Pictures At Runtime?
Me again,

I can create my control array at runtime... how do I remove items from it now?

How To Handle Events For Control Array Generated On Runtime In VB.NET?
Hello!

Does anyone can help me by telling that how can I I handle an event for array of controls which generates on runtime in VB.Net. I am using withevents but it works only for one instance of control, not for array.

Thank You!

Regards,

Muhammad Khan.

Reaaranging/tracking The Deletion Of Elements In Control Array At Runtime????
hi,
need some help!!!!

i want 2 make a popup menu to add & remove labels(with specific names) dynamically.the labels form part of a control array.i can add labels but when deleting them,

a) is there a way to reassign the index of the elements of the array., ie, if i delete element 7 in a array of 1-10, i shud b able 2 reassign the elements 8,9,10(before deletion) as elements 7,8,9 after deletion.

b) if above isnt possible i will need 2 keep track of the indices of the elements of the array that i have deleted,

thanks

Add A Control To A Form During Runtime
I need to add a control to a form I call for a specific event.

I want to add a CheckBox control to the form... I need to know how to position it as well.

vbMarkO

Adding A Control To A Form At Runtime
How do I do that?
"Adding a control to a form at runtime"

I don't wish to use the visible property.

Adding Control To A Form At Runtime
How do I do this:
"Adding control to a form at runtime".

I don't wish to use the visible property.

Resizing A Control In Form At Runtime With Mouse - ????
I would like to resize the controls in a form by dragging the mouse at runtime.
Glad to receive the suggestions in this regard.

Resizing A Control In Form At Runtime With Mouse - ????
Rpgnewbie,
Thanks for the great code .. It helped me alot and it's better than many code posted on the net abut this issue (espaecially the part that only the surrounding shape "shpRect" moves with mouse until it's released, This remove the flikering problem)

Thanks again,
Ayman

Creating A WebBrowser Control In Form At Runtime
Hi guys,

I have a help screen that uses the webbrowser control to display help.
The problem is that each time the user opens the help, the pages previously viewed can accessed by pressing the back button.

What I would like to do is open the browser each time with no history.

I tried the solution posted by Joacim Andersson a couple years ago. All it seemed to do for me is reset the URL Visited flag. It didn't clear the history stack.

Code:
1. Dim History As UrlHistory
2. Set History = New UrlHistory
3. History.ClearHistory


So I've decided that maybe I could create the browser control at runtime, and destruct it when the user is finished. But I don't know how to do this. Can anyone please help with a code snippet?

Cheers,
Nap

Form As Control Array
i noticed that the form object does not contain an index property. does this mean i cant create a form as a control array at runtime?

Form Control Array
can u create a control array using a form
i need to load forms that dont exist can i do that..

i know how to do it say with buttons

Adding An Intrinsic Control To A Control That Was Added Dynamically At Runtime
Hello,
     I need some expertise. I am creating an application in Visual Basic 6.0 Sp6 that creates an SSTab control dynamically at runtime based upon parameters in another form. All this works fine but the problem that I cannot solve is how to add a Label control to each Tab in the SSTab control after the SSTab control has been added with the appropriate number of tabs. I am not even sure this is possible or do you have another suggestion. I tried playing around with the container for the SSTab but had no luck. Thanks to anyone who can help and to whomever put this website together.

Here is the code to add the Active X control(I created) to the form but I am not sure how to add a label to each tab on the SSTab control.
-------------------------------------------------------------------------------------------------------

Public TabbedPane As Project1.Tabbed 'name of SSTab ActiveX control

Public Sub Form_Load()
Set TabbedPane = Controls.Add("Project1.Tabbed", "mytest", MBs_to_be_tested)
TabbedPane.Visible = True
TabbedPane.Tabs = Module1.Number_of_MBs
Dim Index As Integer
Index = 0

If Module1.Number_of_MBs > 5 Then
   TabbedPane.TabsPerRow = 5
Else
   TabbedPane.TabsPerRow = Module1.Number_of_MBs
End If

If TabbedPane.Tabs = 1 Then
   TabbedPane.TabMaxWidth = 16375
End If

TabbedPane.TabHeight = 250
TabbedPane.TabMaxWidth = MBs_to_be_tested.Width / 5
TabbedPane.Width = MBs_to_be_tested.Width

Do
   TabbedPane.TabCaption(Index) = Module1.PointType(Index)
   Index = Index + 1
   MsgBox "Index" & TabbedPane.TabIndex
Loop While Index <> Module1.Number_of_MBs

End Sub





Edited by - dave_zr2 on 2/21/2006 5:47:23 PM

ASP.NET: How Can You Create A Control Array On A Web Form?
I have created a User Control (.ascx file) and want to add it to a Web Form (.aspx file). However, the user control represents records and it should be repeated for each of the records. The number of records can be different every time.

How can I do this? Is it even possible?

Control Array On Tabbed Form
Hi

I am attempting to place multiple option buttons on a form with multiple tabs. When I reach a certain number of option buttons, I get a message saying unable to add any more objects to form.

Is the best way around this to create a control array?


Thanks

Kelly

Add A Button To Form -not With Control Array
I have to add a command button to a form in from activate or click
But there is no control on the form in design mode ..
And i dont want to add a control array.
I think this should be in VBA. Pls let me know..
------------------------------------------------------------
One more question to u all .. ( i assume most of u will also know ASP)
In ASP how do we handle error .. In VB we can give OnError resume next or goto aa: .. etc
But that is not possible in asp
I get a error : EOF or BOF or Record missing when i do
rs.movefirst
AS there is know record in the recordset
How do i trap that
------------------------------------------------------------
Thanks to all.. who spent time for me reading this

Viswanath
vichu000@yahoo.com

How To Add A Control Array To A Form By Vb Language?
now i am doing one project about vb. i got one problem. How to add a control array to a form by vb language? is it possible? becoz the number of controls i add is a variable, it depends on users. Moreover, one item of that control array also consists of two controls.
who can give me some ideas? thanks a lot.

How Do I Acces Control At Runtime From A Specific TAB Of SSTab Control
I have multiple grid or button control in SSTab. suppose grida1 is in tab 1 and grid2 is in tab 2. Now runtime if I want to access tabwise control from SSTab how do I do that..? Because all controls are treating as form level control.
Remember all control I have added at design time so I cant make it as tab container, it's default form container. how do I access tab no wise control from SSTab at runtime. Anybody can help.

Shibobrota Acharya
shibocal@yahoo.co.in
Calcutta

Call A Control's Method From A Form Launched By The Control's Control? (???)
I've placed control A on an active x control. I have a command button that launches form B. From form B I want to call one of control A's methods. I'm gettting an error stating 'Object variable or With blokc not set'. Can anyone tell me how/if I can access this object from this point in the code? I looked at Friend but that didn't seem to solve my problem. Any help would be appreciated.

Control Array, Setfocus, Form Load
I'm trying to setFocus to a control array indexed by 0 in the form load event, but the vb6 keeps erroring me out. does anyone know why?


Code:
Option Explicit


Private Sub Form_Load()

'center the form
frmImages.Top = (Screen.Height - frmImages.Height) / 2
'calculate half way from top
frmImages.Left = (Screen.Width - frmImages.Width) / 2
'calculate half way from bottom
optElement(0).SetFocus

End Sub
i have a control array declared as optElement.

WithEvents As Array - Workaround? (not A Form Control)
Hello,

I declared an (Outlook) Object WithEvents so I can start certain action whenever an Events is raised (by outlook).

I would like to have couple of such events all set to other object instances.

How can I achieve this in a more elegant way then to declare every variable explicit because one can't use WithEvents with Arays.

I've seen some solutions concerning control array or initializing the event myself but since the event is raised by another application (outlook) these don't look that helpful.

Thank you for your input in advance,

Mat.

Using Control Array To Populate Form Labels
I am a visual basic beginner and having problems understanding controlled arrays. I need to update a form when a sql table is updated. The problem I am having is that when the table is updated an error message is returned. I am using labels to display the table information.
I have attached the code. I would appreciate any help.
Right now in the dowhile statement I have code for both a list box and the current statements I am using. I'm assuming that is where the array needs to be included.

Private Sub GetNew214Info()
' Get info from new Carrier214 table
'
Dim rsNew As ADODB.Recordset
Dim sSQL As String
Dim i As Integer
'
On Error GoTo GetNew214Info_Err
'
' Setup SQL statement
sSQL = "SELECT SCAC, Enabled, LastFeed " & _
"From CarrierTable " & _
"Where (Enabled = 1) " & _
"ORDER BY LastFeed DESC "

'
' Open Recordset
If Open_ADORS(cnShipStatDB, rsNew, sSQL) = True Then
'
' Check Record Count to inture there were records found
If rsNew.RecordCount > 0 Then
' Records found
'
rsNew.MoveFirst
i = 0

' Loop through records and insert information into form labels
Do While rsNew.EOF = False

frmWatch.lblNewSCAC(i).Caption = rsNew.Fields("SCAC")
frmWatch.lblLastEntry(i).Caption = rsNew.Fields("LastFeed")
frmWatch.lstListBox.AddItem (rsNew.Fields("SCAC") & vbTab & rsNew.Fields("LastFeed"))

i = i + 1
rsNew.MoveNext

DoEvents
Loop

Else
' no records in RS
MsgBox "No records found in Recordset.", vbOKOnly
End If

' Close Recordset
Call Close_ADORS(rsNew)

End If
'
Exit Sub

Passing Form And Control Array Names
Hi I have a sub in a module file that flips the enabled state of an array of buttons:

Code:
Sub ToggleButtonState(ByVal buttonState As Boolean, ParamArray ButtonIndexes() As Variant)

Dim varIndex As Variant
..For Each varIndex In ButtonIndexes
......MAIN_FORM.Command1(varIndex).Enabled = buttonState
..Next
End Sub


this works just fine, but I am trying to make it more generic by passing the target form name and the target control array name:

Code:
Sub ToggleButtonState(formName As Form, arrayName As Variant, ByVal buttonState As Boolean, ParamArray ButtonIndexes() As Variant)

Dim varIndex As Variant
..For Each varIndex In ButtonIndexes
......formName.arrayName(varIndex).Enabled = buttonState
..Next
End Sub


have got various errors with this, unmatching data types, object does nto supporrt property or method etc. have tried passing arrayName as control or command or variant, none seem to work.

Anyone have any ideas? much appreciated

How To Add Array Control To Blank Form At Run Time
'I use this code to add control to blank form
Private Sub Form_Load()
Dim Txt1 As TextBox
Dim Txt2 As TextBox
Dim Txt3 As TextBox
Set Txt1 = Form1.Controls.Add("vb.textbox", "mytext1")
Set Txt2 = Form1.Controls.Add("vb.textbox", "mytext2")
Set Txt3 = Form1.Controls.Add("vb.textbox", "mytext3")
Txt1.Visible = True
Txt1.Left = 100
Txt2.Visible = True
Txt2.Left = 1300
Txt3.Visible = True
Txt3.Left = 2500
End Sub

But if I want to add array control to blank form at run time
How can I do that ?
Thanks in advances.
Tommy

Unloading Control Array Objects During A Form Resize
You really don't want to know why I want to know how to do this... but,

I need to unload a lot of labels from a control array upon form resize. The alternative is to get into a horrible situation making them visible or invisible and updating lots of information in them. There's also a scroll bar that I can see is just waiting to foul things up if I take this route.

Any way that I can fire off an event from the form resize after I've exited it?

-Thanks.

Control Array Object From Form Controls Collection?
How can I access a control array object as an item on a form, vs. explicitly by name?

e.g. I have a TextBox "Text1", with index=0 on a form (that's it)
but the following code fails with Error 344, "Must specify index for object array"


Code:
Dim xx As Object

For Each xx In Me.Controls
Load xx(1)
Next xx



FWIW
Load Text1(1) works fine.
? TypeName(Text1) = Object
? TypeName(xx) = TextBox

Apparently, in the For Each loop it's giving me actual instances of the textbox control, rather than the control array itself.

Thanks, DaveBo

Adding A Control Array To The Form.Controls Collection
Does anyone know how to add a control Array of text boxes or labels to the Form.Controls Collection. I need this so I can generate an entry form from a script held in a database.

Adding A New Element To An Existing Index Control Array That Is On A Form
Hello all,

I would like to know if there is a way of adding a new element to an existing control index? For example, I have place a Picture Box control on a form with the given name of "pbDynamicIndex" and give this one picture box an index of 0. Then during run time I would like to add another picture box dynamicly to this index. How would I do this? I know you can add control dynamically during run time by making an array of that control type then using the Controls.Add("VB.PictureBox", "pbRadioBtn") to populate the array, but I was trying to add additional control to an already existing "control index array" ( is that what you call them?? ). I don't want to create a whole bunch of the controls then either make them invisible or visible. I can do this easily, but the code needs to demostrate how to add control at run time. Thanks for any help.

Mark

Adjusting Control Array Index Value At Run-Time Once The Control Is Loaded/ Created
Hi All

I am attempting to adjust the index value of one or more control array items. Basically whats happening is one of the controls within the array is being unloaded however the array numbers of items above this are remaining the same and therefore there is a gap within the numbering system. How do I get the index number of every item above the unloaded control reduced by one. I get a read only error however in MSDN it say it can be returned or set.

Thanks for any points on this.

Rusty



Edited by - Rusytness on 7/17/2002 11:44:23 AM

How Can I Make A Control, A Control Array And Upon Request Revert It Back?
VB Version : 6
Hello!I am using the Web browser control in my application.Until now I have not set it an index (at design time) because only an instance of it was needed. Now that I want more instances of the same object I am planning to achieve it by dynamically making it a control array.The problem is that all the related subroutines are referred to the "brwWebBrowser" and not in the "brwWebBrowser(currentIndex)".
So now I cannot go to the design and set the index to wharever.While the Webbrowser control does not conform/apply to any kind of indexing,can I transform it at runtime to be a control array and revert it back to normal?
Something like:

Code:
If chekBox=1 then
'make it a control array
brwWebBrowser.index = 0
else
If chekBox=1 then
'revert to normal (forget all about control arrays)
brwWebBrowser.index=null
end if
end if
Is the below possible?If it is,can I move the last brwWebBrowser (e.g brwWebBrowser (7)) contents into the new one?
Thanks in advance!

Got To Find Other Way To Check If Control In Control-array Is Exist
hello every one ive been asking this question tow days ago
thank you for helping me on the last time ...everyone suggest to trap
the error
it was fine and nice back then
now the trap is braking my code =
its 4 if's in a while
if ther is one control array missing its stops the while
and the function dosent work =
any suggestion to have other way to check if control array exists?

How To Determine If A Control Is Part Of A Control Array In A For Each Loop
When iterating thru the controls on a form using a For Each loop, is there a way I tell if the current control is part of a control array? For example:

vb Code:
Dim c As ControlFor Each c In Me.Controls    If "c is part of a control array" Then       Select Case c.Index            Case 1                c.Text = "A"            Case 2                c.Text = "B"              'etc.        End Select    Else         ' whatever    End IfNext

Instantiating A Copy Of A Designed Control Without Using Control Array
I am a C++ programmer having difficulty getting into VB, here's thespecific problem I have at present, I'd be grateful if any one can help

1. I wanted to instantiate another control like one of my controlscreated
at design time, but I don't want to use a control array, whichincidentally
doesn't seem just like any other array, and I come up with MSDN page
'Invalid use of New keyword', so I read that and see that I must use the
object name not the class and it suggests this code:

' Valid syntax to create the variable.
Dim MyListBox As ListBox
Dim MyFormInst As Form

' Valid syntax to create new instance of a form or list box.
Set MyFormInst = New Form1
Set MyListBox = New List1

Presumably List1 is the name of my ListBox on the form, so I put onenamed
like that on the form and I put this code in a button click eventprocedure,
but it doesn't like List1 and now it says it should be a type (class?),I
think may be this List1 object needs to be an independant global ListBox
object, but then I'm back to how do I instantiate one when I can't usethe
class name? Am I making sense, I'm probably just too C++ focused.

2. Are there any sites/tutorials for C++ OO purists like myself whoneed to use VB
and want to get their head round how these aspects of it really work?

Creating Control Array Of A Run Time Created Control
Problem
********
In VB 6 we can create control at run time. How to make control array of that
control(created run time)...???
Is it feasible in VB 6 or not b'use I won't able to find anything in MSDN.
Programatically can we do something??

Detail
********
To paste a control on form and make control array of that at run time is
the normal process of making control arrays.
My question is to create a control(e.g command button) at run time(VB 6
new feature) like
------------------
Form1.Controls.Add "VB.CommandButton", "cmdObj1"
------------------
then make a control array of it. Now how to make that control array??

More specifically how to assign index to control at run time for making
control array b'use index is read only property at run time.

I am just wondering if VB 6 provides run time control, logically it should
provide control array on that also. If not available readymade through VB 6,
may be through programming.

Let me know if anybody has some idea on this.
Thanks for your time guys.

Determine If A Control Is Part Of Control Array
Hiya

What I want to do is find out if a control is part of a control array without calling "mycontrol.index" and handling the "it's not an array, you idiot" error.

Instead I'd like a function like this:


Code:
If IsPartOfControlArray(MyControl) then...

If it's ridiculously complicated, I'll use the error handling method - I'm not that proud!

Thanks

Joolz

P.S. I know there's been some quite long threads in the past on determining whether a particular member of a control array exists without using error handling, but there didn't seem to be any firm conclusions. Anyway, I think this is a slightly different question.

Copyright © 2005-08 www.BigResource.com, All rights reserved