Board index » delphi » Help needed with assigning values to string var - URGENT!

Help needed with assigning values to string var - URGENT!

I want to assign values to several string variables. The values are from
field1 from a
(interbase) table. The string variables' names are var+value of field2 from
the same
table (i.e. var1000, var2000 etc.). I would like to make the statement
general:

I know I can use this statement:

while not mytable.eof do begin
    if mytable.field2='1000' then
        var1000 := MytableField1.value
    else if mytable.field2='2000' then
         var2000 := MytableField1.value
    etc....
    mytable.next;
end;

But there are 100 - 150 variables, so I wold like to be able to do omething
like this:

 while not mytable.eof do begin
    var||mytableField2.value := mytableField1.value;
    mytable.next;
  end;

(I tried this but it didn't work.)

Anyone have any idea?

Tove

 

Re:Help needed with assigning values to string var - URGENT!


Why don't you use an array of variables instead?

Quote
Tove <t...@i-design.no> wrote in message news:3adfdc76$1_2@dnews...
> I want to assign values to several string variables. The values are from
> field1 from a
> (interbase) table. The string variables' names are var+value of field2
from
> the same
> table (i.e. var1000, var2000 etc.). I would like to make the statement
> general:

> I know I can use this statement:

> while not mytable.eof do begin
>     if mytable.field2='1000' then
>         var1000 := MytableField1.value
>     else if mytable.field2='2000' then
>          var2000 := MytableField1.value
>     etc....
>     mytable.next;
> end;

> But there are 100 - 150 variables, so I wold like to be able to do
omething
> like this:

>  while not mytable.eof do begin
>     var||mytableField2.value := mytableField1.value;
>     mytable.next;
>   end;

> (I tried this but it didn't work.)

> Anyone have any idea?

> Tove

Re:Help needed with assigning values to string var - URGENT!


const
  MaxValues = 150;
var
  S: array[1..MaxValues] of String;
begin
  while not MyTable.Eof do
  begin
    S[MyTable.FieldByName('Field2').AsInteger div 1000] :=
      MyTable.FieldByName('Field1').AsString;
    Next;
  end;

This assumes that the values in Field2 are in fact all even multiples of
1000 as in your example.

--
Bill

Re:Help needed with assigning values to string var - URGENT!


Thanks a lot!

"Bill Todd (TeamB)" <billtodd...@nospam.qwest.net> wrote in message
news:3ae06025_2@dnews...

Quote
> const
>   MaxValues = 150;
> var
>   S: array[1..MaxValues] of String;
> begin
>   while not MyTable.Eof do
>   begin
>     S[MyTable.FieldByName('Field2').AsInteger div 1000] :=
>       MyTable.FieldByName('Field1').AsString;
>     Next;
>   end;

> This assumes that the values in Field2 are in fact all even multiples of
> 1000 as in your example.

> --
> Bill

Re:Help needed with assigning values to string var - URGENT!


...but the values in Field2 are not even multiples of 1000, there are values
like 1030, 1080 etc..

Tove

"Bill Todd (TeamB)" <billtodd...@nospam.qwest.net> wrote in message
news:3ae06025_2@dnews...

Quote
> const
>   MaxValues = 150;
> var
>   S: array[1..MaxValues] of String;
> begin
>   while not MyTable.Eof do
>   begin
>     S[MyTable.FieldByName('Field2').AsInteger div 1000] :=
>       MyTable.FieldByName('Field1').AsString;
>     Next;
>   end;

> This assumes that the values in Field2 are in fact all even multiples of
> 1000 as in your example.

> --
> Bill

Re:Help needed with assigning values to string var - URGENT!


If you have the Enterprise version of Delphi use a TClientDataSet to hold
the values in a two column in-memory table.

--
Bill

Other Threads