| 发表于:2007-04-10 10:29:18 楼主 |
vb中读取xml,点击“下一个”命令按钮时候,总会出现“对象变量或with块变量未设置”,“下一个”命令按钮的代码如下 private sub command2_click() dim xmldoc as new msxml2.domdocument40 dim node as ixmldomnode dim onodelist as ixmldomnodelist xmldoc.load "e:\product.xml " set onodelist = xmldoc.getelementsbytagname( "productid ") i = 0 for i = 0 to onodelist.length i = i + 1 txtid = onodelist.item(i).text txtname = onodelist.item(i).nextsibling.text txtdate = onodelist.item(i).nextsibling.nextsibling.text txtprice = onodelist.item(i).nextsibling.nextsibling.nextsibling.text next end sub xml文件如下 <?xml version= "1.0 " encoding= "gb2312 " ?> - <product> <productid> 1 </productid> <productname> glass </productname> <date> 2007-03-29 </date> <price> 20 </price> <productid> 2 </productid> <productname> milk </productname> <date> 2007-03-30 </date> <price> 3 </price> <productid> 3 </productid> <productname> bread </productname> <date> 2007-04-30 </date> <price> 2 </price> <productid> 4 </productid> <productname> pen </productname> <date> 2006-03-30 </date> <price> 15 </price> <productid> 5 </productid> <productname> notebook </productname> <date> 2006-08-06 </date> <price> 2.5 </price> </product> |
|
|
|
|