How to translate this line of code from C# to Visual Baisc
Asked Answered
D

3

5

i need some help on one line with translating this code:

Original in C#:

using System.Collections.ObjectModel;
using Microsoft.Maps.MapControl;

namespace Binding_Bing_Map_Control.Modal
{
public class MapModal
{
    public Location MapLocation { get; set; }
    public string TooltipText { get; set; }

    public static ObservableCollection<MapModal> getMapRecords()
    {
        ObservableCollection<MapModal> MapRecords = new ObservableCollection<MapModal>();
        MapRecords.Add(new MapModal() { MapLocation = new Location(47.610015, -122.188362), TooltipText = "Main St, Bellevue, WA 98004" });
        MapRecords.Add(new MapModal() { MapLocation = new Location(47.603562, -122.329496), TooltipText = "James St, Seattle, wa 98104" });
        MapRecords.Add(new MapModal() { MapLocation = new Location(47.609355, -122.189970), TooltipText = "Main St, Bellevue, WA 98004-6405" });
        MapRecords.Add(new MapModal() { MapLocation = new Location(47.615820, -122.238973), TooltipText = "601 76th Ave, Medina ,WA 98039" });
        return MapRecords;
    }
}
}

My translation to VB:

Imports System.Collections.ObjectModel
Imports Microsoft.Maps.MapControl

Namespace Map_Control.Modal

Public Class MapModal

    Public Property Location As WPF.Location
    Public Property TooltipTex As String

    Public Function getMapRecors() As ObservableCollection(Of MapModal)
        Dim MapRecords As New ObservableCollection(Of MapModal)
        MapRecords.Add(New MapModal() {Location = New WPF.Location(47, -122), TooltipTex = "Sample tooltiptext!"})
        Return MapRecords
    End Function

End Class

End Namespace

I get error in line:

MapRecords.Add(New MapModal() {Location = New WPF.Location(47, -122), TooltipTex = "Sample tooltiptext!"})

Error: Value of type Boolean cannot be converted to WindowsApplication1.Map_Control.Modal.MapModal

To clarify what am I doing. I am trying to build wpf application and use bing maps. I am following code from this link., but i am not using Silverlight and i am coding in VB.

Donnenfeld answered 5/6, 2013 at 15:12 Comment(3)
+1 for a translation question that is specific, well documented and not simply saying "convert my code for me".Contuse
+1 - same as @Evanlewis - Plus its useful as a question to link other translate questions toHyperphysical
I think everyone came here expecting another "convert all this code for me" questionRuffner
T
5

Try something like this:

MapRecords.Add(New MapModal() With {.Location = New WPF.Location(47, -122), .TooltipTex = "Sample tooltiptext!"})
Toogood answered 5/6, 2013 at 15:17 Comment(0)
T
1

I think the problem is here:

public Location MapLocation { get; set; }

This line can't be translated to

Public Property Location As WPF.Location

I think you're messing with Location class. Notice that there is not such a reference to WPF namespace in the C# version.

Tarry answered 5/6, 2013 at 15:16 Comment(1)
I am using different References. In original the reference points to 'silverlight maps api' where i am using 'wpf maps api'.Donnenfeld
I
1

The object initialiazer syntax is different in VB.Net - I used an online translator and got this:

Imports System.Collections.ObjectModel
Imports Microsoft.Maps.MapControl

Namespace Binding_Bing_Map_Control.Modal
    Public Class MapModal

        Public Property Location As Location
        Public Property TooltipTex As String

        Public Shared Function getMapRecords() As ObservableCollection(Of MapModal)
            Dim MapRecords As New ObservableCollection(Of MapModal)()
            MapRecords.Add(New MapModal() With { _
                Key .MapLocation = New Location(47.610015, -122.188362), _
                Key .TooltipText = "Main St, Bellevue, WA 98004" _
            })
            MapRecords.Add(New MapModal() With { _
                Key .MapLocation = New Location(47.603562, -122.329496), _
                Key .TooltipText = "James St, Seattle, wa 98104" _
            })
            MapRecords.Add(New MapModal() With { _
                Key .MapLocation = New Location(47.609355, -122.18997), _
                Key .TooltipText = "Main St, Bellevue, WA 98004-6405" _
            })
            MapRecords.Add(New MapModal() With { _
                Key .MapLocation = New Location(47.61582, -122.238973), _
                Key .TooltipText = "601 76th Ave, Medina ,WA 98039" _
            })
            Return MapRecords
        End Function
    End Class
End Namespace
Incessant answered 5/6, 2013 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.