PC名VB6中的文件搜索

PC名VB6中的文件搜索,vb6,Vb6,希望您广博的知识基础能在这里有所帮助 我想创建一个搜索并打开代码 我想搜索PC名称(完成该位),并使用该名称搜索文件夹中的文本文件。该文件将包含一行数据,我想用它来配置我的系统注销到的页面,如果该文件不存在,我想打开一个名为default的文件并使用其中的数据行。 例如,我坚持的一点是能够检查一个文件夹中的文件谁的扩展名将是相同的,但谁的名字可以从一台电脑改变到另一台电脑。 原因是我需要验证和测试编程,如果我在代码中更改注销页面数据,那么每次需要更改时都需要对其进行测试。通过这种方式,只需使用适

希望您广博的知识基础能在这里有所帮助

我想创建一个搜索并打开代码

我想搜索PC名称(完成该位),并使用该名称搜索文件夹中的文本文件。该文件将包含一行数据,我想用它来配置我的系统注销到的页面,如果该文件不存在,我想打开一个名为default的文件并使用其中的数据行。 例如,我坚持的一点是能够检查一个文件夹中的文件谁的扩展名将是相同的,但谁的名字可以从一台电脑改变到另一台电脑。 原因是我需要验证和测试编程,如果我在代码中更改注销页面数据,那么每次需要更改时都需要对其进行测试。通过这种方式,只需使用适当的注销数据更新以每台电脑命名的文本文件列表

对于VB.NEt来说,有大量的资源在为VB6寻找素材

附言:我对这件事很感兴趣

谢谢 如果有人有时间,请附上审查代码

再次感谢

Type Point_Type
x As Long
y As Long
End Type

'Allows user to set logout duration
'Logout Duration = timer interval x 19
'Change timer interval or max LogoutCheckCounter to change duration
 Dim LogoutCheckCounter As Integer

Declare Function GetCursorPos Lib "user32.dll" (lpPoint As Point_Type) As 
Long


Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long


Public Sub InacLogOut()

On Error GoTo Err_

Dim CheckUser As String
Dim coord As Point_Type
Dim retval As Long
Dim xPos As Long
Dim yPos As Long
Dim line As Integer
Dim page As integer
Dim LogoutTime As String
Dim LogoutPage As String
Dim MyComputerName As String
Static xOldPos As Long


'get current cursor position
retval = GetCursorPos(coord)
xPos = coord.x
yPos = coord.y

'code executes every 30 seconds

'If mouse is not moved the old position nwill equal t r log in default user
If xOldPos = xPos Then

'get the current user
 CheckUser = System.LoginUserName

 If CheckUser = "NOBODY" Then
    'User is already logged out, exit sub without action
   Exit Sub

Else      
    'get logout time 
    line = FreeFile
    If Dir("C:\LogoutTime.txt") <>"" Then
       Open "C:\LogoutTime.txt" For Input As line
       Line Input #line, LogoutTime
       MsgBox (LogoutTime)
       Close File
     Else 
     LogoutTime = 10
     End if

    ' get logout page
    MyComputerName = fOSMachineName

    Dim  FiletoOpen as string
 FiletoOpen = "C:\" & MyComputerName & ".txt"

    If Dir(FiletoOpen) <>"" Then
        Open "FiletoOpen" For Input As page
        Line Input #page, LogoutPage
        MsgBox (LogoutPage)
        Close File
     Else 
     LogoutPage = MainPage
     End if

      'code executes every 30 seconds, LogoutCheckCounter used to set the 
  logout interval
    If LogoutCheckCounter > LogoutTime Then
     ' code to kill report tool if open
        Shell "taskkill.exe /f /t /im ReportGenerator.exe"
        msgbox (Kill task)

        User.ReplaceCentralFrame LogoutPage
        System.FixLogin "NOBODY", ""

      Else
        LogoutCheckCounter = LogoutCheckCounter + 1
      End If
  End If

 Else
    'mouse has been moved, reset LogoutCheckCounter
    LogoutCheckCounter = 0

End If

'xOldPos will initially be zero the first time the code runs
xOldPos = xPos
Err_:

End Sub
'-----------------------------------------------
Function fOSMachineName() As String
Dim lngLen As Long, lngX As Long
Dim strCompName As String
lngLen = 16
strCompName = String$(lngLen, 0)
lngX = apiGetComputerName(strCompName, lngLen)
If lngX <> 0 Then
fOSMachineName = Left$(strCompName, lngLen)
Else
fOSMachineName = ""
End If
End Function

