pegar valor dos arrays
como faço para pegar o valor desses arrays
procedure TForm1.Button1Click(Sender: TObject);
const
numeros: array[0..9] of string = (´00´,´01´,´02´,´03´,´04´,´05´,´06´,´07´,´08´,´09´);
letras : array[´A´..´Z´] of string = (´10´,´11´,´12´,´13´,´14´,´15´,´16´,´17´,´18´,´19´,´20´,´21´,´22´,´23´,
´24´,´25´,´26´,´27´,´28´,´29´,´30´,´31´,´32´,´33´,´34´,´35´) ;
var EMPRESA,VALOR,teste: string;
begin
EMPRESA := ´OE´;
teste := COPY(EMPRESA,1,1);
VALOR := letras[teste];
teste := COPY(EMPRESA,2,1);
VALOR := Valor+letras[´E´];
showmessage(valor);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
numeros: array[0..9] of string = (´00´,´01´,´02´,´03´,´04´,´05´,´06´,´07´,´08´,´09´);
letras : array[´A´..´Z´] of string = (´10´,´11´,´12´,´13´,´14´,´15´,´16´,´17´,´18´,´19´,´20´,´21´,´22´,´23´,
´24´,´25´,´26´,´27´,´28´,´29´,´30´,´31´,´32´,´33´,´34´,´35´) ;
var EMPRESA,VALOR,teste: string;
begin
EMPRESA := ´OE´;
teste := COPY(EMPRESA,1,1);
VALOR := letras[teste];
teste := COPY(EMPRESA,2,1);
VALOR := Valor+letras[´E´];
showmessage(valor);
end;
Eric.miranda
Curtidas 0
Respostas
Massuda
30/11/2005
Como toda string é um array de char, pode-se fazer algo assim...
procedure TForm1.Button1Click(Sender: TObject); const numeros: array[0..9] of string = (´00´,´01´,´02´,´03´,´04´,´05´,´06´,´07´,´08´,´09´); letras : array[´A´..´Z´] of string = (´10´,´11´,´12´,´13´,´14´,´15´,´16´,´17´,´18´,´19´,´20´,´21´,´22´,´23´, ´24´,´25´,´26´,´27´,´28´,´29´,´30´,´31´,´32´,´33´,´34´,´35´) ; var EMPRESA,VALOR: string; teste: Char; begin EMPRESA := ´OE´; teste := EMPRESA[1]; VALOR := letras[teste]; teste := EMPRESA[2]; VALOR := Valor+letras[teste]; showmessage(valor); (* ou, dum modo mais generico... Valor := ´´; for I := 1 to Length(Empresa) do begin Valor := Valor + Letras[Empresa[I]]; end; *) end;
GOSTEI 0
Eric.miranda
30/11/2005
Valeu Massuda, era isso mesmo que estava precisando..
só mais uma coisa se vc puder me dizer se tem como..
teria como juntar esses dois arrays,
pq tenho uma coisa do tipo.
OEA100001
e tenho que ficar verificando e conventendo cada caracter em seu valor correspondente no array e ir somando
ex O = 24 E= 14 A=10 etc..
24+14+10
valeu
só mais uma coisa se vc puder me dizer se tem como..
teria como juntar esses dois arrays,
pq tenho uma coisa do tipo.
OEA100001
e tenho que ficar verificando e conventendo cada caracter em seu valor correspondente no array e ir somando
ex O = 24 E= 14 A=10 etc..
24+14+10
valeu
GOSTEI 0
Eric.miranda
30/11/2005
fiz de uma forma diferente .. mas estou com um errinho ..
procedure TForm1.Button2Click(Sender: TObject);
const
numeros: array[0..9] of string = (´00´,´01´,´02´,´03´,´04´,´05´,´06´,´07´,´08´,´09´);
letras : array[´A´..´Z´] of string = (´10´,´11´,´12´,´13´,´14´,´15´,´16´,´17´,´18´,´19´,´20´,´21´,´22´,´23´,
´24´,´25´,´26´,´27´,´28´,´29´,´30´,´31´,´32´,´33´,´34´,´35´) ;
var EMPRESA,VALOR: string;
teste: Char;
i: integer;
begin
EMPRESA := ´EPA1123456´;
for i:= 1 to 10 do
begin
teste := EMPRESA;
if (teste in [´A´..´Z´]) then
begin
VALOR := valor+letras[Empresa];
end
else
begin
VALOR := valor+numeros[Empresa];//dá erro aqui!!!!!
end;
end;
showmessage(valor);
end;
vejam se vcs podem me ajudar em mais essa..
valeu pessoal
procedure TForm1.Button2Click(Sender: TObject);
const
numeros: array[0..9] of string = (´00´,´01´,´02´,´03´,´04´,´05´,´06´,´07´,´08´,´09´);
letras : array[´A´..´Z´] of string = (´10´,´11´,´12´,´13´,´14´,´15´,´16´,´17´,´18´,´19´,´20´,´21´,´22´,´23´,
´24´,´25´,´26´,´27´,´28´,´29´,´30´,´31´,´32´,´33´,´34´,´35´) ;
var EMPRESA,VALOR: string;
teste: Char;
i: integer;
begin
EMPRESA := ´EPA1123456´;
for i:= 1 to 10 do
begin
teste := EMPRESA;
if (teste in [´A´..´Z´]) then
begin
VALOR := valor+letras[Empresa];
end
else
begin
VALOR := valor+numeros[Empresa];//dá erro aqui!!!!!
end;
end;
showmessage(valor);
end;
vejam se vcs podem me ajudar em mais essa..
valeu pessoal
GOSTEI 0
Massuda
30/11/2005
fiz de uma forma diferente .. mas estou com um errinho ..
Mude para...VALOR := valor+numeros[Ord(Empresa)];
GOSTEI 0
Eric.miranda
30/11/2005
Massuda, deu erro..
acess violation.. :(
acess violation.. :(
GOSTEI 0
Massuda
30/11/2005
Revendo seu código, ele devia ser algo assim...
... for i:= 1 to Length(Empresa) do begin teste := EMPRESA[I]; if (teste in [´A´..´Z´]) then begin VALOR := valor+letras[teste]; end else begin VALOR := valor+numeros[Ord(teste)]; end; end; ...
GOSTEI 0