Tripoz

Please help my code.. it Cant calculation right..

5 posts in this topic

#1 ·  Posted (edited)

i have code :

--edite--

i want to detect if $Spotakhir is between ($Spotawal + $barrierpositif) or ($Spotawal + $barriernegatif)

 

can anyone help me? thx

Edited by Tripoz
edit

Share this post


Link to post
Share on other sites



You were incorrectly mixing arithmetic and boolean operations.
Try this two lines:

$cek1 = $spotakhir < ($spotawal + $barrierpositif)
$cek2 = $spotakhir > ($spotawal + $barriernegatif)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You were incorrectly mixing arithmetic and boolean operations.
Try this two lines:

$cek1 = $spotakhir < ($spotawal + $barrierpositif)
$cek2 = $spotakhir > ($spotawal + $barriernegatif)

 

still not correct..

how to detect if $Spotakhir in between ($spotawal+$barrierpositif / $barriernegatif)?

Share this post


Link to post
Share on other sites

Another problem of your script is that you are comparing strings.
This works for me:

$iCompareValue = 1003
$iCurrentValue = 1006.99
$iPlus = "4"
$iMinus = "-4"
; Valid Range is 1003-4 to 1003+4 = 999 to 1007
If $iCurrentValue < ($iCompareValue + $iPlus) And $iCurrentValue > ($iCompareValue + $iMinus) Then
    ConsoleWrite("Within Bounds!" & @CRLF)
Else
    ConsoleWrite("Out of Bounds!" & @CRLF)
EndIf

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I don't know if I'm understanding the question correctly, but I think this will work

hitung()
func hitung()
$spotawal = "1003.5209"
$spotakhir = "1001.6473"
$barrierpositif = "4"
$barriernegatif = "-4"
$cek1 = ($spotakhir) < ($spotawal + $barrierpositif)
$cek2 = ($spotakhir) > ($spotawal + $barriernegatif)

if $cek1 = true AND $cek2 = true then  ;<===== Changed OR to AND
   consolewrite("SPOTAKHIR must be betweeN"&@CRLF)
   consolewrite("Hasilnya adalah TRUE"&@CRLF)
   consolewrite("======================================================================================================="&@CRLF)

Else
   consolewrite("Hasilnya adalah FALSE"&@CRLF)
   consolewrite("======================================================================================================="&@CRLF)

EndIf
EndFunc

 


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now