Jump to content

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


Recommended Posts

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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)?

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...