Equivalent on c# to VB.net Error!

Topics: Data Access, Español
May 30, 2008 at 5:25 PM
Edited Jun 2, 2008 at 4: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 -------------------
 


Coordinator
Jun 2, 2008 at 3: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 4:22 PM
Edited Jun 2, 2008 at 4: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));   
  myMap.ZoomToExtents();
     CreateMap();  
 }
 
 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;         
  map.Layers.Add(layCountries);          
  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)))
        myMap.ZoomToExtents()
        CreateMap()
    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
        map.Layers.Add(layCountries)
        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 4:47 PM
Hi again, I make functional the vb.net sample!, tanks. only make a all new proyect without references.

regards.