Equivalent on c# to VB.net Error!

Topics: Data Access, Español
May 30, 2008 at 6:25 PM
Edited Jun 2, 2008 at 5:23 PM
Hi, I traduce line by line the c# sample of asp.net map and try to make a equivalent of vb.net (I work with vb.net), but the files are same and only c# sample work, vb.net equivalent not show the map on page. You can helpme with my error?.

-------------- c# sample work fine -------------------

Jun 2, 2008 at 4:31 PM
Hi ojarana,

I think the problem is your code formatting. VB doesn't like it that lines have breaks in the middle of a line, but C# is ok with this.
Jun 2, 2008 at 5:22 PM
Edited Jun 2, 2008 at 5:41 PM
hi, I have the break lines fine, this editor (this page) deformed all code, I try to send a file but can't attach a file. All code are perfect formated but work in c# and not work in vb.net, my app is in vb.net and can´t convert all to c# only by a extra function. try again to paste the code.
------ THIS WORK ------

using System;
using System.Drawing;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;

public partial class Default : System.Web.UI.Page
 private SharpMap.Map myMap;

 protected void Page_Load(object sender, EventArgs e)
  myMap = InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value,(int)imgMap.Height.Value));   
 protected void imgMap_Click(object sender, ImageClickEventArgs e)
 private SharpMap.Map InitializeMap(System.Drawing.Size   outputsize)
  SharpMap.Map map = new SharpMap.Map( outputsize);
  SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
      layCountries.DataSource = new SharpMap.Providers.ShapeFile(Server.MapPath(@"~\App_data\test.shp"), true);
        layCountries.Style.Fill = new SolidBrush(Color.Green);
  layCountries.Style.Outline = System.Drawing.Pens.Black;
  layCountries.Style.EnableOutline = true;         
  return map;
 private void CreateMap()
  System.Drawing.Image img = myMap.GetMap();
  string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
  imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);

------ THIS NOT WORK ------

Imports System
Imports System.Drawing
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.UI

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Private myMap As SharpMap.Map

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        myMap = InitializeMap(New System.Drawing.Size(CInt(imgMap.Width.Value), CInt(imgMap.Height.Value)))
    End Sub

    Protected Sub imgMap_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

    End Sub

    Private Function InitializeMap(ByVal outputsize As System.Drawing.Size) As SharpMap.Map
        Dim map As SharpMap.Map = New SharpMap.Map(outputsize)
        Dim laycountries As SharpMap.Layers.VectorLayer = New SharpMap.Layers.VectorLayer("Countries")
        laycountries.DataSource = New SharpMap.Providers.ShapeFile(Server.MapPath("~\App_data\test.shp"), True)
        laycountries.Style.Fill = New SolidBrush(Color.Green)
        layCountries.Style.Outline = System.Drawing.Pens.Black
        laycountries.Style.EnableOutline = True
        Return map
    End Function

    Private Sub CreateMap()
        Dim img As System.Drawing.Image = myMap.GetMap()
        Dim imgID As String = SharpMap.Web.Caching.InsertIntoCache(1, img)
        imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID)
    End Sub

End Class

Jun 2, 2008 at 5:47 PM
Hi again, I make functional the vb.net sample!, tanks. only make a all new proyect without references.