Web Control Array UBOUND

I have a page with over 30 fields. I have created a WebLabel array and I place it next to each field as an error indicator. Each one, since it is a control array, has a different index. It has RED ?? characters and I make them visible if that field has an error when you try to save the record.

I have a generalized function to turn on/off the label by passing an index number. I made the array start with element 1 so passing a zero will clear every control from 1 to n.

Is there an easy way to get the upper bound of the configured controls? I don’t like to “hard code” a value for the upper limit that has to be changed if I add a control.

Control sets are not arrays (hence the name “control set”), so there is no upper bound. You need to track the instances yourself.

To count them, you could loop through the controls until you get an exception.

Web Control Sets

You can add a property like Label1_Ubound and in the Label1 control set Open event :

if Index > Label1_Ubound then Label1_Ubound = Index

This won’t tell you if a member is missing, though, and ubound would be overestimated. It becomes your responsibility to reindex members if you remove one. That would be automatic in an array.

[quote=241440:@Paul Lefebvre]To count them, you could loop through the controls until you get an exception.

Web Control Sets[/quote]

If a member is missing the exception will occur before the last member is found.

True. I’ve now added a note to point that out.

Thanks for the info. I suspected it would simply be up to me to keep track. I probably won’t add new members very often but because of the nature of Event Driven Programming and the fact that logic is “scattered” in various methods/events I figured this would avoid having to remember.

You can get an array of all indexes and then call the right ones
the function is simple:

function getControlIndexes(name as text) as integer()
  dim o() as WebObject=ControlsWithName(name)
  dim indexs() as integer
  for i as integer=0 to o.Ubound
    if o(i).Parent=self then
      if o(i) isA WebContainer then
        indexs.Append WebContainer(o(i)).Index
      elseif o(i) isA WebControl then
        indexs.Append WebControl(o(i)).Index
      end if
    end if
  next
  Return indexs
end function

If that control (by name) doesn’t exist then the array will be empty
if that control is not in a set then the array will have one only item: -1
otherwise you will have all the control indexes.

Another way of proceeding if adding members dynamically, is to do it with an array.

Add a property myLabels() as WebLabel and when needed, go

myLabels.Append(New Label1) MyLabels(MyLabels.ubound).Left = MyLabels(MyLabels.ubound).Left+100// Whatever property needed

Then you have both a way to address each member, and an automatic UBound. Add the members already added in the IDE to have the exact count of members. If a member in the middle is removed, ubound is updated automatically.

[quote=241766:@Michel Bujardet]Another way of proceeding if adding members dynamically, is to do it with an array.

Add a property myLabels() as WebLabel and when needed, go

myLabels.Append(New Label1) MyLabels(MyLabels.ubound).Left = MyLabels(MyLabels.ubound).Left+100// Whatever property needed

Then you have both a way to address each member, and an automatic UBound. Add the members already added in the IDE to have the exact count of members. If a member in the middle is removed, ubound is updated automatically.[/quote]

Michael, would this method work with WebContainers? I copied and trying to add containers in the same way but not working as expected. I was just adding by doing new containrType and then embed within, but It seems to make dealing with the added containers a little sloppy. They are not in an or something with the embed method right?


The following doesn't show or seem to recognize my container
I have a property in container I want to embed within: additional_fields() As containerType

Then on click:
additional_fields.Append(new containerType)
additional_fields(additional_fields.ubound).Left = 40 
additional_fields(additional_fields.ubound).Top = top 
additional_fields(additional_fields.ubound).Width = 780 
additional_fields(additional_fields.ubound).Height = 130