Menu

#30 minor problem with example

open
5
2006-05-25
2006-05-17
Anonymous
No

http://nini.sourceforge.net/Manual/NiniManual-3.htm

in the 3.3 Key Value Lists, the VB example is not valid
code. The problem is a single tick ' is the comment
character, so all the code after Split( is a comment.

The correct way to specify a single character in VB.NET
is "|"c using double quotes and a trailing c. So the
example should be

Dim serverList() As String =
source.Configs("MailServers").Get("ServerList").Split("|"c)

Discussion

  • Nobody/Anonymous

    Logged In: NO

    also on that same page further down,
    Sub SourceLoad()
    {
    source = New IniConfigSource()
    source.Saved += New EventHandler(Me.source_Saved)
    }

    Sub source_Saved(sender As object, e As EventArgs) Handles
    source.Saved
    {
    ' perform save actions here
    }

    is invalid VB.NET code too: it should be

    Sub SourceLoad()
    source = New IniConfigSource()
    AddHandler source.Saved, AddressOf Me.source_Saved
    End Sub

    Sub source_Saved(sender As object, e As EventArgs) Handles
    source.Saved
    ' perform save actions here
    End Sub

    VB.NET does not use "{" or "}", and AddHandler is used to
    add an event handler

     
  • Nobody/Anonymous

    Logged In: NO

    whups... my example is still wrong. VB.NET will not allow a
    Handles clause on the sub source_saved, unless the source
    variable was declared with the "WithEvents" keyword: so the
    handles part should just be removed (because the AddHandler
    links the two together).

    Two different ways:
    Sub SourceLoad()
    source = New IniConfigSource()
    AddHandler source.Saved, AddressOf Me.source_Saved
    End Sub

    Sub source_Saved(sender As object, e As EventArgs)
    ' perform save actions here
    End Sub

    or

    Private WithEvents source as IniConfigSource

    Sub SourceLoad()
    source = New IniConfigSource()
    End Sub

    Sub source_Saved(sender As object, e As EventArgs) Handles
    source.Saved
    ' perform save actions here
    End Sub

     
  • Nobody/Anonymous

    Logged In: NO

    Another error: on
    http://nini.sourceforge.net/Manual/NiniManual-4.htm

    section 4.3 Windows Registry Configuration, there is a
    trailing ";" in the VB.NET code...
    Dim maxFileSize As String =
    source.Configs("MyApp").GetString("SomeConfig");

    also, in VB.NET "Software\\MyApp" is a literal string... it
    will have two \ in it, unlike C# which will only have one.

    Lastly, further down the page it has
    Public Static Function Main(args() As String) As Integer

    in VB.NET, Static is not a keyword: it is Shared so it
    should be
    Public Shared Function Main(args() As String) As Integer

     
  • Brent R. Matzelle

    Logged In: YES
    user_id=163900

    You've discovered that I'm a VB.NET fraud! I, like a lazy
    author of a technical book, did not compile my examples
    before releasing them. I haven't really even written a
    single VB.NET app. I actually added it because so many
    people complained that I didn't have any.

    Thank you very much, I will definitely make those changes.

     
  • Brent R. Matzelle

    • assigned_to: nobody --> bmatzelle
     

Log in to post a comment.