Mar 14

Author: Ingmar Verheij

A .NET application that reads a dataset from an XML using the DataSet.ReadXML method might throw the exception : System.IO.DirectoryNotFoundException: Could not find a part of the path ‘<path of XML file>’.

According to MSDN this exception is thrown when when “part of a file or directory cannot be found” .However, this exception is not only thrown when a file cannot be found on the disk. The exception is also thrown when the structure of the XML is invalid (for instance because you didn’t close a node)

Continue reading »

Jan 24

imagesThe available official help in using a Sql Server Compact edition in a .Net program is not very extensive. In fact, it does not mention some elemental aspects that you need in order to create a database. This post will show you how to create a new database or connect to an existing one.

I assume you have already downloaded and installed the latest version of the SQL Server Compact edition, and have added a reference to it in your VB.Net project. Also, that you have imported the right namespace (System.Data.SqlServerCe).

Continue reading »

Mar 04

I’ve had to add a control to a panel in a complicated form, in which many panels overlap and are docked. Working from the VS designer it is not always clear where the focus lies or what control is selected. It’s even worse trying to figure out to which panel control I should add my new control.

So I’ve written a small recursive function that returns a TreeNode object that contains all the controls in their hierarchical structure, starting from the form itself. Together with a form that contains only a TreeView control and takes a TreeNode in its constructor, I could easily find out to which panel I had to add a control and how to dock or anchor it. Here’s the function:

Function CreateTreeNode(ByVal p_objControl As Control) As TreeNode

    Dim l_objTreenode As New TreeNode()
    l_objTreenode.Text = p_objControl.Name

    If p_objControl.HasChildren Then
        For Each l_objSubControl As Control In p_objControl.Controls
            l_objTreenode.Nodes.Add(CreateTreeNode(l_objSubControl))
        Next
    End If

    Return l_objTreenode
End Function

If you then add this node to a TreeView control, you will see how the form’s controls are structured, and you can determine where to add what!

Mar 04

I’ve been looking for a replacement for the VB6 (and QuickBasic) function String$ for ages. Usually I just use PadLeft and PadRight if I can, but sometimes that really isn’t what I want: a string that consists of a specific number of occurences of the same character—almost always a space.

Creating your own method to do this is very straightforward, but today I’ve found a little VB.Net function that does just this! It’s the StrDup function, and it takes two parameters: the number of times you want a character to be repeated, and the character:

Dim l_objFiller As String = StrDup(10, " ")

will give you a string of 10 spaces.

Oct 21

  

The string 'True' is not a valid Boolean value.  

This error is thrown when an XML file is read into a DataSet using “System.Boolean” as DataType.
Continue reading »

Mar 11

It’s possible to connect to the Performance Counters of a remote machine and retrieve the values of the different counters. But when the local language is different than the one you are connecting to, it will present you the language of the categories and counters of the local machine:

So local machine language is Dutch and remote machine is English, the categories and counters are displayed in Dutch.

This is really annoying when scripting or programming.

You can change this behaviour by changing the CultureSet (vb.net):

‘Define constants
Const strApplicationCulture As String = "en-US"

‘Set the culture of this application to the specified culture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(strApplicationCulture, False)

Ingmar Verheij & Daniel Nikolic