2017-09-26 84 views
-2

希望你的渊博知识的基础可以帮助在这里,文件搜索在PC名VB6

即时通讯寻求建立一个搜索和开放代码,

我要搜索的计算机名(有位实现)并使用该名称搜索文件夹中的文本文件。该文件将包含一行数据,我想用它来配置我的系统注销的页面,如果文件不存在,我想打开一个名为default的文件并使用其中的数据行。 即。即时通讯卡上的位是能够检查文件夹的扩展名将相同但名称可以从PC更改为PC的文件。 原因是我需要验证和测试编程,如果我更改代码内的注销页面数据,每次需要对其进行更改时都需要对其进行测试。通过这种方式更新每个带有合适的注销数据的pc命名的文本文件列表,这些都是需要更改的。

有足够的资源为VB.NEt努力寻找VB6的东西。

PS。在这非常绿色。

感谢 审查附带的代码,如果任何人有足够的时间,

再次感谢

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 

'---------------------------------------------------` 
+0

你也要打个咖啡吗?你在问一些不可能的事情。 –

+0

没有什么是不可能的;只是很难。我有读取PC名称的代码并操作包含以PC命名的文本文件的文件夹。我只需要一种方法来加入找到的文件名(PC名称)和已知的扩展名。例如,在PC-001001上,我使用PC名称在C:\ LogoutCode \中有一个文件。 PC001001.txt我只需要一种方法来加入字符串的路径......“C:\ LogoutCode \”&&“PC001001.txt”,并感谢您的快速响应 –

+0

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/concatenation-operators – Marc

回答

0

它在VB6比马克引用做得有点不同。您不要在VB6中的同一行上声明和初始化变量。继微软的例子:

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 

所以

Dim strPath as String 
Dim strName as String 
Dim strFileSpec as String 

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

thanks @ thx1138v2 –