How do I find and open the most recent txt file within a subdirectory structure using vb.net - vb.net

Using vb.net I am writing a standalone application that needs to read a value from the very latest text file written to a random subdirectory from a known directory. I need this to run on a scheduled basis so I am using the vb timer.
Despite searching the web for some time I can't seem to find any code to perform this relatively simple task without visual studio failing to compile all the examples I've tried. Surely this is quite a simple task?
Also what would be the most efficient way of doing this?
Private Sub tmrLoop_Tick(sender As Object, e As EventArgs) Handles tmrLoop.Tick
For Each TXTFile As System.IO.FileInfo In New System.IO.DirectoryInfo(Server.MapPath("\\10.179.221.125\cmsdata\GNH3D\TDD\TDD_waveradar\H1d3\"))
.GetFileSystemInfos("*.txt", System.IO.SearchOption.AllDirectories)
.OrderByDescending(Function(f) f.LastWriteTimeUTC)
.Skip(PageSize * Page)
.Take(PageSize)
MsgBox(TXTFile)
Next
End Sub
The above code doesn't like the Server.MapPath part

Related

Add ookii dialogs into a Sharpdevelop VB.NET project

When searching for an alternative to the FolderBrowserDialog, I found here answers mentionning the "ookii dialogs" librairies and I would like to use these dialogs in my project. Being very new to VB.NET, I could not find precise instructions to successfully add that to my project.
I'm not even sure if it's possible since the ookii dialogs librairies I found are coded in C# and my application is coded in Visual Basic. Is it possible? Will the included .dll work anyway?
I use Sharpdevelop 4.4.2. Here is what I tried so far :
'Add reference' and browsed to the Ookii.Dialogs.dll
'Add existing Item' and browsed to the Ookii.Dialogs.dll
'Add reference/existing item' and browsed to the Ookii.Dialogs.xml
I Though I was good because now the auto suggest function of sharpdevelop let me pin to the properties and methods of the ookii librairies but I get a "Type not defined" error when trying to compile with
Dim zzz As Ookii.Dialogs.VistaFolderBrowserDialog
Am I just missing a proper 'imports' statement?
Yes the okki dialogs work in vb.net. Check the documentation.
There is an exemple of VistaFolderBrowserDialog.
Imports Ookii.Dialogs.Wpf
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dlg As VistaFolderBrowserDialog = New VistaFolderBrowserDialog()
'show the dialogbox for the user to choose the folder
Dim folderResult As Object = dlg.ShowDialog
'you can get the selected parth with this. Here I put it in a textbox.
TexBox1.Text = dlg.SelectedPath
End Sub

Move directories checked in a CheckedListBox to another. (VB.NET)

I'm developing some software that installs mods into the Cemu emulator. I've been having some trouble lately, mainly related to the CheckedListBox.
I've broken the code for it and it's not actually working as it should anymore so I've had to resort to coming here for help...
Basically, I just want to be able to check some items in the CheckedListBox (which are listed as folder names and not their full directories) and click Install Mods to just transfer them somewhere.
I don't really have any code to represent here so I'll just show an example of what I need. :P
Image of representation.
---------------------------------------------------- EDIT ----------------------------------------------------
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.DirectoryExists("C:\CemuModManager\Mods\botw\") And cb_Games.SelectedItem.ToString = "The Legend of Zelda: Breath of the Wild" Then
For Each Folder As String In System.IO.Directory.GetDirectories(tb_ModsDirectory.Text)
clb_ModsList.Items.Add(Path.GetFileName(Folder))
Next
End If
End Sub
This is basically all I have now for the CheckListBox. I'd be nice to know if it was possible to move checked items from their directory (listed above) to another.
FYI, the following are the names of the objects:
cb_Games - ComboBox1
tb_ModsDirectory - TextBox2
clb_ModsList - CheckedListBox1
Hopefully the goal is a bit more clearer now.
Sorry about that. :/

How can I check if a string given is a real word?

I am making a program that solves anagrams in Visual Basic. How can I check if a string given by the anagram solver is a real word? I know I will have to access some sort of dictionary but I have no idea how to do this?
I need a function that checks the word to return a true/false boolean value. Is this possible?
I'm using Visual Basic in Microsoft's VS2015.
Hunspell is pretty easy to use.
Install the .net-library through Nuget (open your project in Visual Studio, then > Extras > Nuget-Package-Manager -> Console, type Install-Package NHunspell)
Download the .aiff and .dic files, see the dictionaries link on the Hunspell project page. Include these files in your project or use absolute paths.
Sample Code:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Using h As New NHunspell.Hunspell(
"...path ...\en_US.aff",
"...path ...\en_US.dic")
Me.TextBox1.BackColor = If(h.Spell(Me.TextBox1.Text),
Color.PaleGreen, Color.PeachPuff)
End Using
End Sub
Hunspell
.net library NHunspell
NHunspell C# Code Samples
If your are using WPF then checking if a word in a textbox can be done simply by checking if it has a spelling error.
Public Function WordOk(Word As String) As Boolean
return TextBox1.GetNextSpellingErrorCharacterIndex(0, Windows.Documents.LogicalDirection.Forward) < 0
End Function
If you are using windows forms then you can create a "User Control (WPF)" to do the same thing, though it is a bit tricky to explain how to do that here.
(There may be a better test than the one I showed though.. I'm not overly familiar with WPF)

Extract file using SevenZip

I'm trying to add a file unzipper to my application, so I googled a little and stumbled on the sevenzipsharp library that is able to extract the most common archive formats.
So I for testing I created a simple application with a windows form.
So the entered data is the file location C:\Users\jeee\Desktop\CriticalSubPrintout.rar and the extract location C:\Users\jeee\Desktop\Test Extract
I added some code, without any documentation.. not my strong side apparently..
Imports SevenZip
Public Class Archiver
Private Sub btnExtractArchive_Click(sender As Object, e As EventArgs) Handles btnExtractArchive.Click
Dim Extractor As New SevenZipExtractor(tbExtractFile.Text)
Extractor.ExtractArchive(tbExtractPath.Text)
End Sub
End Class
This causes an error when I try and run the code
Can anyone provide a sample code, or a link to a good example how-to-use SevenZipSharp? Because I searched and can't find any VB.NET samples.
Or maybe just help me figure out what I need to do.
Thanks.
You need to call SevenZipBase.SetLibraryPath with the path to 7z.dll, and make sure that you are using the correct version for your application (32- or 64-bit). e.g.
SevenZipBase.SetLibraryPath("C:\Dev\7z.dll")
Dim Extractor As New SevenZipExtractor(tbExtractFile.Text)
Extractor.ExtractArchive(tbExtractPath.Text)

How do you launch an .exe in a VB.net application who's directory varies amongst users?

I am creating an application for an Arma 3 server that directly launches the game and connects the user to a specific server. The problem that I am encountering, being the relatively new VB coder that I am, is that the Arma3battleye.exe directory (the .exe used to launch the game) may be installed in different directories depending on where the user originally installed it. I've developed the code to connect the user to the server if they've installed Arma in the normal location:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Process.Start("C:\Program Files (x86)\Steam\steamapps\common\Arma 3\arma3battleye.exe", "2 1 -noSplash -skipIntro -useBE -noPause -world=empty -connect=192.99.36.80 -port=2505 -mod=#Exile;#AlRayak;#AllInArmaTerrainPack;#CUP Units;#CUP Vehicles;#CUP Weapons;#CBA_A3;#TRYK's Multi-Play Unifrom's pack")
End Sub
However, after researching for many hours, I cannot determine how to have the program automatically determine the install directory of the arma3batteye.exe and then execute it with all of the correct start parameters included. Any solutions or pointers to help solve this problem would be greatly appreciate.
TLDR: What is the easiest way to program an application to automatically find the install directory of a given .exe and then execute it with the given parameters as I've done above?
Edit: Another thread similar to mine asks a similar question (how to view/get to the steam folder without hard coding it. They arrive at the conclusion that if you do (for winx32):
Dim strSteamInstallPath as String = My.Computer.Registry.GetValue(
"HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)
Or using this registry location for winx64:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam
and then were to create a button using Process.Start that it would allow you to ultimately view the directory. At this point I haven't discovered a way for that to translate into being able to execute the battleyearma3.exe from within that steam directory with the proper parameters. While it seems this code may be useful in arriving at the solution I'm looking for, I can only get the program to view the general steam directory at this time.
edit: Solution posted at bottom. Thanks to #VisualVincent who was really the one that allowed me to complete this. It really should be you having posted the correct answer, not me.
I would use the registry...
You add a key like HKEY_LOCAL_MACHINE\Software\Arma3\ServerPath = "..." when you install the server.
And whenever you need to start the client, you check up the path from that registry key.
So with the comments and tips you gave me (especially #VisualVincent) I managed to piece enough stuff together to solve my issue. Thanks to everyone for the help:
First I declared 2 variables. The first one (BattleyePath) goes into the registry as far as I can get it to dig. Executing this variable on its own will open the users steam directory. I then declared a second variable (BattleyePath2) which uses IO.Path.Combine get to the directory the users Arma3.exe is installed in:
Dim BattleyePath As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath", Nothing)
Dim BattleyePath2 As String = IO.Path.Combine(BattleyePath, "SteamApps", "common", "Arma 3", "arma3battleye.exe")
I added a couple buttons to close the program and mute the sound:
`Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Computer.Audio.Stop()
End Sub`
Finally I created the button that actually launches the game:
`Private Sub Button4_Click_1(sender As Object, e As EventArgs) Handles Button4.Click
Process.Start(BattleyePath2, "2 1 -noSplash -skipIntro -useBE -noPause -world=empty -connect=192.99.36.80 -port=2505 -mod=#Exile;#AlRayak;#AllInArmaTerrainPack;#CUP Units;#CUP Vehicles;#CUP Weapons;#CBA_A3;#TRYK's Multi-Play Unifrom's pack")
End Sub`