'---------------------------------------------------`
类型点\类型
x尽可能长
只要
端型
'允许用户设置注销持续时间
'注销持续时间=计时器间隔x 19
'更改计时器间隔或最大LogoutCheckCounter以更改持续时间
Dim LogoutCheckCounter为整数
将函数GetCursorPos Lib“user32.dll”(lpPoint作为Point_类型)声明为
长的
私有声明函数apiGetComputerName Lib“kernel32”别名_
“GetComputerNameA”(ByVal lpBuffer为字符串,nSize为长)为长
公共子系统注销()
上错下错_
Dim CheckUser作为字符串
作为点_类型的尺寸坐标
暗淡的后退
使XPO变暗为长
暗淡的yPos和长的一样
将线变暗为整数
将页面设置为整数
作为字符串的Dim LogoutTime
Dim LogoutPage作为字符串
将计算机名称设置为字符串
静态xOldPos尽可能长
'获取当前光标位置
retval=GetCursorPos(坐标)
xPos=coord.x
yPos=坐标y
'代码每30秒执行一次
'如果未移动鼠标,则在默认用户中,鼠标将移动到原来的位置
如果xOldPos=xPos,则
'获取当前用户
CheckUser=System.LoginUserName
如果选中user=“NOBODY”,则
'用户已注销,无需操作退出sub
出口接头
其他的
'获取注销时间
行=自由文件
如果Dir(“C:\LogoutTime.txt”)“”则
打开“C:\LogoutTime.txt”作为行输入
行输入#行,注销时间
MsgBox(LogoutTime)
关闭文件
其他的
LogoutTime=10
如果结束
'获取注销页面
MyComputerName=fOSMachineName
Dim FiletoOpen as string
FiletoOpen=“C:\”&MyComputerName&“.txt”
如果Dir(FiletoOpen)“,则
打开“FiletoOpen”作为输入页面
行输入#页,注销页
MsgBox(登录页面)
关闭文件
其他的
LogoutPage=MainPage
如果结束
'代码每30秒执行一次,LogoutCheckCounter用于设置
注销间隔
如果LogoutCheckCounter>LogoutTime,则
'关闭报告工具(如果打开)的代码
Shell“taskkill.exe/f/t/im ReportGenerator.exe”
msgbox(杀死任务)
User.ReplaceCentralFrame注销页面
System.FixLogin“无人”,“”
其他的
LogoutCheckCounter=LogoutCheckCounter+1
如果结束
如果结束
其他的
'鼠标已移动,重置LogoutCheckCounter
LogoutCheckCounter=0
如果结束
'代码第一次运行时,xOldPos最初将为零
xOLPOS=xPos
错误:
端接头
'-----------------------------------------------
函数fOSMachineName()作为字符串
暗谷一样长,lngX一样长
Dim strCompName作为字符串
lngLen=16
strCompName=String$(lngLen,0)
lngX=apiGetComputerName(strCompName,lngLen)
如果lngX为0,则
fOSMachineName=Left$(strCompName,lngLen)
其他的
fOSMachineName=“”
如果结束
端函数
'---------------------------------------------------`

它在VB6中的执行方式与Marc引用的稍有不同。在VB6中,不能在同一行上声明和初始化变量。以下是Microsoft的示例:

Dim x As String
Dim y As String

x = "Mic" & "ro" & "soft"
y = "Mic" + "ro" + "soft"

Dim a As String
Dim d As String
Dim z As String
Dim w As String

a = "abc"
d = "def"
z = a & d
w = a + d 
“&”运算符可以使用任何数据类型,变量将转换为字符串。“+”运算符仅适用于字符串,如果任何变量或文字还不是字符串,则会引发编译或运行时错误

Dim a as string
Dim x as long

x = 123
a = "abc" & x
results  in "abc123"

a = "abc" + x
results in an error
所以


你也想煮咖啡吗?你在要求一些不可能的事情,没有什么是不可能的;很难。我有代码读取电脑名并打开文件夹,其中包含以电脑名命名的文本文件。我只需要一种方法来连接找到的文件名(电脑名)和已知的扩展名。例如,在PC-001001上,我在C:\LogoutCode\中有一个文件,文件名为PC。PC001001.txt我只需要一种方法来连接字符串的路径。。。。。。“C:\LogoutCode\”和“PC001001.txt”,感谢您的快速响应
Dim strPath as String 
Dim strName as String 
Dim strFileSpec as String 

strPath = "C:\LogoutCode\"
strName = "PC001001"
strFileSpec = strPath + strName + ".txt"