Run batch file in

You can use the Process class to run a batch file Dim psi As New ProcessStartInfo(“Path TO Batch File”) psi.RedirectStandardError = True psi.RedirectStandardOutput = True psi.CreateNoWindow = False psi.WindowStyle = ProcessWindowStyle.Hidden psi.UseShellExecute = False Dim process As Process = Process.Start(psi)

Crossthread operation not valid… – VB.NET

The purpose of the BackgroundWorker class is to perform work on a non-GUI thread while the GUI remains responsive. Unless you set Control.CheckForIllegalCrossThreadCalls to false (which you shouldn’t do), or use Invoke as suggested in the other answers (which I also wouldn’t recommend), you’re going to get an illegal cross-thread operation exception. If you want … Read more

How to Save/Reload data in after .exe close?

Consider serialization. For this, a class is more in order than an old fashioned Struct: <Serializable> Class Animal Public Property Name As String Public Property Coloring As String Public Property VaccinesUpToDate As Boolean Public Property Species As String Public Property DateOfBirth As DateTime Public ReadOnly Property Age As Integer Get If DateOfBirth <> DateTime.MinValue Then … Read more

How to read a specific line from a text file in VB

You will have to read all lines up to the one you’re interested in. For example: Function ReadLineWithNumberFrom(filePath As String, ByVal lineNumber As Integer) As String Using file As New StreamReader(filePath) ‘ Skip all preceding lines: ‘ For i As Integer = 1 To lineNumber – 1 If file.ReadLine() Is Nothing Then Throw New ArgumentOutOfRangeException(“lineNumber”) … Read more

Control array in VB.NET

Controls in .NET are just normal objects so you can freely put them into normal arrays or lists. The special VB6 construct of control arrays is no longer necessary. So you can for example say, Dim buttons As Button() = { Button1, Button2, … } For Each button As Button In Buttons button.Text = “foo” … Read more