小编dba*_*ett的帖子

PictureBox MouseEnter/MouseLeave事件未触发

使用三个图片框创建一个新表单.此代码用于在鼠标进入图片框时绘制边框,并在其离开时将其删除.结果不一致.有时它会绘制/移除边框,有时则不会.这段代码并不复杂.使用VS 2012.

Private Sub PictureBox_MouseEnter(sender As Object, e As EventArgs) _
    Handles PictureBox1.MouseEnter, PictureBox2.MouseEnter, PictureBox3.MouseEnter
    Dim pb As PictureBox = DirectCast(sender, PictureBox)
    pb.BorderStyle = BorderStyle.FixedSingle
    ' Debug.WriteLine("E " & pb.Name)
End Sub

Private Sub PictureBox_MouseLeave(sender As Object, e As EventArgs) _
    Handles PictureBox1.MouseLeave, PictureBox2.MouseLeave, PictureBox3.MouseLeave

    Dim pb As PictureBox = DirectCast(sender, PictureBox)
    pb.BorderStyle = BorderStyle.None
    ' Debug.WriteLine("X " & pb.Name)
End Sub
Run Code Online (Sandbox Code Playgroud)

vb.net winforms

6
推荐指数
1
解决办法
3519
查看次数

如何使用VBA在许多文本.log文件中找到特定字符串?

这是我到目前为止找到文件夹中所有日志文件的代码.但我需要能够在每个文件中找到一个特定的字符串,如果它在一个文件中找到,停止查找并退出循环并报告它所在的文件名.

似乎有很多不同的方法来打开文件并搜索它我不知道哪个是最好的,我通常不使用VBA但是我现在只能访问它.

另外,最多可以有36个日志文件,每个文件最多5MB.

Sub StringExistsInFile()
    Dim TheString As String

    TheString = "MAGIC"

    Dim StrFile As String
    StrFile = Dir("c:\MyDownloads\*.log")
    Do While Len(StrFile) > 0
        'Find TheString in the file
        'If found, debug.print and exit loop
    Loop
End Sub
Run Code Online (Sandbox Code Playgroud)

我找到了这个代码,但似乎在2007 +版本的Excel VBA Application.FileSearch被淘汰了:

Sub FindText()
'http://www.mrexcel.com/forum/excel-questions/68673-text-file-search-excel-visual-basic-applications.html

Dim i As Integer

'Search criteria
With Application.FileSearch
    .LookIn = "c:\MyDownloads" 'path to look in
    .FileType = msoFileTypeAllFiles
    .SearchSubFolders = False
    .TextOrProperty = "*MAGIC*" 'Word to find in this line
    .Execute 'start search

'This loop …
Run Code Online (Sandbox Code Playgroud)

string vba find text-files

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

find ×1

string ×1

text-files ×1

vb.net ×1

vba ×1

winforms ×1