Subtract '-'
Positron8 · Revision 4.0.6.5 · PDF page 81
Syntax
Assignment Variable = Variable - Variable
Overview
Subtracts variables and/or constants, returning an unsigned or signed 8, 16, 24, 32-bit or floating point result.
Operands
Variable can be a constant, variable or expression. Assignment Variable can be any valid variable type.
Subtract works exactly as you would expect with signed and unsigned integers as well as floating point.
Example 1
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
Dim wMyVar1 as Word = 1000 ' Create a variable and assign a value to it
Dim wMyVar2 as Word = 999 ' Create a variable and assign a value to it
wMyVar1 = wMyVar1 - wMyVar2 ' Subtract the numbers
HRsoutLn Dec wMyVar1 ' Display the result
Example 2
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
' 32-bit subtraction
Dim wMyVar1 as Word
Dim dMyVar2 as Dword
wMyVar1 = 1575
dMyVar2 = 9763647
dMyVar2 = dMyVar2 - wMyVar1 ' Subtract the numbers
HRsoutLn Dec wMyVar2 ' Display the result
Example 3
Device = 18F26K40 ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
' 32-bit signed subtraction
Dim dMyVar1 as SDword = 1575
Dim dMyVar2 as SDword = 9763647
dMyVar1 = dMyVar1 - dMyVar2 ' Subtract the numbers
HRsoutLn SDec dMyVar1 ' Display the result
