首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

关于settext()的困惑

2012-03-16 
求教:关于settext()的困惑itemchanged 事件内有如下语句dw_1.accepttext()dw_1.settext(trim(dw_1.gettext

求教:关于settext()的困惑
itemchanged 事件内有如下语句

dw_1.accepttext()
dw_1.settext(trim(dw_1.gettext()))

目的:检查当前输入的内容是否包括空格,如果有则去掉
但为什么以上语句执行后没有效果呢 例如我输入“ 111” 焦点转以后并没有变成我想要的“111”
很是困惑,请高人指点

[解决办法]
你自己到PB的帮助界面中看看即可知道如何处理了。在help的索引中输入settesx即可,看其中的代码例子。
我给你贴过来:
This example converts a number that the user enters in the column called credit to a negative value and sets both the item and the edit control's text to the negative number. This code is the script for the ItemChanged event. The data argument holds the newly entered value:

integer negative

IF dwo.Name = "credit" THEN

IF Integer(data) > 0 THEN

// Convert to negative if it's positive

negative = Integer(data) * -1

// Change the primary buffer value.

This.SetItem(row, "credit", negative)

// Change the value in the edit control

This.SetText(String(negative))

RETURN 1

END IF

END IF
[解决办法]
在itemchanged事件里一般是用getitemXXX()和setitem()函数
[解决办法]
应用itemchanged的参数data
在用setitem来做试试

探讨
itemchanged 事件内有如下语句

dw_1.accepttext()
dw_1.settext(trim(dw_1.gettext()))

目的:检查当前输入的内容是否包括空格,如果有则去掉
但为什么以上语句执行后没有效果呢 例如我输入“  111”  焦点转以后并没有变成我想要的“111”
很是困惑,请高人指点

[解决办法]
在itemchanged里面,gettext取的还是上次获焦前的字符,要切换到其他地方才会改变,在itemchanged里面用accpettext不是一个太好的办法
听楼上的,用data试试
this.settext(trim(data)) 
如果还不行就换成setitem,区别在于settext可以不理会数据类型,而setitem的话非字符型还要做转换

热点排行