Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having problem with a variable value

Status
Not open for further replies.
Jan 20, 2007
237
US
Hi Everyone
i just need to store the result of
Ctot(Dtoc(Ttod(m.ldFrom))+' '+(department.clockout)) in a local variable i defined named "ltIn"

when i run the above code from the command window as "? Ctot(Dtoc(Ttod(m.ldFrom))+' '+(department.clockout))"
i get the correct result, however in the below "cmd click event" when running the form, i get error "Function argument value, type or count is invalid" and this is pointing to "ltIn" and of course in the debugger the value of "ltIn =.F." but however all the values in here Ctot(Dtoc(Ttod(m.ldFrom))+' '+(department.clockout)) shows the correct values.

by the way m.ldFrom it is datetime value and department.clockin it is character value
so this is what i have in my cmd click event

Code:
Local lnPK, ldFrom, ldTo, lnptod, lndouble, lnbereav, lnjury, llSalary,ltIn,ltOut,lcdept

ldFrom = This.Parent.dtperiod1.valuefrom
ldTo = This.Parent.dtperiod1.valueto

Select empname
Locate For emppk=m.lnPK
If Found()
	lcdept=empname.dept
	Select department
	Locate For deptcode =m.lcdept
	ltIn=Ctot(Dtoc(Ttod(m.ldFrom))+' '+(department.clockin))
	MESSAGEBOX(m.ltIn)
	ltOut=Ctot(Dtoc(Ttod(m.ldFrom))+' '+(department.clockout))
	MESSAGEBOX(m.ltout)
Endif
can anyone explain why i am doing wrong or why this behavior ?
Thanks in advance
 
Hi,

if would you check you will see the that Ctot(Dtoc(Ttod(m.ldFrom)) is a Time and not a Character.
Try:

Code:
? lctot = CTOT(DTOC(TTOD(DATETIME())))+"a"
you will get the error

CTOT Returns a DateTime value from a character expression. see Help


Koen
 
Hi Koen,
Thanks for getting back to me but iam including even the character to be converted to time, look for the parenthesis(last parenthesis after clockin

Ctot(Dtoc(Ttod(m.ldFrom))+' '+(department.clockin))
then just store the above to variable "ltIn", it works as above from the command window in vfp 9.0 sp2
please see picture
Thanks my respects
Ernesto
 
 https://files.engineering.com/getfile.aspx?folder=87562148-eba1-48ee-9cd7-2202c3f99f0d&file=test.PNG
A couple of possible issues come to mind:

1. Are you sure ldFrom and ldTo actually contain datetime values? If they happen to be empty, they might contain a logical .F. You can easily check that in the debugger.

2. Are you sure that a record exists in Department where the dept. code equals lcDept? In other words, I'm wondering if you need to put [tt]IF FOUND()[/tt] after the [tt]LOCATE FOR deptcode =m.lcdept[/tt].

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hi mike,
1-Yes, i was making sure there are having a proper value, in fact that is why i added that picture from the command window as i emulate from outside the use of the tables and do in the command window
2-also when the error appears i suspended and go to the bebugger and i just moved the mouse cursor to the mldfrom, mlto and lcpdet and
they show the values there, so values are in there only ltin shows =.f.
thanks a lot
 
The locate in the department table could get to EOF, you thenhave no value for department.clockin.

General rule of thumb: If a lengthy expression fails, split this up into several lines, then you can see which step fails.

Code:
ldFrom = Ttod(m.ldFrom)
lcFrom = Dtoc(m.ldFrom)
lcFrom = m.lcFrom +' '+(department.clockin)
ltIn = Ctot(m.lcFrom)

Bye, Olaf.



Olaf Doschke Software Engineering
 
From your screenshot: If the expression would have worked, the last output would need to be a datetime, including time portion WITH seconds. But it isn't
Something failed and likely you have an error handler suppressing errors at this stage, therefore you think it works, but it doesn't.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Landfla,

When I reproduce your code I get " - - : : "

Please check yourselves also

Code:
departmentclockin = "monkey"
ldFrom = DATETIME()
? Ctot(Dtoc(Ttod(m.ldFrom)))
? Ctot(Dtoc(Ttod(m.ldFrom))+' '+(departmentclockin))

The first ? gives the date with 00:00:00, the next an empty value
Koen
 
here is the point guys i found out thanks to all your suggestions
actually ldFrom is date type no a datetime
sorry guys
Thanks
 
The code I posted is not what I gave you, I split up your long expression into the single steps it does. What you do is totally different.

What deptartment.clckin needs to be is a time, not "monkey". For the last step CTOT() to work the character expression needs to be a date followed by space and then a time portion. If you put completelywrong things together of course you get errors.

When I nevertheless execute your code I get the date from the first ? line and what you post from the second ? line. Yes. OK, this does NOT error,itsimply fails to convert the value to a datetime,becasue you can't convert nonsense to a datetime. What you see here is the empty datetime, a fallback value, when the conversion doesn't work.

If I put in departmentclockin = "07:30" the last line outputs 09/26/2018 07:30:00, that works. But notice the time portion is extended with seconds 07:30[highlight #FCE94F]:00[/highlight]. In your screenshot you don't have seconds in the last output, whatever you output there is a string expression that waasn't converted to a datetime.

Bye, Olaf.

Olaf Doschke Software Engineering
 
>actually ldFrom is date type no a datetime

Well, okay, then if you had tested my code, you'd seen ldFrom = Ttod(m.ldFrom) fails with a type error, yes. So the strategy to split up a long expression into the single steps is spot on.

Bye, Olaf.

Olaf Doschke Software Engineering
 
here is what i did now
ltIn=Ctot(Dtoc(m.ldFrom)+' '+(clockin))

if vartype((m.ldFrom)=D then using Dtoc(m.ldFrom) convert this to Character, now + ' '+ (clockin) that is already a character value as "08:00" is in clockin field from the table department, then if enclose all of that using Ctot, i should get a datetime value in ltin variable as 09/26/2018 08:00 and i am getting that.

i already test it, if you still can suggest is something is wrong with it, i really appreciate to inform me.
Thanks
 
Well, you still overlook the detail a datetime displayed is having seconds, too, but the expression will work on the basis you act on ldFrom depending on whether it is a date or datetime.

I was referring to your screenshot. Your "proof" of this working was displaying something that looked like it was the final dateteime to you, but it was displayed as 07:30 instead of 07:30:00 so whatever you displayed must have been what the variable still contained from a previous iteration or your command window test.

So I was only referring to the past, to your wrong interpretations of it.

And then I was referring to what you did with my code, I wrote that before I saw your response. I started writing that when the thread had one less message from you.

Simply forget it, you solved your problem. Just for future reference, finding out the problematic conversion or part of a lengthy exprssion still is best done by splitting it. The error message will only tell the line of an error, not the column or position of the error, therefore you only can find out what part of an expression fails, if you don't execute this as one single expression. Lengthy expressions are less maintainable anyway.

Bye, Olaf.



Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top