高手来看一下VB的简单编程题!!!

1数组a(1to100)存放职工类型变量。编写代码删除姓名为“mary”的职工信息。设数组里已有n(n<100)个职工信息且职工姓名不重复。2文件d:\b.txt保存上述... 1 数组a(1 to 100)存放职工类型变量。编写代码删除姓名为“mary”的职工信息。设数组里已有n(n<100)个职工信息且职工姓名不重复。

2 文件d:\b.txt保存上述类型记录,编写代码物理删除姓名为“mary”的职工信息。已知职工姓名不重复。

3 设职工信息存放于关系数据库personel的employee表中,字段分别为姓名、部门和工资,其中姓名为关键字。数据控件data1与该表绑定。编写代码删除姓名为“mary”的职工信息。

跪求!
展开
 我来答
婧雨儿
2009-05-23 · TA获得超过2067个赞
知道答主
回答量:343
采纳率:0%
帮助的人:177万
展开全部
提供一个差猜搭 VB 遍历指定文件夹下 文件的 代码

'查找第一个文件的API
Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
'查找下一个文件兆圆的API
Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
'获取文件属性的API
Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
'关闭查找文件的API
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
'以下为调用浏览文件夹窗口的API
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

'常量
Public Const MAX_PATH = 260
Public Const MAXDWORD = &HFFFF
Public Const INVALID_HANDLE_VALUE = -1
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const BIF_RETURNONLYFSDIRS = 1

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

'定义类(用于查找文件)
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

'定义类(用于虚拿浏览文件夹窗口)
Public Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

'自定义函数
Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function

窗体代码:
Function GetAllFilePath(path As String, SearchStr As String)
Dim FileName As String ' 文件名
Dim DirName As String ' 子目录名
Dim dirNames() As String ' 目录数组
Dim nDir As Integer ' 当前路径的目录数
Dim i As Integer ' 循环计数器变量
Dim hSearch As Long ' 搜索句柄变量
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer

If Right(path, 1) <> "\" Then path = path & "\"
'搜索子目录
nDir = 0
ReDim dirNames(nDir)
Cont = True
hSearch = FindFirstFile(path & "*", WFD)

If hSearch <> INVALID_HANDLE_VALUE Then
Do While Cont
DirName = StripNulls(WFD.cFileName)
If (DirName <> ".") And (DirName <> "..") Then
If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
dirNames(nDir) = DirName
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If
End If

Cont = FindNextFile(hSearch, WFD) '获取下一个子目录
Loop

Cont = FindClose(hSearch)

End If

' 遍历目录并累计文件总数
hSearch = FindFirstFile(path & SearchStr, WFD)
Cont = True

If hSearch <> INVALID_HANDLE_VALUE Then
While Cont

FileName = StripNulls(WFD.cFileName)
If (FileName <> ".") And (FileName <> "..") Then
GetAllFilePath = GetAllFilePath + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
List1.AddItem path & FileName
If GetFileAttributes(path & FileName) = 32 Then
List2.AddItem FileName
End If
End If
Cont = FindNextFile(hSearch, WFD) ' 获取下一个文件

Wend

Cont = FindClose(hSearch)
End If
'如果子目录存在则遍历之
If nDir > 0 Then
For i = 0 To nDir - 1
GetAllFilePath = GetAllFilePath + GetAllFilePath(path & dirNames(i) & "\", _
SearchStr)
Next i
End If
End Function

Private Sub Command1_Click()
Dim SearchPath As String
Dim FindStr As String
Dim FileSize As Long
Dim iNull As Integer, lpIDList As Long, lResult As Long
Dim sPath As String, udtBI As BrowseInfo

With udtBI
'设置浏览窗口
.hWndOwner = Me.hWnd
'返回选中的目录
.ulFlags = BIF_RETURNONLYFSDIRS
End With

'调出浏览窗口
lpIDList = SHBrowseForFolder(udtBI)

If lpIDList Then
sPath = String$(MAX_PATH, 0)
'获取路径
SHGetPathFromIDList lpIDList, sPath
'释放内存
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)

If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If

Screen.MousePointer = vbHourglass
List1.Clear
List2.Clear
SearchPath = sPath '选中的目录为搜索的起始路径
FindStr = "*.*" '搜索所有类型的文件(此处可另作定义)

FileSize = GetAllFilePath(SearchPath, FindStr)

Screen.MousePointer = vbDefault

End Sub

FindStr = "E:\*.jpg" 就可以 E盘遍历.jpg文件

InStr(1, a, "123") 就可以识别 含有"123"的字符串: 返回 0 没有,非 0 有

稍微改一下就可以了

这个程序主要是实现遍历,可以找到指定文件夹下所有文件,包括子目录下,
如果只需要搜索指定文件夹下文件,不处理子目录,就可以不用这么复杂。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式