Data types conversion [examples]

Convert the data type of an expression
CAST
> m_var = "date"
> ? cast("12/12/2005" as (m_var))
12/12/2005
> open database southwind
> select cast(limit-balance as numeric(10,2)) from example

https://www.lianja.com/doc/index.php/CAST()


Return a letter code that represents a data type
TYPE
i = 10
? type("i")
N

https://www.lianja.com/doc/index.php/TYPE()


Return a letter code that represents a data type
VARTYPE

 

i = 10
? vartype(i)
N

https://www.lianja.com/doc/index.php/VARTYPE()


Advertisements

Variable

Q:

I am trying to upload an image file (http post “multipart/form-data”) to a “storeimage.rsp” to process. However, it returns the following error:

Error message:
ARRAY reference is out of bounds

Error line:
_FILES[0].tmp_nam

————————————————
How can i read and store the file with the _files[]?

A:

The array starts from 1 not 0.

There is an example included in the distribution in C:\lianja\cloudserver\tenants\public\wwwroot\examp les\example_upload.html which calls C:\lianja\cloudserver\tenants\public\wwwroot\examp les\example_upload.rsp.

You can run it as http://127.0.0.1:8001/examples/example_upload.html

Note that example_upload.html references ‘http://127.0.0.1/examples/example_upload.rsp’ – if you have not enabled port 80 on the Lianja Server (or set up the ISAPI IIS extension), change this to ‘http://127.0.0.1:8001/examples/example_upload.rsp’.


AMEMBERS()  works with object() also:

Code:
lo = object()
lo.hank = "here"
lo.yvonne = "over there"
lo.barry = "way over there"
? amembers(awhowhere,lo)
? lo
? awhowhere

result:

3
Object (refcnt=1)
(
[hank] => here
[yvonne] => over there
[barry] => way over there
)
Array (refcnt=1)
(
[1] = HANK
[2] = YVONNE
[3] = BARRY
)

It also works with the SCATTER MEMO NAME <name> object.


AMEMBERS() does not work with the UI framework classes.


Q:

I’ve a form, with a new container, with a button.

On the “cick” event, I call a procedure “sp_close_handler”

Code:
oContBottom.addObject("sp_close", "commandbutton")
sp_close.move(1, 1, 60, 20)
sp_close.text = "Close"
sp_close.click = sp_close_handler
Code:
proc sp_close_handler()
	p_myform.close()
endproc

can I send a parameter on the call?
for example:

Code:
oContBottom.addObject("sp_close", "commandbutton")
sp_close.move(1, 1, 60, 20)
sp_close.text = "Close"
sp_close.click = sp_close_handler with "aaa"

 

Code:
proc sp_close_handler(m_text)
	lianja.showmessage(m_text)
	p_myform.close()
endproc

naturally, this code not work.. 🙂

A:

use use a public variable to pass the text.

If the event to which you you assign sp_close_handler has one or more params, they should be passed to the routine you assign.

However, the click() event does not have params.

You could use a public var for this. In Lianja, where we aren’t creating large monolithic applications, the usual best practice of “don’t use public vars” doesn’t really apply. When I have a lot of them, I do place them on an object() when in VFP, or in a dynamic JavaScript array

VFP

Code:
goMyVars = object()
goMyVars.Phabio = "lasagna lover"

JavaScript

Code:
goMyVars = {};
goMyVars.Phabio = "lasagna lover";