Page 1 of 1

Is there a way to swap out the name of a constant using a

Posted: Sat Jun 22, 2013 1:45 pm
by mikeschn
Is there a way to swap out the name of a constant using a variable?

for example, in the procedure below, can I change #String_partno_line0 to #String_partno_line+x?

so that I don't have to type the SetGadgetText(#string_partno_line... 100 times?





Procedure printgrid()
For x = 1 To 100
SetGadgetText(#String_partno_line0,partno1$(x))
Next x
EndProcedure

Thanks,

Mike...

Re: Is there a way to swap out the name of a constant using

Posted: Sat Jun 22, 2013 2:18 pm
by Josh
Hi mikeschn,

welcome to the Pb-Forum. You gave the answer yourself:

Code: Select all

Procedure printgrid()

   For x = 0 To 99
     SetGadgetText(#String_partno_line0 + x, partno1$(x))
   Next x

 EndProcedure
Of course, this will only run, if all your constants are in ascending sequence.

P.S.: Please use the tags if you publish code-snippets.

Josh

Re: Is there a way to swap out the name of a constant using

Posted: Sat Jun 22, 2013 2:54 pm
by mikeschn
That worked! I made sure my constants were in some kind of order, and got the value of the first constant in the series... :D

Code: Select all

 Procedure printgrid()
    partno_control_number = #String_partno_line0
    partname_control_number = #String_partname_line0
    vol_control_number = #String_vol_line0
    den_control_number = #String_den_line0
    mass_control_number = #String_mass_line0  
    For k = 0 To 9
      SetGadgetText(partno_control_number+k,partno1$(k))
      SetGadgetText(partname_control_number+k, partname1$(k))
      SetGadgetText(vol_control_number+k, StrF(volume1(k),2))
      SetGadgetText(den_control_number+k, StrF(density1(k),8))
      SetGadgetText(mass_control_number+k, StrF(mass1(k),3))
    Next k  
  EndProcedure

Re: Is there a way to swap out the name of a constant using

Posted: Sat Jun 22, 2013 3:03 pm
by ts-soft
I think this one is better:

Code: Select all

Enumeration
  #String_partno_line0
  #String_partname_line0
  #String_vol_line0
  #String_den_line0
  #String_mass_line0
EndEnumeration

Procedure printgrid()
  Protected k
  
  For k = 0 To 9
    SetGadgetText(#String_partno_line0 + k, partno1$(k))
    SetGadgetText(#String_partname_line0 + k, partname1$(k))
    SetGadgetText(#String_vol_line0 + k, StrF(volume1(k), 2))
    SetGadgetText(#String_den_line0 + k, StrF(density1(k), 8))
    SetGadgetText(#String_mass_line0 + k, StrF(mass1(k), 3))
  Next k
EndProcedure
Greetings - Thomas