Case \黄选华\
If txtPassword.Text = \Then txtUserName.Text = \黄选华\ LogIn = True Else
LogIn = False End If
Case \胡丽萍\
If txtPassword.Text = \Then txtUserName.Text = \胡丽萍\ LogIn = True Else
LogIn = False End If
Case \张岚\
If txtPassword.Text = \Then txtUserName.Text = \张岚\ LogIn = True Else
LogIn = False End If
Case \冯现萍\
If txtPassword.Text = \Then txtUserName.Text = \冯现萍\ LogIn = True Else
LogIn = False End If
Case \陶学群\
If txtPassword.Text = \Then txtUserName.Text = \陶学群\ LogIn = True Else
LogIn = False End If
Case \陶明艳\
If txtPassword.Text = \Then txtUserName.Text = \陶明艳\
LogIn = True Else
LogIn = False End If
End Select
★将一个文件复制到另外一个目录,并改变名字
Dim xlFile, xlFileCopy As String
xlFile = App.Path & \合金厂产品质检明细表.xls\
xlFileCopy = \& \& Format(Now, \H_MM_SS\& \
FileCopy xlFile, xlFileCopy ★用format()函数自定义日期/时间格式
★VB读取一个文件的创建日期: 我看网上找到一个,用fso的 Dim file As Variant Dim fso As Variant
Set fso = CreateObject(\ Set file = fso.GetFile(.filename)
MsgBox vbLf & \创建时间:\& file.DateCreated & _ vbLf & \修改时间:\& file.DateLastModified & _ vbLf & \访问时间:\& file.DateLastAccessed
另外还有一个问题,就是获取文件版本,可以使用
Declare Function GetFileVersionInfo Lib \_
Alias \(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
但是我对其中的一些参数意思不太明白。
lptstrfilename自然是文件的名字,应该是包括全路径的;后面三个参数是什么意思我就不太懂了,特别的,最后一个类型是any,这是什么东东?
★删除指定位置的普通文件
Private Declare Function FindFirstFile Lib \Alias \ (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib \Alias \
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib \(ByVal hFindFile As Long) As Long
Private Declare Function FileTimeToSystemTime Lib \(lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long Private Const FILE_ATTRIBUTE_DIRECTORY = &H10 Private Type SYSTEMTIME wYear As Integer wMonth As Integer
wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer
wMilliseconds As Integer End Type
Private Type FILETIME
dwLowDateTime As Long dwHighDateTime As Long End Type
Private Const MAX_PATH = 260 Private 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
Dim Fdata As WIN32_FIND_DATA
Private Sub DelFiles(ByVal sPath As String, ByVal xD As String) On Error Resume Next
Dim R1 As Long, R2 As Long, TmpTime As String Dim SYSTM As SYSTEMTIME
R1 = FindFirstFile(sPath & \Fdata)
If (Fdata.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = False T
hen
FileTimeToSystemTime Fdata.ftCreationTime, SYSTM
TmpTime = CStr(SYSTM.wYear) & \& CStr(SYSTM.wMonth) & \& CStr(SYSTM.wDay) & \\& CStr(SYSTM.wHour) & \& CStr(SYSTM.wMinute) & \& CStr(SYSTM.wSecond)
If CDate(TmpTime) < CDate(xD) Then Kill sPath & StrF(Fdata.cFileName) End If Do
R2 = FindNextFile(R1, Fdata) If R2 = 0 Then Exit Do
If (Fdata.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = False Then
FileTimeToSystemTime Fdata.ftCreationTime, SYSTM
TmpTime = CStr(SYSTM.wYear) & \& CStr(SYSTM.wMonth) & \& CStr(SYSTM.wDay) & \\& CStr(SYSTM.wHour) & \& CStr(SYSTM.wMinute) & \& CStr(SYSTM.wSecond)
If CDate(TmpTime) < CDate(xD) Then Kill sPath & StrF(Fdata.cFileName) End If DoEvents Loop End Sub
Private Function StrF(ByVal S As String) As String StrF = Left(S, InStr(S, Chr(0)) - 1) End Function
用法:(删除“c:\\xltemp\\”这里所有的10天前的文件) Private Sub Command1_Click() Dim NowDate As String NowDate = Str(Date - 10) DelFiles \NowDate End Sub
(若需要删除指定扩展名的文件,将 R1 = FindFirstFile(sPath & \Fdata)这一行里面的 “*” 改成 “*.扩展名”)
(另外有一点,在这个程序里面,文件的创建时间是精确到秒的, 你的时间只用了date-10,只有日期没时间, 比如2010-3-10号,
只能删除10号之前的。10号当天的删除不了。) ★VB日期选择边框
网上有不少做日期选择框的方法或控件,搞得非常复杂。
其实VB6自带有日期选择框的: 菜单:工具,部件
把mcrosoft windows common controls-2 6.0(sp6) 得到的DTPicker就是DateTimePicker 一般就用 DTPicker控件 这就是你想要的东西了
★VB自带的删除文件功能 Kill filename
★建立连接用ADO对象很方便
首先添加“工程-引用”:Microsoft ActiveX Objects 6.0 Library dim cn as new connection dim rs as new recordset cn.open \数据库连接串\
set rs=cn.execute(\* from tab1\debug.print rs.fields(\字段名\
(\数据库连接串\这段内容,可以用一个udl文件生成,用记事本创建一个没有内容的扩展名为udl文件,双击打开,按上边的提示配置好,再用记事本打开,就可以找到需要的那段字符串了。)
Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
cn.ConnectionString = \Security Info=True;User ID=kio;Data Source=SQLDb;Initial Catalog=DataTest\cn.Open
rs.Open \cn, 1, 3 rs.AddNew
rs(\登陆时间\= Text1.Text rs(\用户名\= Text2.Text rs.Update rs.Clone cn.Close End Sub
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库VB打开EXCEL的方法解析(3)在线全文阅读。
相关推荐: