Drawing Maps with Visual Basic (Scott Wisniewski)

Published 26 November 07 11:35 AM

If you find yourself looking for something to do with your awesome new copy of Visual Studio 2008, you should check out the December 2007 edition of MSDN magazine. It features an article, written by me, that provides a walk through on how to visualize data on a map using VB 9, WPF and LINQ.

To give you a sneak preview of what the app described in the article does, I've included a screen shot below:

 

 

 

Over my next several posts I plan on expanding on the article by showing how you can extend the application by adding new functionality to it. For now, I will give you some time to read through the article, download the code sample, and play around with the app. In my next post I will show how you can make the application multithreaded while still taking full advantage of WPF data binding.

Enjoy!

Comments

# karlisle » Drawing Maps with Visual Basic (Scott Wisniewski) said on November 26, 2007 5:43 PM:

PingBack from http://karlisle.consulting23.info/2007/11/26/drawing-maps-with-visual-basic-scott-wisniewski/

# BELLET said on November 27, 2007 3:45 AM:

it seems that there is a Culture Sensitivity problem when running the sample as i get the exception below when i run the sample on a french PC :

System.InvalidCastException was unhandled

 Message="La conversion de la chaîne "-5396.3399246595609" en type 'Double' n'est pas valide."

 Source="Microsoft.VisualBasic"

 StackTrace:

      à Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)    à Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value)    à WpfApplication1.Extensions._Closure$__1._Lambda$__2($CLS0 z) dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Extensions.vb:ligne 33    à System.Linq.Enumerable.<SelectIterator>d__d`2.MoveNext()    à System.Linq.Enumerable.Min(IEnumerable`1 source)    à System.Linq.Enumerable.Min[TSource](IEnumerable`1 source, Func`2 selector)    à WpfApplication1.Extensions.MinDBL[T](IEnumerable`1 x, Func`2 y) dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Extensions.vb:ligne 33    à WpfApplication1.Window2._Lambda$__19(VB$AnonymousType_7`2 $VB$Key, IEnumerable`1 $VB$Group) dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Window2.xaml.vb:ligne 118    à System.Linq.Lookup`2.<ApplyResultSelector>d__3`1.MoveNext()    à System.Linq.Enumerable.<SelectIterator>d__d`2.MoveNext()    à System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)    à System.Linq.GroupedEnumerable`4.GetEnumerator()    à System.Linq.Enumerable.<SelectIterator>d__d`2.MoveNext()    à WpfApplication1.Extensions.AddRange[T](ICollection`1 col, IEnumerable`1 sequence) dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Extensions.vb:ligne 28    à WpfApplication1.Window2.LoadFile(String file, ICollection`1 list) dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Window2.xaml.vb:ligne 139    à WpfApplication1.Window2.LoadData() dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Window2.xaml.vb:ligne 38    à WpfApplication1.Window2.WindowLoaded() dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Window2.xaml.vb:ligne 107    à WpfApplication1.Window2._Lambda$__5(Object a0, RoutedEventArgs a1) dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\Window2.xaml.vb:ligne 0    à System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)    à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)    à System.Windows.UIElement.RaiseEventImpl(RoutedEventArgs args)    à System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)    à MS.Internal.FrameworkObject.OnLoaded(RoutedEventArgs args)    à System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)    à System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)    à MS.Internal.LoadedOrUnloadedOperation.DoWork()    à System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()    à System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()    à System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)    à System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)    à System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)    à System.Windows.Interop.HwndTarget.OnResize()    à System.Windows.Interop.HwndTarget.HandleMessage(Int32 msg, IntPtr wparam, IntPtr lparam)    à System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)    à MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)    à MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)    à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)    à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)    à System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)    à System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)    à MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)    à MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)    à System.Windows.Window.ShowHelper(Object booleanBox)    à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)    à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)    à System.Windows.Threading.DispatcherOperation.InvokeImpl()    à System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)    à System.Threading.ExecutionContext.runTryCode(Object userData)    à System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)    à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)    à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    à System.Windows.Threading.DispatcherOperation.Invoke()    à System.Windows.Threading.Dispatcher.ProcessQueue()    à System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)    à MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)    à MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)    à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)    à System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)    à System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)    à System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)    à MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)    à MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)    à System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)    à System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)    à System.Windows.Threading.Dispatcher.Run()    à System.Windows.Application.RunInternal(Window window)    à System.Windows.Application.Run(Window window)    à System.Windows.Application.Run()    à WpfApplication1.Application.Main() dans C:\Users\cbellet\Documents\Visual Studio 2008\Projects\MapsWithVB9WPF\WpfApplication1\obj\Debug\Application.g.vb:ligne 61    à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)    à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    à System.Threading.ThreadHelper.ThreadStart_Context(Object state)    à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    à System.Threading.ThreadHelper.ThreadStart()

 InnerException: System.FormatException

      Message="Le format de la chaîne d'entrée est incorrect."

      Source="Microsoft.VisualBasic"

      StackTrace:

           à Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)    à Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat)

      InnerException:

# BELLET said on November 29, 2007 7:47 AM:

i just had the folowing code in the WindowLoaded Sub and it was OK.

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US", False)

# VBTeam said on November 29, 2007 3:47 PM:

Bellet,

Thanks for pointing out the bug, and letting me know about the fix!!!!

# marcelo said on December 15, 2007 9:52 AM:

All I got is just a bunch of errors, is this example working?

thanks in advanced

New Comments to this post are disabled

This Blog

Syndication

Page view tracker