I am having trouble with an If statement in crystal reports. Can someone tell me what I am doing wrong
if (time > -1) then
prev = time
else if (isnull({tbl.field}))then //error on this line
prev := 0
else
prev := TONUMBER({tbl.field});
It is giving me a "Boolean expected here error" on the second if after the else.
if time > -1 then
prev := time // missing :
else if isnull({tbl.field}) then
prev := 0
else
prev := TONUMBER({tbl.field})
;
Related
I am currently trying to get back into coding (its been some time) and for some reason I cant get my pinescipt to execute properly.
The intent is that
Condition for strategy execution is met, on the first candle a particular strategy.entry with alert_message is executed (3commas deal start).
On the next candle, or any subsequent candle WHILE the deal is open, if the same condition is met a second strategy.entry and alert_message is executed (3commas deal add funds)
If following these the event is NOT met, strategy close is triggered.
At the moment, for some reason its only triggering the deal start repeatedly, and not jumping to the add - I know its a dumb mistake - I just cant see it!!!
base_Long_Order_Placed = 0
message_long_entry = "3commas deal start"
message_long_addition = "3commas deal add funds"
message_long_exit = "3commas close all deals"
longCondition = SECRET_SAUCE
if (longCondition == true and base_Long_Order_Placed == 0)
strategy.entry('Long', strategy.long, when = longCondition ==true and barstate.isconfirmed, alert_message = message_long_entry) /
base_Long_Order_Placed := 1
else if (longCondition == true and base_Long_Order_Placed == 1)
strategy.entry('Long', strategy.long, when = base_Long_Order_Placed == 1 and longCondition ==true and barstate.isconfirmed, alert_message = message_long_addition)
else if (longCondition == false)
strategy.close('Long', when=longCondition == false and barstate.isconfirmed, alert_message = message_long_exit)
base_Long_Order_Placed := 0
else
na
Your script will be executed on every bar. When you define a variable like below
base_Long_Order_Placed = 0
It will be re-defined every time and base_Long_Order_Placed == 0 will always be true. If you want to keep its value between executions, you need to use the var keyword.
var base_Long_Order_Placed = 0
Edit
var is just a keyword that tells the compiler to keep its value for the next execution. It is just a regular variable otherwise. It will keep its value unless you overwrite. It will not iterate unless you do
base_Long_Order_Placed := base_Long_Order_Placed + 1
So, you can definitely reset it when your condition is met.
if (deal_closed)
base_Long_Order_Placed := 0
I am using Xquery mapping in my OSB project. Below is a sample code I am using which is throwing error
let $unitofmeasure :=
if (data($ItemMaster/ns1:Item/ns1:dcunitofmeasure)= 1) then
'CS'
else if (data($ItemMaster/ns1:Item/ns1:dcunitofmeasure) = 2 or
data($ItemMaster/ns1:Item/ns1:dcunitofmeasure) = 3 ) then
'EA'
else if (data($ItemMaster/ns1:Item/ns1:corpwarehouseunitofmeasure) = 2 or
data($ItemMaster/ns1:Item/ns1:corpwarehouseunitofmeasure) = 3 ) then
'EA'
else
'CS'
Later I am using above defined variable to map to a target node BaseStorageUOM(String)
{
if ($unitofmeasure != '') then
(
<BaseStorageUOM>{xs:string($unitofmeasure)}</BaseStorageUOM>
)
else
(
<BaseStorageUOM>CS</BaseStorageUOM>
)
}
When I run this its throwing Error executing the XQuery transformation:
{http://www.w3.org/2005/xqt-errors}FORG0001: "": invalid value for cast/constructor: {http://www.w3.org/2001/XMLSchema}double: error: double: Invalid double value:
I couldnt figure out the issue with the code.
This simplified version runs fine using Saxon, so the XQuery is ok, provided you have a return somewhere no mentioned in your example.
let $data := <root>
<dcunitofmeasure>2</dcunitofmeasure>
</root>
let $unitofmeasure := if ($data//dcunitofmeasure = 1)
then 'CS'
else if ($data//dcunitofmeasure = 2 or $data//dcunitofmeasure = 3)
then 'EA'
else 'CS'
return
if ($unitofmeasure != '')
then ( <BaseStorageUOM>{xs:string($unitofmeasure)}</BaseStorageUOM> )
else ( <BaseStorageUOM>CS</BaseStorageUOM> )
I'm trying to make a program that print every 100K-th odd prime number until 10M using Potion, my code:
last = 3
res = (last) # create array
loop:
last += 2
prime = true
len = res length -1
i = 0
while(i<len):
v = res at(i)
if(v*v > last): break.
if(last%v == 0): prime = false, break.
i += 1
.
if(prime):
res append(last)
if(res size % 100000 == 0): last print.
if(last>9999999): break.
.
.
But this gives Segmentation fault (core dumped), I wonder what's wrong?
For reference, the working Ruby version:
res = [last=3]
loop do
last += 2
prime = true
res.each do |v|
break if v*v > last
if last % v == 0
prime = false
break
end
end
if prime
res << last
puts last if res.length % 100000 == 0
break if last > 9999999
end
end
The output should be:
1299721
2750161
4256249
5800139
7368791
8960467
and no, this is not a homework, just out of curiosity.
you found it out by yourself, great!
println is called say in potion.
And it crashed in res size.
E.g. use this for debbugging:
rm config.inc
make DEBUG=1
bin/potion -d -Dvt example/100thoddprime.pn
and then press enter until you get to the crash.
(example/100thoddprime.pn:18): res append(last)
>
; (3, 5)
[95] getlocal 1 1 ; (3, 5)
[96] move 2 1 ; (3, 5)
[97] loadk 1 5 ; size
[98] bind 1 2 ; function size()
[99] loadpn 3 0 ; nil
[100] call 1 3Segmentation fault
so size on res returned nil, and this caused the crash.
And instead of last print, "\n" print.
Just do last say.
This came from perl6 syntax, sorry :)
My bad, I forgot to change from res length -1 to res length when changing from 0 to len (i), because this syntax not recognized as a loop (failed to receive break).
last = 3
res = (last)
loop:
last println
last += 2
prime = true
len = res length
i = 0
while(i<len):
v = res at(i)
if(v*v > last): break.
if(last%v == 0): prime = false, break.
i += 1
.
if(prime):
res append(last)
if(res length % 100000 == 0): last print, "\n" print.
if(last>9999999): break.
.
.
I am starting to learn programming.
I have to do (HW) program where I can add in example name and surname, add it to single linked list and than display this single linke list.
I tried to do it, program is compiling and it is even working. I can add data and it is displayed. But I propably dont understan something and make mistake. I am adding first person, it is displayed, than I am adding second person, it is also displayed but the first person data is override by the second person I added. So I have two the same records. Listbox is only showing data from the single linked list so I suppose there is no problem. Each pointer should point different data so why each record is the same as the last one I added?
Here is my code:
type
wskaznik = ^Lista;
Lista = record
lp : string;
dane : string;
wsk : wskaznik;
end;
var
Form1 : TForm1;
First, current : wskaznik;
tekst : string;
liczba : string;
i, k : integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure AddToList(dane : string; lp : string; var current : wskaznik);
var
prev, Next : wskaznik;
begin
if current <> nil then
begin
prev := current;
Next := current^.wsk;
end
else
begin
prev := nil;
Next := nil;
end;
new(current);
current^.dane := dane;
current^.lp := lp;
current^.wsk := Next;
if prev <> nil then
prev^.wsk := current;
end;
procedure GetAddr(dane : string; var First, current : wskaznik);
var
Next : wskaznik;
begin
if First <> nil then
begin
Next := First;
repeat
if Next^.wsk <> nil then
Next := Next^.wsk
until (Next^.wsk = nil) or (Next^.dane = dane);
current := Next;
end;
end;
procedure GetNum(n : integer; var First, current : wskaznik);
var
Next : wskaznik;
begin
if First <> nil then
if n = 1 then
current := First
else
if (n = 2) and (First^.wsk = nil) then
n := 0
else
begin
Next := First;
i := 1;
repeat
Inc(i);
if Next^.wsk <> nil then
Next := Next^.wsk
until (i = n) or (Next^.wsk = nil);
if (Next^.wsk = nil) and (i < n) then
n := 0
else
current := Next;
end;
end;
procedure List;
var
l : integer;
begin
form1.listbox1.Clear;
form1.listbox2.Clear;
for l := 1 to i do
begin
Getnum(l, First, current);
if l > 1 then
form1.listbox1.items.add(current^.dane);
form1.listbox2.items.add(current^.lp);
end;
end;
procedure findLess(dane : string; lp : string; var First, current : wskaznik);
var
tmp, Next : wskaznik;
begin
if First <> nil then
begin
Next := First;
repeat
if (Next^.wsk <> nil) then
begin
tmp := Next;
Next := Next^.wsk;
end;
until (Next^.wsk = nil) or (Next^.dane > dane);
if Next^.dane > dane then
current := tmp
else
current := Next;
if Next^.lp > lp then
current := tmp
else
current := Next;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
Inc(i);
findLess(edit1.Text, edit2.Text, First, current);
addtolist(edit1.Text, edit2.Text, current);
label3.Caption := 'Elementów: ' + IntToStr(i - 1);
//edit1.SetFocus;
list;
end;
end.
You never assign anything to First (assuming Firstis to be the beginning of the list).
The first time you call AddToList you should assign Current to First
I am creating a Sudoku solver in C++ while implementing Lua scripting for the actual solving of the puzzle. I have created the following Lua code, but get a
PANIC: unprotected error in call to Lua API (attempt to call a nil value)
error whenever my C++ code reaches the first instance of lua_call.
When compiling the code in SciTE, I get the following error:
lua: SudokuSolver.lua:99: 'end' expected (to close 'for' at line 61)
near ''
Adding three 'end's to the end of the function that has the for loop at line 61 clears that error, but causes errors in the C++ program. Can someone please look at my Lua and see if there's any syntax errors or other issues which may be causing this? Thank you
CODE
-- Table Declaration
SudokuGrid = {}
function RecieveGrid ( _Pos, _Value )
-- Recives the cell value at _Pos position from C++
SudokuGrid[_Pos] = _Value
end
function SolveSudoku ( _Pos )
-- Recursive function which solves the sudoku puzzle
local iNewValue = 1
-- If Position is 82+, all cells are solved
if( _Pos >= 82 ) then
return true
end
-- If Position already has a value
if( SudokuGrid[_Pos] ~= 0) then
return SolveSudoku( _Pos + 1 )
else
while(true) do
SudokuGrid[_Pos] = iNewValue
iNewValue = iNewValue + 1
-- If the new value of the cell is higher than 9 its not valid
if( SudokuGrid[_Pos] > 9 ) then
--Reset value
SudokuGrid[_Pos] = 0
return false
end
if( IsValid( _Pos ) and SolveSudoku( _Pos + 1 ) ) then
return true
end
end
end
end
function IsValid ( _Pos )
-- Calculate Column and Row in Grid
x = _Pos % 9
if( x == 0 ) then
x = 9
end
y = math.ceil(_Pos / 9)
-- Check Rows
for i=1, 9 do
CheckVal = ((y - 1) * 9) + i
if( CheckVal == _Pos ) then
-- Do nothing
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal]and SudokuGrid[_Pos] ~= 0 ) then
return false
else
-- Do nothing
end
end
-- Check Columns
for i=1, 9 do
CheckVal = ((i - 1) * 9) + x
if( CheckVal == _Pos ) then
-- Do nothing
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal] and SudokuGrid[_Pos] ~= 0 ) then
return false
else
-- Do nothing
end
end
-- Check 3X3 Grid
SquareCol = math.ceil(x/3)
SquareRow = math.ceil(y/3)
StartVal = (SquareCol - 1) * 27 + (SquareRow * 3) -2
for j=0, 2 do
for i=0, 2 do
CheckVal = StartVal + i
if( CheckVal == _Pos ) then
-- Do nothing
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal] and SudokuGrid[_Pos] ~= 0 ) then
return false
else
-- Do nothing
end
end
StartVal = StartVal + 9
end
return true
end
function SendGrid ( _Pos )
-- Sends the value at _Pos to C++
return SudokuGrid[_Pos]
end
The syntax error is in all lines containing else if:
else if ( SudokuGrid[_Pos] == SudokuGrid[CheckVal]and SudokuGrid[_Pos] ~= 0 ) then
In Lua, use elseif instead. Using else if would need more closing end.
elseif SudokuGrid[_Pos] == SudokuGrid[CheckVal] and SudokuGrid[_Pos] ~= 0 then