[Gambas-user] SetFocus to next MaskBox in a Group

Tobias Boege taboege at ...626...
Thu Feb 12 14:12:06 CET 2015


On Thu, 12 Feb 2015, John Rose wrote:
> I have a set of MaskBoxes (each with Group Cyphered & with MaxLength of
> 1) with Names of CypheredMaskBox1, CypheredMaskBox2, CypheredMaskBox3
> etc. CypheredMaskBox1 has Tag of 1, CypheredMaskBox2 has Tag of 2 etc.
> In my Cyphered_Change event, I do validation of a user-entered character
> but want to SetFocus to the next (i.e. with Tag of 1 greater than
> current Tag) in case of successful validation. How do I do this (ideally
> by extending the code fragment below)?
> 
> Code fragment:
> Dim iNextTag As Integer
> Dim strNextTag As String
> Dim strNextCyphered As String
> iNextTag = CInt(Last.Tag) + 1
> strNextTag = CStr(iNextTag)
> strNextCyphered = "CypheredMaskBox" & strNextTag
> 

You can adapt this... I would almost call it a paradigma or a way of life:

  Private Sub Discover(h As Container)
    Dim g As Control
    For Each g In h
      Print g ' (*)
      If g Is Container Then Discover(g)
    Next
  End

It recursively discovers all controls on a form where at (*) you can do
whatever you want with a single control g, like checking whether it's a
MaskBox and what its Tag is.

Since you are searching MaskBoxes over an entire Form -- I assume; and this
assumption is critical here -- and have your MaskBoxes named nicely, you can
more comfortably use FForm.Controls (assuming your form's name is FForm):

  Dim hNextMaskBox As MaskBox

  ' your code fragment here
  hNextMaskBox = FForm.Controls[strNextCyphered]
  hNextMaskBox.SetFocus()

If you must constrain your search to a non-Form container, you must resort
to a variant of Discover(). If you additionally have embedded forms in the
container you want to discover, things will get a little uglier but no need
to discuss that if all you want is FForm.Controls.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list