[mono-vb] Reporting 2 possible errors

Jan Bodnar vronskij at gmail.com
Fri Sep 17 15:47:07 EDT 2010


Hi,

I am writing a Visual Basic tutorial. Mainly I use the mono compiler. 
Examples were tested on Visual Basic.Net Compiler version 0.0.0.5914 (Mono
2.4.2 - r).
They compiled OK and worked on Visual Basic 2008 Express Edition.

While working on the tutorial, I have bumped into the 2 following errors:

********************************************************

The first one. There is a problem with a Ref keyword. 

$ ./swap2.exe 
Outside Swap procedure
a is 4
b is 7

Unhandled Exception: System.InvalidProgramException: Invalid IL code in
Example:Swap (byte&,byte&): IL_001b: call      0x0a000002


  at Example.Main () [0x00000] 




Option Strict On


Module Example

    Dim a As Byte = 4
    Dim b As Byte = 7

    Sub Main
       
        Console.WriteLine("Outside Swap procedure")
        Console.WriteLine("a is {0}", a)
        Console.WriteLine("b is {0}", b)

        Swap(a, b)

        Console.WriteLine("Outside Swap procedure")
        Console.WriteLine("a is {0}", a)
        Console.WriteLine("b is {0}", b)
        
    End Sub
    

    Sub Swap(ByRef a As Byte, ByRef b As Byte) 
        Dim temp As Byte
        temp = a
        a = b
        b = temp
        Console.WriteLine("Inside Swap procedure")
        Console.WriteLine("a is {0}", a)
        Console.WriteLine("b is {0}", b)
    End Sub
  
End Module


********************************************************

Second One

The compiler does not compile the following construct. In this example,
I want to retrieve keys and values from the dictionary.

Dim keys As Dictionary(Of String, String).KeyCollection = domains.Keys


Option Strict On

Imports System.Collections.Generic

Module Example

    Sub Main()

        Dim domains As New Dictionary(Of String, String)

        domains.Add("de", "Germany")
        domains.Add("sk", "Slovakia")
        domains.Add("us", "United States")
        domains.Add("ru", "Russia")
        domains.Add("hu", "Hungary")
        domains.Add("pl", "Poland")

        Console.WriteLine(domains("sk"))
        Console.WriteLine(domains("de"))

        Console.WriteLine("Dictionary has {0} items", _
            domains.Count)

        Console.WriteLine("Keys of the dictionary:")

        Dim keys As Dictionary(Of String, String).KeyCollection =
domains.Keys

        For Each key As String In keys
            Console.WriteLine("{0}", key)
        Next

        Console.WriteLine("Values of the dictionary:")

        Dim vals As Dictionary(Of String, String).ValueCollection =
domains.Values

        For Each val As String In vals
            Console.WriteLine("{0}", val)
        Next

        Console.WriteLine("Keys and values of the dictionary:")

        For Each kvp As KeyValuePair(Of String, String) In domains
            Console.WriteLine("Key = {0}, Value = {1}", _
                kvp.Key, kvp.Value)
        Next

    End Sub

End Module





-- 
View this message in context: http://mono.1490590.n4.nabble.com/Reporting-2-possible-errors-tp2544355p2544355.html
Sent from the Mono - VB mailing list archive at Nabble.com.


More information about the Mono-vb mailing list