Author Topic: Mastering InForm: control arrays?  (Read 23433 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Mastering InForm: control arrays?
« on: August 20, 2018, 09:56:39 am »
Fellippe, another request (so simple to implement, I have no doubt) from your user:

See attached image of part of the Gravitational Simulation program (NB Positions on screen are not yet set).  The program will allow the user to input the starting masses, positions (x-,y-,z-) and velocities (x-,y-,z-) of up to 11 bodies (why 11 bodies, not quite sure - that's what I have used in the previous non-Inform version of the program).  This means that there are 77 controls, individually labelled and each of which has to have code to check input and move on.  I've only started the coding of the first seven and the number of program lines is becoming substantial.

In Visual Basic, they had Control Arrays which could be named with subscripts, and this makes coding very much easier.  (They removed Control Arrays in Visual Studio - that ghastly programming tool).  So, when will Control Arrays be coming?!!!

Richard
Array of Controls.jpg
* Array of Controls.jpg (Filesize: 91.38 KB, Dimensions: 981x828, Views: 558)
« Last Edit: August 24, 2018, 10:49:31 am by odin »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mastering InForm
« Reply #1 on: August 22, 2018, 08:27:42 am »
Fellippe, another request (so simple to implement, I have no doubt) from your user:

See attached image of part of the Gravitational Simulation program (NB Positions on screen are not yet set).  The program will allow the user to input the starting masses, positions (x-,y-,z-) and velocities (x-,y-,z-) of up to 11 bodies (why 11 bodies, not quite sure - that's what I have used in the previous non-Inform version of the program).  This means that there are 77 controls, individually labelled and each of which has to have code to check input and move on.  I've only started the coding of the first seven and the number of program lines is becoming substantial.

In Visual Basic, they had Control Arrays which could be named with subscripts, and this makes coding very much easier.  (They removed Control Arrays in Visual Studio - that ghastly programming tool).  So, when will Control Arrays be coming?!!!

Richard

You could put the 77 items in a list box, select the item to edit have that item load in an text box with two buttons one to change and one to cancel edit. They could be listed as key = value lines and you could label the text box with the key name.

Control arrays were cool!

PS You could put a whole line of data as one list item, then when selected, edit the whole line using a space or comma to seperate the numbers. This would make the List Box listing look like an 2D array.
« Last Edit: August 22, 2018, 09:11:23 am by bplus »

FellippeHeitor

  • Guest
Re: Mastering InForm
« Reply #2 on: August 22, 2018, 10:15:09 am »
Sorry for the absence in this topic.

Control arrays have been considered in the past but for some reason I can't recall at the moment they were later scraped. If I can't remember what made me give up on them, I may reconsider adding them sometime in the future.

For now, what I have done when I needed to manipulate my controls with an array was to create it manually. Tedious, I know, but it has saved work later.

You'd DIM SHARED MyControlArray(totalControls) AS LONG (control IDs are stored as LONG) and then you'd assign each index in that array to the desired control as created with the editor.

When needed, you'd manipulate Control(MyControlArray(myIndex)).Property.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Mastering InForm: control arrays?
« Reply #3 on: August 31, 2018, 07:52:36 am »
Fellippe, you won't be surprised to hear that your method above works.  I now need to replace hundreds of lines of code with an indexed procedure.

Richard

FellippeHeitor

  • Guest
Re: Mastering InForm: control arrays?
« Reply #4 on: August 31, 2018, 09:06:08 am »
Fellippe, you won't be surprised to hear that your method above works.  I now need to replace hundreds of lines of code with an indexed procedure.

Richard
Glad to hear!

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Mastering InForm: control arrays?
« Reply #5 on: August 31, 2018, 10:01:46 am »
So, after creating the array of controls (tedious, but now done), the first bit of code transforms as follows:

From:
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.     IF VAL(Text(HowManyBodiesTB)) < 11 THEN
  6.         Control(Body11LB).Disabled = True
  7.         Control(Body11LB).Hidden = True
  8.         Control(BodyMass11TB).Disabled = True
  9.         Control(BodyMass11TB).Hidden = True
  10.         Control(XPosition11TB).Disabled = True
  11.         Control(XPosition11TB).Hidden = True
  12.         Control(YPosition11TB).Disabled = True
  13.         Control(YPosition11TB).Hidden = True
  14.         Control(ZPosition11TB).Disabled = True
  15.         Control(ZPosition11TB).Hidden = True
  16.         Control(XVelocity11TB).Disabled = True
  17.         Control(XVelocity11TB).Hidden = True
  18.         Control(YVelocity11TB).Disabled = True
  19.         Control(YVelocity11TB).Hidden = True
  20.         Control(ZVelocity11TB).Disabled = True
  21.         Control(ZVelocity11TB).Hidden = True
  22.     END IF
  23.     IF VAL(Text(HowManyBodiesTB)) < 10 THEN
  24.         Control(Body10LB).Disabled = True
  25.         Control(Body10LB).Hidden = True
  26.         Control(BodyMass10TB).Disabled = True
  27.         Control(BodyMass10TB).Hidden = True
  28.         Control(XPosition10TB).Disabled = True
  29.         Control(XPosition10TB).Hidden = True
  30.         Control(YPosition10TB).Disabled = True
  31.         Control(YPosition10TB).Hidden = True
  32.         Control(ZPosition10TB).Disabled = True
  33.         Control(ZPosition10TB).Hidden = True
  34.         Control(XVelocity10TB).Disabled = True
  35.         Control(XVelocity10TB).Hidden = True
  36.         Control(YVelocity10TB).Disabled = True
  37.         Control(YVelocity10TB).Hidden = True
  38.         Control(ZVelocity10TB).Disabled = True
  39.         Control(ZVelocity10TB).Hidden = True
  40.     END IF
  41.     IF VAL(Text(HowManyBodiesTB)) < 9 THEN
  42.         Control(Body9LB).Disabled = True
  43.         Control(Body9LB).Hidden = True
  44.         Control(BodyMass9TB).Disabled = True
  45.         Control(BodyMass9TB).Hidden = True
  46.         Control(XPosition9TB).Disabled = True
  47.         Control(XPosition9TB).Hidden = True
  48.         Control(YPosition9TB).Disabled = True
  49.         Control(YPosition9TB).Hidden = True
  50.         Control(ZPosition9TB).Disabled = True
  51.         Control(ZPosition9TB).Hidden = True
  52.         Control(XVelocity9TB).Disabled = True
  53.         Control(XVelocity9TB).Hidden = True
  54.         Control(YVelocity9TB).Disabled = True
  55.         Control(YVelocity9TB).Hidden = True
  56.         Control(ZVelocity9TB).Disabled = True
  57.         Control(ZVelocity9TB).Hidden = True
  58.     END IF
  59.     IF VAL(Text(HowManyBodiesTB)) < 8 THEN
  60.         Control(Body8LB).Disabled = True
  61.         Control(Body8LB).Hidden = True
  62.         Control(BodyMass8TB).Disabled = True
  63.         Control(BodyMass8TB).Hidden = True
  64.         Control(XPosition8TB).Disabled = True
  65.         Control(XPosition8TB).Hidden = True
  66.         Control(YPosition8TB).Disabled = True
  67.         Control(YPosition8TB).Hidden = True
  68.         Control(ZPosition8TB).Disabled = True
  69.         Control(ZPosition8TB).Hidden = True
  70.         Control(XVelocity8TB).Disabled = True
  71.         Control(XVelocity8TB).Hidden = True
  72.         Control(YVelocity8TB).Disabled = True
  73.         Control(YVelocity8TB).Hidden = True
  74.         Control(ZVelocity8TB).Disabled = True
  75.         Control(ZVelocity8TB).Hidden = True
  76.     END IF
  77.     IF VAL(Text(HowManyBodiesTB)) < 7 THEN
  78.         Control(Body7LB).Disabled = True
  79.         Control(Body7LB).Hidden = True
  80.         NEXT Index%
  81.         Control(BodyMass7TB).Disabled = True
  82.         Control(BodyMass7TB).Hidden = True
  83.         Control(XPosition7TB).Disabled = True
  84.         Control(XPosition7TB).Hidden = True
  85.         Control(YPosition7TB).Disabled = True
  86.         Control(YPosition7TB).Hidden = True
  87.         Control(ZPosition7TB).Disabled = True
  88.         Control(ZPosition7TB).Hidden = True
  89.         Control(XVelocity7TB).Disabled = True
  90.         Control(XVelocity7TB).Hidden = True
  91.         Control(YVelocity7TB).Disabled = True
  92.         Control(YVelocity7TB).Hidden = True
  93.         Control(ZVelocity7TB).Disabled = True
  94.         Control(ZVelocity7TB).Hidden = True
  95.     END IF
  96.     IF VAL(Text(HowManyBodiesTB)) < 6 THEN
  97.         Control(Body6LB).Disabled = True
  98.         Control(Body6LB).Hidden = True
  99.         Control(BodyMass6TB).Disabled = True
  100.         Control(BodyMass6TB).Hidden = True
  101.         Control(XPosition6TB).Disabled = True
  102.         Control(XPosition6TB).Hidden = True
  103.         Control(YPosition6TB).Disabled = True
  104.         Control(YPosition6TB).Hidden = True
  105.         Control(ZPosition6TB).Disabled = True
  106.         Control(ZPosition6TB).Hidden = True
  107.         Control(XVelocity6TB).Disabled = True
  108.         Control(XVelocity6TB).Hidden = True
  109.         Control(YVelocity6TB).Disabled = True
  110.         Control(YVelocity6TB).Hidden = True
  111.         Control(ZVelocity6TB).Disabled = True
  112.         Control(ZVelocity6TB).Hidden = True
  113.     END IF
  114.     IF VAL(Text(HowManyBodiesTB)) < 5 THEN
  115.         Control(Body5LB).Disabled = True
  116.         Control(Body5LB).Hidden = True
  117.         Control(BodyMass5TB).Disabled = True
  118.         Control(BodyMass5TB).Hidden = True
  119.         Control(XPosition5TB).Disabled = True
  120.         Control(XPosition5TB).Hidden = True
  121.         Control(YPosition5TB).Disabled = True
  122.         Control(YPosition5TB).Hidden = True
  123.         Control(ZPosition5TB).Disabled = True
  124.         Control(ZPosition5TB).Hidden = True
  125.         Control(XVelocity5TB).Disabled = True
  126.         Control(XVelocity5TB).Hidden = True
  127.         Control(YVelocity5TB).Disabled = True
  128.         Control(YVelocity5TB).Hidden = True
  129.         Control(ZVelocity5TB).Disabled = True
  130.         Control(ZVelocity5TB).Hidden = True
  131.     END IF
  132.     IF VAL(Text(HowManyBodiesTB)) < 4 THEN
  133.         Control(Body4LB).Disabled = True
  134.         Control(Body4LB).Hidden = True
  135.         Control(BodyMass4TB).Disabled = True
  136.         Control(BodyMass4TB).Hidden = True
  137.         Control(XPosition4TB).Disabled = True
  138.         Control(XPosition4TB).Hidden = True
  139.         Control(YPosition4TB).Disabled = True
  140.         Control(YPosition4TB).Hidden = True
  141.         Control(ZPosition4TB).Disabled = True
  142.         Control(ZPosition4TB).Hidden = True
  143.         Control(XVelocity4TB).Disabled = True
  144.         Control(XVelocity4TB).Hidden = True
  145.         Control(YVelocity4TB).Disabled = True
  146.         Control(YVelocity4TB).Hidden = True
  147.         Control(ZVelocity4TB).Disabled = True
  148.         Control(ZVelocity4TB).Hidden = True
  149.     END IF
  150.     IF VAL(Text(HowManyBodiesTB)) < 3 THEN
  151.         Control(Body3LB).Disabled = True
  152.         Control(Body3LB).Hidden = True
  153.         Control(BodyMass3TB).Disabled = True
  154.         Control(BodyMass3TB).Hidden = True
  155.         Control(XPosition3TB).Disabled = True
  156.         Control(XPosition3TB).Hidden = True
  157.         Control(YPosition3TB).Disabled = True
  158.         Control(YPosition3TB).Hidden = True
  159.         Control(ZPosition3TB).Disabled = True
  160.         Control(ZPosition3TB).Hidden = True
  161.         Control(XVelocity3TB).Disabled = True
  162.         Control(XVelocity3TB).Hidden = True
  163.         Control(YVelocity3TB).Disabled = True
  164.         Control(YVelocity3TB).Hidden = True
  165.         Control(ZVelocity3TB).Disabled = True
  166.         Control(ZVelocity3TB).Hidden = True
  167.     END IF
  168.     AA& = MessageBox("Value From 2 to 11 Required", "", 0)
  169.  

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

And the original doesn't overwrite user's previous input (which would need dozens more lines).

TempodiBasic will be pleased.

Richard