我用
a_data = dataobject.listname[i]
当列名是具体的列名的时候可以获得相应的值;但是用变量的时候报错
例如这样:a_data = dataobject.ls_listname[i]
如果是用getitem,我不知道怎么判断该列的类型;
PB好像没有类似a_data = dw[i,j] 的写法?
6 个解决方案
#1
PB好像没有类似a_data = dw[i,j] 的写法?
有,你可以用 dw_1.object.data[row, col]来取,知道行号,你也可以这么写
dw_1.getitemstring(ll_row, "列名")
有,你可以用 dw_1.object.data[row, col]来取,知道行号,你也可以这么写
dw_1.getitemstring(ll_row, "列名")
#2
谢谢版主,我试了一下,dw_1.object.data[row, col],确实可以,接下来我要研究怎样获得col的值,row相对简单。
dw_1.getitemstring(ll_row, "列名"):这种写法如果字段类型不是字符型会不会报错?我印象中类型不匹配是报错的;
dw_1.getitemstring(ll_row, "列名"):这种写法如果字段类型不是字符型会不会报错?我印象中类型不匹配是报错的;
#3
你可以用dw_1.describe("列名.coltype")判断一下类型,再用相应的getitemstring或者getitemnumber之类去取
Describe argument:
"controlname.ColType"
Parameter Description
controlname The column for which you want the datatype. Possible datatypes are:?Char (n) - n is the number of characters?Date?DateTime?Decimal (n) - n is the number of decimal places?Int ?Long?Number?Real?Time?Timestamp?ULong
Describe argument:
"controlname.ColType"
Parameter Description
controlname The column for which you want the datatype. Possible datatypes are:?Char (n) - n is the number of characters?Date?DateTime?Decimal (n) - n is the number of decimal places?Int ?Long?Number?Real?Time?Timestamp?ULong
#4
dwo.name就是列名哦
#5
Long ll_Col,ll_Row
Long ll_ColCount,ll_Value
String ls_ColName,ls_ColType,ls_Value
DateTime ldt_Value
ll_ColCount = Long(dw_1.Describe("datawindow.column.count"))
For ll_Col = 1 To ll_ColCount
ls_ColName = dw_1.Describe("#"+String(ll_Col)+".name")
ls_ColType = dw_1.Describe("#"+String(ll_Col)+".coltype")
ls_ColType = Upper(ls_ColType)
If Pos(ls_ColType,'CHAR') > 0 Then
ls_Value = dw_1.GetItemString(ll_Row,ls_ColName)
ElseIf ls_ColType = 'DATETIME' Then
ldt_Value = dw_1.GetItemDateTime(ll_Row,ls_ColName)
ElseIf ls_ColType = 'LONG' Then
ll_Value = dw_1.GetItemNumber(ll_Row,ls_ColName)
Else //等等...
End If
Next
Long ll_ColCount,ll_Value
String ls_ColName,ls_ColType,ls_Value
DateTime ldt_Value
ll_ColCount = Long(dw_1.Describe("datawindow.column.count"))
For ll_Col = 1 To ll_ColCount
ls_ColName = dw_1.Describe("#"+String(ll_Col)+".name")
ls_ColType = dw_1.Describe("#"+String(ll_Col)+".coltype")
ls_ColType = Upper(ls_ColType)
If Pos(ls_ColType,'CHAR') > 0 Then
ls_Value = dw_1.GetItemString(ll_Row,ls_ColName)
ElseIf ls_ColType = 'DATETIME' Then
ldt_Value = dw_1.GetItemDateTime(ll_Row,ls_ColName)
ElseIf ls_ColType = 'LONG' Then
ll_Value = dw_1.GetItemNumber(ll_Row,ls_ColName)
Else //等等...
End If
Next
#6
感谢各位,问题解决。这里小结一下,遇见几个有趣的问题:
ls_ColumnName = dwo.Name
ls_DataType = dwo.ColType
当事件单击或双击在表体的时候可以获取相应的值,但是双击在表头的时候报错;
error accessing external object property coltype......
AndriyChoi 的方法本质和版主的差不多,可能你这段程序的目的和我有些不一样。
ls_ColumnName = dwo.Name
ls_DataType = dwo.ColType
当事件单击或双击在表体的时候可以获取相应的值,但是双击在表头的时候报错;
error accessing external object property coltype......
AndriyChoi 的方法本质和版主的差不多,可能你这段程序的目的和我有些不一样。
#1
PB好像没有类似a_data = dw[i,j] 的写法?
有,你可以用 dw_1.object.data[row, col]来取,知道行号,你也可以这么写
dw_1.getitemstring(ll_row, "列名")
有,你可以用 dw_1.object.data[row, col]来取,知道行号,你也可以这么写
dw_1.getitemstring(ll_row, "列名")
#2
谢谢版主,我试了一下,dw_1.object.data[row, col],确实可以,接下来我要研究怎样获得col的值,row相对简单。
dw_1.getitemstring(ll_row, "列名"):这种写法如果字段类型不是字符型会不会报错?我印象中类型不匹配是报错的;
dw_1.getitemstring(ll_row, "列名"):这种写法如果字段类型不是字符型会不会报错?我印象中类型不匹配是报错的;
#3
你可以用dw_1.describe("列名.coltype")判断一下类型,再用相应的getitemstring或者getitemnumber之类去取
Describe argument:
"controlname.ColType"
Parameter Description
controlname The column for which you want the datatype. Possible datatypes are:?Char (n) - n is the number of characters?Date?DateTime?Decimal (n) - n is the number of decimal places?Int ?Long?Number?Real?Time?Timestamp?ULong
Describe argument:
"controlname.ColType"
Parameter Description
controlname The column for which you want the datatype. Possible datatypes are:?Char (n) - n is the number of characters?Date?DateTime?Decimal (n) - n is the number of decimal places?Int ?Long?Number?Real?Time?Timestamp?ULong
#4
dwo.name就是列名哦
#5
Long ll_Col,ll_Row
Long ll_ColCount,ll_Value
String ls_ColName,ls_ColType,ls_Value
DateTime ldt_Value
ll_ColCount = Long(dw_1.Describe("datawindow.column.count"))
For ll_Col = 1 To ll_ColCount
ls_ColName = dw_1.Describe("#"+String(ll_Col)+".name")
ls_ColType = dw_1.Describe("#"+String(ll_Col)+".coltype")
ls_ColType = Upper(ls_ColType)
If Pos(ls_ColType,'CHAR') > 0 Then
ls_Value = dw_1.GetItemString(ll_Row,ls_ColName)
ElseIf ls_ColType = 'DATETIME' Then
ldt_Value = dw_1.GetItemDateTime(ll_Row,ls_ColName)
ElseIf ls_ColType = 'LONG' Then
ll_Value = dw_1.GetItemNumber(ll_Row,ls_ColName)
Else //等等...
End If
Next
Long ll_ColCount,ll_Value
String ls_ColName,ls_ColType,ls_Value
DateTime ldt_Value
ll_ColCount = Long(dw_1.Describe("datawindow.column.count"))
For ll_Col = 1 To ll_ColCount
ls_ColName = dw_1.Describe("#"+String(ll_Col)+".name")
ls_ColType = dw_1.Describe("#"+String(ll_Col)+".coltype")
ls_ColType = Upper(ls_ColType)
If Pos(ls_ColType,'CHAR') > 0 Then
ls_Value = dw_1.GetItemString(ll_Row,ls_ColName)
ElseIf ls_ColType = 'DATETIME' Then
ldt_Value = dw_1.GetItemDateTime(ll_Row,ls_ColName)
ElseIf ls_ColType = 'LONG' Then
ll_Value = dw_1.GetItemNumber(ll_Row,ls_ColName)
Else //等等...
End If
Next
#6
感谢各位,问题解决。这里小结一下,遇见几个有趣的问题:
ls_ColumnName = dwo.Name
ls_DataType = dwo.ColType
当事件单击或双击在表体的时候可以获取相应的值,但是双击在表头的时候报错;
error accessing external object property coltype......
AndriyChoi 的方法本质和版主的差不多,可能你这段程序的目的和我有些不一样。
ls_ColumnName = dwo.Name
ls_DataType = dwo.ColType
当事件单击或双击在表体的时候可以获取相应的值,但是双击在表头的时候报错;
error accessing external object property coltype......
AndriyChoi 的方法本质和版主的差不多,可能你这段程序的目的和我有些不一样。