Author Topic: @Qwerkey: What about NumericTextBoxes?  (Read 14671 times)

0 Members and 1 Guest are viewing this topic.

FellippeHeitor

  • Guest
@Qwerkey: What about NumericTextBoxes?
« on: August 31, 2018, 10:27:26 am »
So, after creating the array of controls (tedious, but now done), the first bit of code transforms as follows:

From:
[code.../]

To:
Code: QB64: [Select]
  1.                 IF VAL(Text(HowManyBodiesTB)) >= 2 AND VAL(Text(HowManyBodiesTB)) <= 11 THEN
  2.                     Control(BodyDataFR).Disabled = False
  3.                     Control(BodyDataFR).Hidden = False
  4.                     SetFocus BodyMass1TB
  5.                     Index% = VAL(Text(HowManyBodiesTB))
  6.                     FOR M% = 3 TO 11
  7.                         IF Index% < M% THEN
  8.                             FOR K% = 8 * M% - 7 TO 8 * M%
  9.                                 Control(TheQwerkey(K%)).Disabled = True
  10.                                 Control(TheQwerkey(K%)).Hidden = True
  11.                             NEXT K%
  12.                         ELSE
  13.                             FOR K% = 8 * M% - 7 TO 8 * M%
  14.                                 Control(TheQwerkey(K%)).Disabled = False
  15.                                 Control(TheQwerkey(K%)).Hidden = False
  16.                             NEXT K%
  17.                         END IF
  18.                     NEXT M%
  19.                 ELSE
  20.                     AA& = MessageBox("Value From 2 to 11 Required", "", 0)
  21.                 END IF

Very streamlined, Richard!

BTW: I see you're validating input between 2 and 11. Have you considered turning this TextBox into a NumericOnlyTextBox? At design time they're two different controls:

Captura de Tela 2018-08-31 às 11.56.05.png

...but internally it's just a TextBox with a special property set. Somewhere in __UI_OnLoad add this:

Code: QB64: [Select]
  1. Control(HowManyBodiesTB).NumericOnly = __UI_NumericWithBounds
  2. Control(HowManyBodiesTB).Min = 2
  3. Control(HowManyBodiesTB).Max = 11

Then you can also access its numeric value directly with Control(HowManyBodiesTB).Value.
« Last Edit: August 31, 2018, 10:56:32 am by FellippeHeitor »

Marked as best answer by on April 11, 2024, 04:33:16 pm

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: @Qwerkey: What about NumericTextBoxes?
« Reply #1 on: August 31, 2018, 11:06:18 am »
  • Undo Best Answer
  • Have you considered turning this TextBox into a NumericOnlyTextBox?

    Er, no.  The InForm student was too stupid to know that this can be done.  When you've convinced Terry Ritchie* to create a full on-line Tutorial for InForm, this student will be the class dunce.  In the meantime, I'll look into what you've recommended here, thank you - I have lots of textboxes which have upper & lower limits.  I get more & more amazed with InForm: you seem to have thought of everything.

    * He's very good at tutorials, as we know.

    Richard

    Offline Qwerkey

    • Forum Resident
    • Posts: 755
    Re: @Qwerkey: What about NumericTextBoxes?
    « Reply #2 on: August 31, 2018, 11:16:53 am »
    ... Most of my inputs are celestial quantities, requiring exponentiation.  Numeric-only doesn't allow this, unfortunately.  Richard