end sub
'========================================================
'十九、注册表的操作
'========================================================
option explicit
const hkey_classes_root = &h80000000
const hkey_current_user = &h80000001
const hkey_local_machine = &h80000002
const hkey_users = &h80000003
const hkey_performance_data = &h80000004
const hkey_current_config = &h80000005
const hkey_dyn_data = &h80000006
const reg_none = 0
const reg_sz = 1
const reg_expand_sz = 2
const reg_binary = 3
const reg_dword = 4
const reg_dword_big_endian = 5
const reg_multi_sz = 7
private declare function regsetvalueex lib "advapi32.dll" alias "regsetvalueexa" (byval hkey as long, byval lpvaluename as string, byval reserved as long, byval dwtype as long, lpdata as any, byval cbdata as long) as long
private declare function regcreatekey lib "advapi32.dll" alias "regcreatekeya" (byval hkey as long, byval lpsubkey as string, phkresult as long) as long
private sub command1_click()
dim hkey as long
dim dsnname, strdriver, strserver, strdatabase, strlastuser, strdbtype as string
dsnname = "myodbc"
strdriver = "c:\\winnt\\system32\\sqlsrv32.dll" 'sql server的驱动,如果用vfp可以改成相应的文件
strserver = "server"
strdatabase = "test"
strlastuser = "sa"
strdbtype = "sql server"
regcreatekey hkey_local_machine, "software\odbc\odbc.ini\odbc data sources", hkey
regsetvalueex hkey, dsnname, 0, reg_sz, byval strdbtype, len(strdbtype) + 1
regcreatekey hkey_local_machine, "software\odbc\odbc.ini\" & dsnname, hkey
regsetvalueex hkey, "driver", 0, reg_expand_sz, byval cstr(strdriver), len(strdriver) + 1
regsetvalueex hkey, "server", 0, reg_sz, byval cstr(strserver), len(strserver) + 1
regsetvalueex hkey, "database", 0, reg_sz, byval cstr(strdatabase), len(strdatabase) + 1
regsetvalueex hkey, "lastuser", 0, reg_sz, byval cstr(strlastuser), len(strlastuser) + 1
end sub
'========================================================
'二十、treeview的使用,及选中其中指定的节点
'========================================================
private sub command1_click()
dim nodey as node
for each nodey in treeview1.nodes
if cstr(trim(nodey.text)) = "ff" then
nodey.selected = true
treeview1.setfocus
exit for
end if
next
end sub
private sub form_load()
rs1.commandtype = adcmdtext
rs1.recordsource = "select distinct biao,zu from test order by zu"
rs1.refresh
dim rs as adodb.recordset
set rs = rs1.recordset
set nodx = treeview1.nodes.add(, , "r", "报表组 ")
i = 0
dim tempstring as string
dim tempkey as long
do until rs.eof or rs.bof
if tempstring = rs!zu then
set nodex = treeview1.nodes.add("z" & tempkey, tvwchild, "b" & i, rs!biao)
else
set nodx = treeview1.nodes.add("r", tvwchild, "z" & i, rs!zu)
set nodex = treeview1.nodes.add("z" & i, tvwchild, "b" & i, rs!biao)
tempstring = rs!zu
tempkey = i
end if
rs.movenext
i = i + 1
loop
end sub
'========================================================
'二十一、word对象的使用(查找word文档中是否包含指定关键字,
'以及在指定位置插入字符串)
'========================================================
private sub command1_click()
dim wrdapp as object
dim f, fso as object
dim filepath as string
dim keywords as string
filepath = "c:\words"
keywords = "abc"
set fso = createobject("scripting.filesystemobject")
set folders = fso.getfolder(filepath)
i = 0
for each f in folders.files
if lcase(right(f.name, len(f.name) - instrrev(f.name, "."))) = "doc" then
set wrdapp = createobject("word.application")
wrdapp.visible = false
wrdapp.documents.open filename:=filepath & "\" & f.name
if instr(wrdapp.activedocument.content.text, keywords) <> 0 then
msgbox f.name
end if
wrdapp.quit