0

I got tasked with working on a project that uses Visual Basic as the language to debug some programs on an Intermec handheld scanner that runs Windows Embedded Handheld 6.5 Classic/CE OS 5.2.29217. The problem I keep running into is that I don't have a reference for data types, methods, etc. because I don't know what version of VB I'm using. Is there maybe a VB reference website that helps with backwards compatibility?

Note - I have to code this all on Visual Studio 2008 Pro because I couldn't get the program to work on a newer version of Visual Studio.

Example problem:

Public listSites As List(Of String)

...

listSites.Clear() 'This gives a NullReferenceException

In the example above, I have a global variable called listSites that should hold an array of strings. All I want to do is safely empty it out before using it, regardless of whether or not it is filled. I noticed that this variable had .Clear() in its list of available methods, but when I try to use it I get a NullReferenceException.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
TheMortiestMorty
  • 421
  • 2
  • 4
  • 12
  • 2
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Craig Feb 20 '23 at 17:51
  • That error should be independent of which version of Visual Studio you're using. If you have .NET VB code (which this appears to be given the use of a generic `List`) then I would expect it to compile fine in a current version of Visual Studio. – Craig Feb 20 '23 at 17:52
  • 1
    Why do you think the reference for data types, methods, etc is related to the version of VB.NET you are using, or to VB.NET at all? The data types, methods etc available for Windows CE programming are limited by the .NET Framework 3.5 Compact rather than the language you are using it from. You can view the data types, methods etc available in it by bringing up the Object Browser in Visual Studio, and you can press F1 there to get the help. It's especially weird for the `List(Of String)` specifically as this most basic type is available everywhere. – GSerg Feb 20 '23 at 17:52
  • 2
    @Craig VS 2008 is the last one that supports programming for Windows Mobile/Windows CE. – GSerg Feb 20 '23 at 17:57
  • 3
    `Public listSites As List(Of String)` tells it that `listSites` is a `List(Of String)`, but it doesn't put an instance of that type into the variable. If you enable [`Option Strict On`](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-strict-statement) for the project (and set it as the default for new projects) it will tell Visual Studio to point out that kind of problem, and many others, for you. It will also lead you to how to fix the problems. (You may need to investigate where to set the option in the ancient VS2008.) – Andrew Morton Feb 20 '23 at 18:05
  • _listSites.Clear() 'This gives a NullReferenceException_: As it should. You've declared it, but haven't created a new instance. Try `Public listSites As New List(Of String)` or `Public listSites As List(Of String) = New List(Of String()` – Tu deschizi eu inchid Feb 21 '23 at 04:31
  • Searching for `.net compact framework 3.5 windows ce 6.0 book` gives results. One of which is ISBN 0735624178 – Tu deschizi eu inchid Feb 21 '23 at 04:43
  • @user09938 yup, that was the problem. I was missing the `New` keyword. – TheMortiestMorty Feb 22 '23 at 16:21

0 Answers0