希望您丰富的知识基础可以在这里提供帮助,
我希望创建一个搜索和打开代码,我想搜索PC名称(完成该位)并使用该名称搜索文件夹中的文本文件。该文件将包含一行数据,我想用它来配置我的系统注销的页面,如果文件不存在,我想打开一个名为default的文件并使用其中的数据行。 即。我坚持的位是能够检查文件夹的文件扩展名将是相同的,但名称可以从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)
它在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
&#34;&amp;&#34;运算符可以使用任何数据类型,变量将转换为字符串。 &#34; +&#34;运算符仅适用于字符串,如果任何变量或文字不是字符串,则会抛出编译或运行时错误。
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"