Using ControlType(Control Name)

mozaharul

Active Member
Licensed User
Hi,
when using the following code to clean up controls on a Panel it runs on the desktop but gives the error attached when tried to compile for device :

B4X:
names() = GetControls("Panel2")      '-- check for missing info. in tab page Pg3
   For i = 0 To ArrayLen(names()) - 1
      If ControlType(names(i)) = "ComboBox" OR ControlType(names(i)) = "TextBox" Then 
         If (ControlType(names(i)) = "ComboBox" AND Control(names(i)).SelectedIndex < 0) OR (ControlType(names(i)) = "TextBox" AND Control(names(i)).text = "" Then) Then
            Msgbox ("Information missing on Pg 3","",cMsgboxOK,cMsgboxExclamation)
            tbc.SelectedIndex = 2
            Return
         End If
      End If
   Next

the error is attahced.

Please suggest the right code.

regards.
 

Attachments

  • ControlType.JPG
    28.7 KB · Views: 235

mjcoon

Well-Known Member
Licensed User
... it runs on the desktop but gives the error attached when tried to compile for device.

When you say "runs on the desktop" perhaps you mean running interpreted under the IDE, which is quite forgiving about syntax errors. If you compile for the desktop it may fail too.

Assuming you have quoted your source accurately, there is a syntax error at:
B4X:
Control(names(i)).text = "" Then) Then
with that spurious "Then".

Pity the error message is so distracting!

HTH, Mike.
 

mozaharul

Active Member
Licensed User
Hi,
Thanks for finding the silly mistake. But its same after dropping the spurious "Then".

regards,
 

mjcoon

Well-Known Member
Licensed User
Hi,
Thanks for finding the silly mistake. But its same after dropping the spurious "Then".

regards,

In that case I think you should take what the Help says about Control() more specifically, and use the appropriate type-name. E.g.
B4X:
If (ControlType(names(i)) = "ComboBox" AND ComboBox(names(i)).SelectedIndex < 0) OR ...

Potentially the use of the specific control type keyword "ComboBox()" allows checking that a permitted propertyfor that control type is being used. That is why there is a list of properties (not including SelectedIndex) which do not need the optional second argument in the (deprecated) Control(,) and, by implication, for the others it is not optional. So either try adding that 2nd argument, or use the alternative ComboBox() I suggest above.

Caveat: I have avoided using run-time control manipulation myself as far as I could!

Mike.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…