How can I check if a string given is a real word? - vb.net

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)

Related

How do I find and open the most recent txt file within a subdirectory structure using 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

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

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 can i do arithmetic operations in one TextBox?

For example i write in TextBox1
4*5 or 3-2
how can make the answer appear in the same textbox ?
I tried this but it did not work anyway
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
textbox1.text = val(textbox1.text)
end sub
it just shows the first number
This is a rather complex task for which there is no built-in support in the VB.NET language. The first step is to parse the text into an expression tree. The second step is to evaluate that expression tree to determine the result. The task is certainly an advanced one for beginners, but rather than doing it yourself, there are a couple other options. You could use an existing third-party library which does all of the heavy lifting for you, such as the free open-source NCalc library. Or, you could use .NET's CodeDom classes to dynamically build the expression as a .NET library and then call it to get the result.

How to read an Atom Feed in VB.Net

I have searched and searched and searched enough until my Head aches! What I am trying to do is take an ATOM feed from here: National Weather Service Alerts and incorporate it into my program, however, I don't even KNOW where to begin :( What I want to do eventually is download the Atom feed and place it in a scrolling label. I don't want to parse it pulling out sections or anything. Just want to display the NWS alert for my area. I don't expect anyone to just write out the code or anything, but any help pointing me in the right direction for programming it simply and painlessly for an intermediate vb programmer would be greatly appreciated. Please Help!
Here is a code sample that should work for your case. Assuming you already downloaded your Atom feed and saved it to your disk. If not, you may need a slight modification:
Imports System.Xml
Imports System.ServiceModel.Syndication
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim messageList As New Generic.List(Of String)
Using feedReader = XmlReader.Create("X:\vi.php.webintents")
Dim feedContent = SyndicationFeed.Load(feedReader)
If feedContent Is Nothing Then Return
For Each item As Object In feedContent.Items
messageList.Add(Convert.ToString(item.Title.Text))
Next
End Using
lbl_warnings.Text = String.Join(vbNewLine & vbNewLine, messageList)
End Sub
End Class
Replace "X:\vi.php.webintents" with your file location.
For System.ServiceModel.Syndication to be available, you need to add System.ServiceModel.dll to your references (.NET 4.0). For .NET 3.5 you would use System.ServiceModel.Web.dll
I used this answer as a base for SyndicationFeed usage in this example.