DEMO 通訊錄(三)

2021-06-16 04:50:13 字數 4637 閱讀 4358

四、功能**:

'①主窗體**:

』定義ado的模型物件,用來資料庫的連線和操作

dim objrs as recordset

dim objcmd as command

dim objcn as connection

private sub cklxr_click()

』檢視全部聯絡人

dim i as integer

dim list

if objrs.eof and objrs.bof then

objrs.close

'        msgbox "通訊錄中沒有聯絡人"

objrs.open

cklxr.enabled = true

else

objrs.movefirst

do while objrs.eof = false

set list = listview1.listitems.add(, , objrs.fields(0))

for i = 1 to objrs.fields.count - 1

list.subitems(i) = objrs.fields(i)

next i

objrs.movenext

loop

objrs.close

cklxr.enabled = false

end if

end sub

private sub cz_click()

formcz.show 1

end sub

'窗體載入的時候將listview控制項填充表頭

private sub form_load()

dim l1

listview1.gridlines = true

listview1.fullrowselect = true

listview1.view = lvwreport

set l1 = listview1.columnheaders.add(, , "編號", 0)

set l1 = listview1.columnheaders.add(, , "姓名", 1000)

set l1 = listview1.columnheaders.add(, , "年齡", 700)

set l1 = listview1.columnheaders.add(, , "性別", 700)

set l1 = listview1.columnheaders.add(, , "住宅**", 1300)

set l1 = listview1.columnheaders.add(, , "手機號碼", 1300)

set l1 = listview1.columnheaders.add(, , "家庭住址", 1400)

set l1 = listview1.columnheaders.add(, , "工作單位", 1800)

set objrs = new recordset

set objcmd = new command

set objcn = new connection

objcn.open "provider=microsoft.jet.oledb.4.0;data source=txl.mdb;persist security info=false"

objrs.open "select * from message order by 姓名", objcn, 3, 1

end sub

private sub sc_click()

formdel.show 1

end sub

'用timer控制項完成窗體顯示的動態更新

private sub timer2_timer()

unload formmain

formmain.show

call cklxr_click

timer2.enabled = false

end sub

'用timer控制項顯示時間

private sub timernow_timer()

label1.caption = "今天是" & "" & format(now, "yyyy" & "年" & "mm" & "月" & "dd" & "日" & "   " & _

"現在是:" & "hh" & "時" & "mm" & "分" & "ss" & "秒")

end sub

private sub tj_click()

formtj.show 1

end sub

private sub xg_click()

formxg.show 1

end sub

②新增聯絡人窗體**:

dim objrs as recordset

dim objcmd as command

dim objcn as connection

'資料新增和矯正

private sub command1_click()

dim a as integer

if textname.text <> "" and textnl.text <> "" and _

combo1.text <> "" and textdh.text <> "" and textsj.text <> "" _

and textdz.text <> "" and textdw.text <> "" then

if isnumeric(textnl.text) then

if isnumeric(textdh.text) then

if isnumeric(textsj.text) then

objrs.open "select * from message order by 編號", objcn, 3, 1

objcmd.activeconnection = objcn

objcmd.commandtext = "insert into message values(trim('" & textbh & "'),trim('" & textname & "'),trim('" & textnl & "'),trim('" & combo1 & "'),trim('" & textdh & "'),trim('" & textsj & "'),trim('" & textdz & "'),trim('" & textdw & "'))"

objcn.begintrans

objcmd.execute

objcn.committrans

objrs.close

a = msgbox("填加聯絡人" & "【" & textname.text & "】" & "成功", 0, "提示")

unload me

formmain.timer2.enabled = true

else

msgbox "手機號碼必須是純數字"

textsj.text = ""

textsj.setfocus

end if

else

msgbox "住宅**必須是純數字"

textdh.text = ""

textdh.setfocus

end if

else

msgbox "年齡必須是純數字"

textnl.text = ""

textnl.setfocus

end if

else

msgbox "資料沒有填寫完全,請填寫完整!"

textname.setfocus

end if

end sub

'重新填充

private sub command2_click()

textname = ""

textnl.text = ""

textdh.text = ""

textsj.text = ""

textdz.text = ""

textdw.text = ""

textname.setfocus

end sub

private sub command3_click()

unload me

end sub

private sub form_load()

set objrs = new recordset

set objcmd = new command

set objcn = new connection

objcn.open "provider=microsoft.jet.oledb.4.0;data source=txl.mdb;persist security info=false"

textbh.text = format(now, "yyyy" & "mm" & "dd" & "hh" & "mm" & "ss")

textbh.visible = false

end sub

DEMO 通訊錄(四)

修改聯絡人窗體的 dim objcn as connection dim objrs as recordset dim objcmd as command dim list as listitem 查詢要修改的聯絡人 private sub command2 click unload me end ...

單鏈表通訊錄 通訊錄2 0

單鏈表通訊錄 通訊錄2.0 標頭檔案 ifndef address h define address h include include include define success 10000 define failure 10001 define true 10002 define false ...

通訊錄問題

include using namespace std include include typedef struct lnodelnode,linklist 通訊錄的建立 void createlist l linklist l,int n createlist l 通訊者結點的插入 void li...