HQuintas Posted November 18, 2015 at 09:27 AM Report Share #589845 Posted November 18, 2015 at 09:27 AM Boas Quero substituir as váriáveis pelos seus valores na formula. Exemplo: Formula= (H-H1)/2+H+L H=50 H1=10 L=1 Resultado: (50-10)/2+50+1 O problema está ao substituir a variável H em que fica (50-501)/2+50+1 (só se verificar se o próximo caracter é um simbolo matemático) Já vi o tópico http://www.portugal-a-programar.pt/topic/36830-definir-expressao-com-variaveis-em-runtime/page__hl__+replace%20+var#entry339494 Mas não estou compreendo como aplicar. Queria algo mais simples. Obrigado Link to comment Share on other sites More sharing options...
vikcch Posted November 18, 2015 at 07:43 PM Report Share #589862 Posted November 18, 2015 at 07:43 PM boas estas a usar a função replace? podes trocar primeiro o H1 e só depois o H.... como recebes os valor do H, H1 e L? Link to comment Share on other sites More sharing options...
HQuintas Posted November 19, 2015 at 07:21 AM Author Report Share #589871 Posted November 19, 2015 at 07:21 AM Sim estou a usar replace. Criei uma função calculo(formula as string,variaveis as string) calculo("(H-H1)/2+H+L","H=50;H1=10;L=1") Só se substituir primeiro as variáveis com maior cumprimento de string, vou tentar. Obrigado Link to comment Share on other sites More sharing options...
HQuintas Posted November 20, 2015 at 07:14 AM Author Report Share #589915 Posted November 20, 2015 at 07:14 AM Ok, funcionou desse jeito. Trocando primeiros as variáveis com maior comprimento, foi simples e funcional. Obrigado. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now