vbs 通讯录

Dim NewName '名字
Dim NewNum  '号码
Dim FindIn '输入号码
Dim strLine,strLineCase,strNewFile 
Dim Ch '选择操作
Set fso = CreateObject("Scripting.FileSystemObject")


Sub LoadFile
  If Not fso.FileExists("d:\Telephone.txt") Then
'MsgBox "cant find Telephone.txt"
fso.CreateTextFile("d:\Telephone.txt")
End If
End Sub
 
 '添加号码
Sub AddNumber
NewName=InputBox("Please Enter Your Name:","电话簿")
NewNum=InputBox("Please Enter Your Phonenumber:","电话簿")
MsgBox "phonebook:"&NewName&":"&NewNum&",please clik ok"
fso.openTextFile("d:\telephone.txt",8).writeline(NewName&":"&NewNum)
fso.openTextFile("d:\telephone.txt",8).close
End Sub


'查询号码
Sub FindData
Findin=InputBox("name","电话簿")
Findout=Len(Findin)
Set FindText=fso.OpenTextFile("d:\Telephone.txt",1)
FindNum=""
Do While Not FindText.AtEndOfLine
FindTemp=FindText.Read(Findout)
If Findin=FindTemp Then  '如果输入的姓名和通讯录中姓名相同的话
FindNum=FindText.ReadLine
Else
FindText.SkipLine
End If
Loop

FindText.Close

If FindNum="" Then
MsgBox "cant find peoplle"
Else
MsgBox  Findin&FindNum
End If
End Sub




'删除号码
Sub DeleteData
Findin=InputBox("name","电话簿")

Set fso=CreateObject("Scripting.FileSystemObject") 
Set FindText=fso.OpenTextFile("d:\telephone.txt",1) 
Do Until FindText.AtEndOfStream 
strLine=FindText.Readline 
If instr(strLine,Findin) or instr(strLineCase,Findin) or Findin="" then 
strNewFile=strNewFile 
Else 
strNewFile=strNewFile&strLine&vbcrlf
End If 
msgbox "delete complete"
Loop 

FindText.Close 
Set fso=CreateObject("Scripting.FileSystemObject") 
Set FindText=fso.OpenTextFile("d:\telephone.txt",2) 
FindText.Write strNewFile 
FindText.Close 
End Sub


LoadFile
'选择操作
Do 
Ch=InputBox("what will you do?please input number.1:ADD,2:Find,3:delete,4:exit","电话簿")


Select Case Ch
Case 1: 
AddNumber
Case 2:
FindData
Case 3:
DeleteData
Case 4:
Wscript.Quit
Case Else 
msgbox "enter wrong "
End Select


Loop
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