Author |
Topic: Problem with a Cheetah function (Read 252 times) |
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
Problem with a Cheetah function
« Thread started on: Sep 9th, 2016, 08:26am » |
|
Richard,
First I want to say that everything you said about "wrappers" is true. They're probably not necessary, and are rarely supported. However, I don't have sufficient documentation or expertise to access Cheetah2.dll directly. Walt Decker's LB dll wrapper has been working sufficiently well for me up to this point. I am hoping you can give this problem some thought before I go looking for Walt, or post on the LB forum.
I cannot get any output from ""DBADDDATE". It doesn't generate an error, but always returns an empty string. Two other date functions have been working correctly. I know this is outside your large area of responsibility, but any suggestions will be much appreciated. Let me know if you don't have the two Cheetah dll files handy.
Thanks, Jack
Code:
open "LBcheetah2.dll" for dll as #DBF
print "DBaddDate$(=|"; DBaddDate$("20151231", 5); "|"
print DBdaysApart("20151231", "20160105")
[ProgramEnd]
print "Program ended."
end
function DBaddDate$(StartDate$, Days)
StartDate$ = trim$(StartDate$) + chr$(0)
CallDll #DBF, "DBADDDATE", StartDate$ AS PTR, AddDate$ AS PTR, _
Days AS LONG, Result AS VOID
' "DBADDDATE", StartDate$ AS PTR, AddDate$ AS PTR,Days AS LONG, Result AS VOID
' (from LBCheat.INC.BAS)
if DBerror("DBADDDATE") then goto [ProgramEnd]
DBaddDate$=stripped$(AddDate$)
end function
function DBdaysApart(DateFrom$, DateTo$)
DateFrom$ = trim$(DateFrom$) + chr$(0)
DateTo$ = trim$(DateTo$) + chr$(0)
CallDll #DBF, "DBDAYSAPART", DateFrom$ AS PTR, DateTo$ AS PTR, _
DBdaysApart AS LONG
if DBerror("DBDAYSAPART") then goto [ProgramEnd]
end function
function DBerror(ErrorNote$)
CallDll #DBF, "DBERROR", ErrorCode as Long
select case ErrorCode
case 0
DBerror=0
exit function
case else
notice "DB Error "+str$(ErrorCode)+chr$(13)+ErrorNote$
DBerror=ErrorCode
end select
CallDll #DBF,"DBRESETERROR", result as Void
end function
function stripped$(a$)
a$=trim$(a$)
if right$(a$,1)=chr$(0) then a$=left$(a$,len(a$)-1)
stripped$=trim$(a$)
end function
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Problem with a Cheetah function
« Reply #1 on: Sep 9th, 2016, 08:55am » |
|
on Sep 9th, 2016, 08:26am, Jack Kelly wrote:I cannot get any output from ""DBADDDATE". It doesn't generate an error, but always returns an empty string. |
|
That appears to be because you don't allocate any memory to hold the returned string! Look at this code:
Code: StartDate$ = trim$(StartDate$) + chr$(0)
CallDll #DBF, "DBADDDATE", StartDate$ AS PTR, AddDate$ AS PTR, _
Days AS LONG, Result AS VOID StartDate$ is (I presume) an input to the function and AddDate$ is the output from the function. That means you must initialize AddDate$ to a dummy string (it doesn't matter what it contains) which is at least as long as the longest string that can ever be returned from the function. Something like this:
Code: StartDate$ = trim$(StartDate$) + chr$(0)
AddDate$ = space$(MAX.DATE.LENGTH) + chr$(0)
CallDll #DBF, "DBADDDATE", StartDate$ AS PTR, AddDate$ AS PTR, _
Days AS LONG, Result AS VOID That should hopefully fix the problem. Here I'm assuming that MAX.DATE.LENGTH is a global constant.
Richard.
|
|
Logged
|
|
|
|
Jack Kelly
Full Member
member is offline
Gender:
Posts: 106
|
|
Re: Problem with a Cheetah function
« Reply #2 on: Sep 9th, 2016, 12:29pm » |
|
Thanks Richard, that did the trick! Thank you again, for the umpteenth time!
|
|
Logged
|
|
|
|
|