以下是我一直在使用的内容.虽然它确实有效,但我的程序在尝试计算一个相当大的文件时会锁定,例如10,000行或更多行.较小的文件立即运行.
是否有更好的或者我应该说更快的方式来计算文本文件中的行?
这是我目前正在使用的:
Dim selectedItems = (From i In ListBox1.SelectedItems).ToArray()
For Each selectedItem In selectedItems
ListBox2.Items.Add(selectedItem)
ListBox1.Items.Remove(selectedItem)
Dim FileQty = selectedItem.ToString
'reads the data file and returns the qty
Dim intLines As Integer = 0
'Dim sr As New IO.StreamReader(OpenFileDialog1.FileName)
Dim sr As New IO.StreamReader(TextBox1_Path.Text + "\" + FileQty)
Do While sr.Peek() >= 0
TextBox1.Text += sr.ReadLine() & ControlChars.CrLf
intLines += 1
Loop
ListBox6.Items.Add(intLines)
Next
Run Code Online (Sandbox Code Playgroud) 所以我知道在下面的代码示例中,它检查文件是否存在(完整文件名)...
If My.Computer.FileSystem.FileExists("C:\Temp\Test.cfg") Then
MsgBox("File found.")
Else
MsgBox("File not found.")
End If
Run Code Online (Sandbox Code Playgroud)
...但是如果文件的一部分存在呢?文件没有标准的命名约定,但它们总是具有.cfg扩展名.
所以我想检查C:\ Temp是否包含*.cfg文件,如果它存在,做一些事情,否则做其他事情.
我需要检查一个特定图像的图片框.我知道你可以查看图片框是否填充了图片......
If Not pictureBox.Image is Nothing Then
Else
End If
Run Code Online (Sandbox Code Playgroud)
但在我的情况下,我需要检查这个图片框,看看我在此过程中加载的图像.
这是我用于加载图像的当前代码...
PictureBox1.Image = My.Resources.TestImage1
Run Code Online (Sandbox Code Playgroud)
我想通过使用以下代码我可以检查图像名称,但这显然不起作用.
If PictureBox1.Image = My.Resources.TestImage1 Then
'do something
Else
'do something else
End if
Run Code Online (Sandbox Code Playgroud)
建议?
因此,我需要将一些 Visual Studio 项目转移到另一台计算机上。是像复制粘贴一样简单还是会搞砸?两台计算机都将安装相同版本的 Visual Studio,因此这应该不是问题。
是否有我忽略的导出功能?
好的,所以这是我正在运行的命令.执行时,命令提示符会一直显示,直到命令完成.
有没有办法隐藏命令提示符?
Process.Start(
"\\path_to_exe\Testing.exe ",
Arg2 + Arg3 + Arg4 + Arg5 + Arg6 + Arg7 + Arg8 + Arg9 + Arg10 + Arg11)
Run Code Online (Sandbox Code Playgroud) 有没有办法暂停进程或等待unitl进程完成后再继续下一行代码?
这是我当前压缩所有PDF然后删除的过程.目前,它在压缩之前删除文件已完成.有没有办法暂停/等待过程完成?
Dim psInfo As New System.Diagnostics.ProcessStartInfo("C:\Program Files\7-Zip\7z.exe ", Arg1 + ZipFileName + PathToPDFs)
psInfo.WindowStyle = ProcessWindowStyle.Hidden
System.Diagnostics.Process.Start(psInfo)
'delete remaining pdfs
For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Temp\", FileIO.SearchOption.SearchAllSubDirectories, "*.pdf")
File.Delete(foundFile)
Next
Run Code Online (Sandbox Code Playgroud) 所以这是我正在使用的以下VBA代码.它工作得很好,但我需要扩大范围以检查其他单元格,但其中一些单元格可能包含空单元格,我不想选择那些单元格.
有没有办法绕过那些空单元格?
Dim RNG1 As Range
Set RNG1 = Range("H1:H30")
Dim randomCell1 As Long
randomCell1 = Int(Rnd * RNG1.Cells.Count) + 1
With RNG1.Cells(randomCell1)
.Select
'will do something else here, like copy the cell, fill the cell with a color, etc
End With
Run Code Online (Sandbox Code Playgroud) 只要该文件尚不存在,以下代码就会移动文件.如果是,则不会移动文件.
我的问题是关于File.Move.msgbox何时显示?文件完全移动后会显示,还是在File.Move执行完毕后显示.
根据文件大小,移动文件可能需要一段时间,因此我不希望msgbox显示,直到文件完全移动.
有没有更好的方法呢?
For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Temp\", FileIO.SearchOption.SearchAllSubDirectories, "*.zip")
Dim foundFileInfo As New System.IO.FileInfo(foundFile)
If My.Computer.FileSystem.FileExists("C:\Transfer\" & foundFileInfo.Name) Then
Msgbox("File already exists and will not moved!")
Exit Sub
Else
File.Move(foundFile, "C:\Transfer\" & foundFileInfo.Name)
Msgbox("File has been moved!")
End If
Next
Run Code Online (Sandbox Code Playgroud) vb.net ×6
command-line ×1
excel ×1
excel-vba ×1
file-exists ×1
picturebox ×1
process ×1
random ×1
streamreader ×1
text-files ×1
vba ×1