Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 4 Jahren, 7 Monaten
Letzter Beitrag:
vor 4 Jahren, 7 Monaten
Beteiligte Autoren:
dappel, Piet van Zanten, Paulo Oliveira, Al, Allard

calculations

Startbeitrag von dappel am 26.11.2013 22:40

hi i have some troubel with performing a calculation.i wil try to explain the problem as clear as i can.

the window contains 3 static controls 2 configured as numeric and 1 as text
static control1 = contains a random number
static control2= contains a random number
static control3 = contains 1 random operator ("+","-","*","/")
the goal was make formule end then calculate the formule:
static control1 + variabel operator + static control2
i used string build for making the formule
buth now the problem is windev doesent want to calculate it.windev thinks it is a text string
if i use val to extract the value it ends up in a paradox problem.
since if u say resultnumber= number 1+ operator(=-:/+)+number 2
and that cant work.that is why i tried to use stringbuild to work around this.

can someone help me out a bit?

Antworten:

Hi Dappel,

Put "Result " in front of your calculation and do a compile with the string.

Regards,
Piet

von Piet van Zanten - am 26.11.2013 23:00
i tried to make it functional using the tip above witouth sucses

this is the code:

sB13EXPRESS=StringBuild(STC_NoName1+STC_NoName3)
sB14EXPRESS=StringBuild(sB13EXPRESS+STC_NoName2)
sB15EXPRESS=StringBuild(sB14EXPRESS+"="+"sB16EXPRESS")
Trace(sB15EXPRESS)
Compile("cal",sB15EXPRESS)
ExecuteCode("cal")
Trace(sB16EXPRESS)

trace returned this:
166*8219=sB16EXPRESS

so as you can see windev does not want to calculate the formule

von dappel - am 27.11.2013 01:04
Hello Dappel

Here is some code from a similar process

"FormulaResult" is a control on the screen
"ARFormula" is a builtup string similar to yours in that it will be "(x + y) * z"
The construction of the "LFormula" variable means that when the compile function evaluates the string in ARForumula it assigns the answer to the control named "Formula Result"
If this code does not work for you there is a problem in the buildup of your formula string


LFormula is string = "FormulaResult ="+ARFormula
LErrCode = ""
// Dynamic compilation of the source code contents in the control
Res is string
Res = Compile("ProcDyn",LFormula)
SWITCH Upper(Res)
CASE "" // All OK
CASE "ERR" // Serious Error
Error("Unable to compile the code."+CR+LFormula)
RETURN
OTHER CASE // Error message sent to the compiler
Error(Res)
RETURN
END //SWITCH Upper(Res)
// Interception of execution errors
WHEN EXCEPTION IN
// Execution of dynamic compilation process
ExecuteProcess("ProcDyn",trtProcedure)
//FormulaResult += RoundingAdjAmt
DO
// Display execution errors
LErrCode = "Error in Line N° "+(ExceptionInfo(errLine))+" : "+ExceptionInfo(errSummary)+CR
IF ExceptionInfo(errDuring)"" THEN
LErrCode+="During :"+ExceptionInfo(errDuring) +CR
END
LineSelection(ExceptionInfo(errLine),"Formula",ExceptionInfo(errInfo))
END //WHEN EXCEPTION IN




Next time you post on the forum please include the PCSoft product and version in the header as it means you will get a more relevant question e.g. [WD16]

Regards
Al

von Al - am 27.11.2013 03:30
Hi Dappel,

Your formula does not make any sense. You forgot the result part of the function. And why the = part?
If you give Windev something to compile it should have the syntax of a function.
BTW, to combine strings you don't need stringbuild, just use +.
Stringbuild is intended to insert variables into a string.
Try something like:
sFormula,sRes is string
sFormula="RESULT "+ stc_NoName1+stc_NoName3+stc_NoName2
sRes = Compile("MyProc",sFormula)
IF sRes="" THEN
resultnumber=ExecuteProcess("MyProc",trtProcedure)
sRes=Compile("MyProc","") //clear the procedure
ELSE
//error
END

Regards,
Piet

von Piet van Zanten - am 27.11.2013 07:44
Hi,

Wht not do A litle simple programming like this:

( I used edt istead of statics but that should work as well:

IF EDT_NoName2 = "*"THEN
EDT_NoName4= EDT_NoName1 * EDT_NoName3
END

IF EDT_NoName2 = "+"THEN
EDT_NoName4 = EDT_NoName1+EDT_NoName3
END
IF EDT_NoName2 = "-"THEN
EDT_NoName4 = EDT_NoName1-EDT_NoName3
END

Ps
the "EDT_NoName2'= a tekst the other controls are numbers

Just my opinion , keep it simple


Regards

Allard

von Allard - am 27.11.2013 09:43
For this simple operation ExecuteCode is your best friend.
http://doc.windev.com/en-US/?1000019783

von Paulo Oliveira - am 27.11.2013 12:35
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.