Author Archives: Darin

Visual Basic 11 beta is out

3
Filed under .NET, Rants, VB Feng Shui

vs2010_iconlibrary

OK, It’s been a few weeks, so this is likely not “new” news, but still.

Looks like MS isn’t backing off on VB one bit, and that’s a good thing. Heck, as I understand it, there’s even a project in skunkworks build VB in VB! I’ve always said the mark of a complete language is when it’s actually written in itself.

But I digress. Back to VB 11. The VB Team website has a nice rundown of some of the high points of the release here.

 

 

 

 

To summarize:

  1. Async support. Meh. VB (actually any .net language) has always had this. The Async stuff definitely makes it easier, so I won’t complain too much. Personally, I’ve kind of gotten into the Javascript notion of lambdas for callbacks in support of async stuff. You can do that in VB, but lambda’s, being limited to single lines) haven’t been all that useful for it, up till now with….
  2. Multi-line Lambdas. That’s right, you can finally declare a Function()….. lambda that spans multiple lines.
  3. Iterators. Which basically means a Yield keyword that can fall out of an iteration loop to allow the iterating code to perform it’s work.
  4. Caller info. This is a big one for me. I’ve written more than my share of error logging/trapping/handling frameworks over the years, starting with VB3, on through VB6 and then into .net. Unfortunately, this feature has nothing to do with that!
    Caller info allows a function to easily and straightforwardly retrieve the Name, Line number or FilePath, of the calling function. While the Line number and Calling path are of dubious value, the caller name is incredibly powerful for things like front ending field accessors in data access libraries. Say you have a small function that retrieves a value from a VB, via a name. With this feature, you can easily create properties of an object that are named that name and then pass the property name down to the accessor function to retrieve the value.
    This has been doable for ever in .net as well (via the call stack), but was not straightforward and was susceptible to corruption if you used code obfuscators. No word on whether this feature will play better with obfuscators at this point, though.
  5. Call View Hierarchy. Looks like a very nice feature, but I’ll have to play with it more before making any concrete observations.
  6. Global Namespace. Another meh. On some projects, I could see this being handy. But it’s nothing to get too excited over. A very incremental improvement.

 

What’s missing

  1. Unsafe code. At least, I’ve seen no mention of it.
  2. Property-level scope. They added auto properties in VB10. Property-level scope seems like the next natural step for that. And by this, I mean:
    Public Property Name() as string
         Private _Name as string      <—– Property level scope
         Get()
                Etc
          End Get()
          Set ()
                Etc
          End Set
    End property

    EDIT: The suggestion that I posted to MS’s suggestion board ended up getting a comment from Lucian Wischik. You can read his full comments here.
    Property Scope Variables
  3. More Dynamic functionality, though you could argue that you can actually do quite a lot of dynamic stuff now in .net languages.

It’s good to see the language getting very close to parity with C#, and the news of a forthcoming VB.net coded compiler is even more exciting.

Coding in College vs a real job

0
Filed under Uncategorized

Just came across this at http://i.imgur.com/Lus4Y.png

image

Ring any bells for you? <g>

Squiggly Spell Checking in Notepad++

0
Filed under Utilities

imageNotepad++ has been a favorite editor of mine for quite some time. It’s quite capable, flexible, fast, has tons of plugins, and continues to be reasonably maintained.

But something that’s been missing is a decent spell checker. Sure there’s the available spell check plugin from the site, but that requires you click a button to spell check the document, and you have to laboriously wade through all the false positives to spell check. Sooooo last century.

However, a recent faux pas with a readme.txt that ended up with some nasty misspellings in it had me off to find something of a solution. I either had to give up Notepad++, or resolve this some other way. Misspellings are my priority 1000 issue!

Fortunately, Karim Sharif has (or rather HAD, back in 2010) come to rescue with his Squiggly Spell Check plugin.

Installation is not for the faint of heart, as it’s completely manual and requires also installing ASpell and making mods to your system’s PATH environment var, but, once it’s going, yeehaw! Nice, Word style squiggly spell check in the document types of your choice, right in Notepad++.

Granted, it’s bare bones, but it works a treat with the latest unicode Notepad++ (version 5.9.6.2 as I write this).

If you use Notepad++, it’s definitely worth checking out.

Ban SOPA/PIPA!!!

0
Filed under Rants

imageIf you don’t know about it, go here.

http://sopastrike.com/strike

Basically, SOPA/PIPA is a bill about to go before congress that could dramatically affect your ability to create new web content, as well as use existing sites freely.

For instance, do you like Craigslist.com?

Under SOPA/PIPA, Monster Cable (the company) could press to shut them down simply because people sell used Monster Cables through Craigslist and that eats away a little at Monster Cable’s revenue.

While I’m not blacking out my blog on the 18’th as many sites will be, this is definitely an important issue.

Call or email your congressman/senator now!

Windows Can’t Acquire IP Address Via DHCP

0
Filed under Troubleshooting

I’ve run into a situation a few times where, for some unknown reason, a Windows machine will be unable to obtain an IP address via DHCP.

Then that happens, the machine is likely to get an APIPA address, such as 169.254.xxx.xxx. This is known as the DHCP failover situation, and generally, it’ll mean that while you might be able to see sites out on the internet, most likely, you won’t be able to see any computers connected to your internal network (often computers on your internal network will be associated with IP addresses of 192.168.xxx.xxx).

In my case, I could set static addresses for those affected computers and they’d work fine, but reset them back to using DHCP and they’d be unable to obtain an IP address.

Googling turned up a variety of possible solutions (unplug your router, reset the IP stack by deleting registry entries, plug your computer into a different power outlet <huh?>, running IPCONFIG /RELEASE….IPCONFIG /RENEW, etc), but nothing was working for me.

On a lark, I browsed over to my router (in this case a Verizon Fios router) to check it’s configuration.

I have several routers, but the Verizon router is the only one set up to be a DHCP server (there should only be one machine, router, or actual server, on your internal network set up as a DHCP server), and it all looked good, but then I noticed something.

I had a LOT of devices showing up in the connected devices list. Many were offline, but they were still there.

This means that the router was still holding leases for them and tying up those IP addresses. Hmmmm.

I counted. 21 of them.

So I navigated to the DHCP configuration screen of the router and lo and behold, I had it set to lease addresses from 192.168.100.100 to 192.168.100.120. Exactly 21 addresses!

Ugh.

Why?

Way back when I set up this router, my thinking was “I’ll never have more than 20 devices connecting, so why should I accommodate any more than that?” so I’d limited to the available IP address range that the router would pick from.

In retrospect, I suppose that was being a little to prematurely security-conscience.

It was that limit, along with a router than apparently does not like to recycle IP leases readily, that caused me to simply run out of DHCP addresses, and thus the failure of Windows to acquire an IP address.

Moral of the Story

At the end of the day, I probably shouldn’t have limited the router to 21 addresses. It seemed like a reasonable number, but these days, with several computers in each house, plus smart phones, TIVOs, internet-connected TVs, IPADs, laptops, game systems, etc, it’s completely conceivable to have far more than 20 devices or so vying for IP addresses through DHCP.

When I exhaust the range from 192.168.100.100 to 192.168.100.200, then I’ll know I have too much tech <g>!

Authoring VB6 IDE Addins in VB.net

0
Filed under .NET, Utilities, VB6

imageOk, Ok, I know what you’re asking yourself right now.

WTF would you want to do this?

But bare with me.

Realistically speaking, VB6 has a very limited shelf life. I have plenty of VB6 apps that run just fine under Win7 (even 64 bit), but Under Win8? Who knows.

But, the truth is, there are plenty of businesses that rely on WinXP and VB6 apps today, and those businesses aren’t converting those apps to .net (or anything else) particularly quickly.

As it happens, I’m currently doing some maintenance and upgrade work on a VB6 application, and, while it IS a 10+ year old IDE, it does have it niceties and not-so-niceties.

CodeSmart, MZTools, CodeHelper, and other add-ins can certainly help, but one thing I’ve definitely missed now that I’ve worked with VS2005+ is persistent bookmarks and breakpoints.

That fact that VB6 didn’t save bookmark and breakpoint locations is a real shame.

Now, people have asked about this capability for years. I found posts going back to 2001 asking for this function, but the only utility that even came close was the open source CodeDawg project. And while I still have the source here, I can no longer even locate a link for it on the web. No matter, really, because it never did work particularly well, would miss breakpoints or bookmarks that you set sometimes, and just generally had a terribly interface.

But it was a valiant attempt!

Fast forward to today, and I’m back in VB6, working in a large and not particularly straightforward codebase, and I find myself really needing bookmarks and breakpoints that I can set and come back to the next day or whenever.

But .net provides so much simpler coding paradigms for many things now (generic collections, and direct support for subclassing anyone!) that after a few days working up a prototype add-in in VB6, I couldn’t stand it and had to see if it was possible to put something together in .net.

That’s right. A VB6 addin written in VB.net 2010!

It’s not quite finished yet, so I’ll hold off on presenting the full monty for now, but it most certainly is doable, and actually makes for a quite nice development and debugging experience.

First, fire up VS2010 and create a DLL Library project.

In the project  properties, you’ll need to make sure to check the “Make assembly COM visible”

image

Next, On the compile tab, you need to set “Register for COM Interop”

image

You’ll also need to add a reference to the VBIDE.DLL file:image

You can usually find the file under the COM tab on the Add Reference screen:

image

Finally, create a new CLASS, call it Connect, and paste this:

<ComClass("96861C1E-73A0-46E2-9993-AE66D2BC6A91", "1AEA0235-959D-4424-8231-8EBB9B9C85FE")> _
<ProgId("BookmarkSave.Connect")> _
Public Class Connect
    Implements VBIDE.IDTExtensibility

    Private _App As Application

    Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements VBIDE.IDTExtensibility.OnAddInsUpdate
        _App.OnAddInsUpdate(custom)
    End Sub

    Public Sub OnConnection(VBInst As Object, ConnectMode As VBIDE.vbext_ConnectMode, AddInInst As VBIDE.AddIn, ByRef custom As System.Array) Implements VBIDE.IDTExtensibility.OnConnection
        Try
            If _App Is Nothing Then
                _App = New Application
            End If
            _App.OnConnection(VBInst, ConnectMode, custom)
        Catch ex As Exception
            ex.Show("Unable to start addin.")
        End Try
    End Sub

    Public Sub OnDisconnection(RemoveMode As VBIDE.vbext_DisconnectMode, ByRef custom As System.Array) Implements VBIDE.IDTExtensibility.OnDisconnection
        _App.OnDisconnect(RemoveMode, custom)
    End Sub

    Public Sub OnStartupComplete(ByRef custom As System.Array) Implements VBIDE.IDTExtensibility.OnStartupComplete
        _App.OnStartupComplete(custom)
    End Sub
End Class

Now to explain a few things.

The two GUIDs you see in the first COMCLASS line, you’ll need to generate your own unique id’s for them.

Obviously, the ProgID will also need to be changed (the general convention is {addin-name.Connect}).

The Application object is my actual core addin application. I’ve intentionally kept all the addin’s code OUT of the Connect class, to keep it simple, and because this class MUST be made visible to COM so that VB6 itself can instantiate the CONNECT object (and thus kickstart your addin). Usually, the less “stuff” you have to expose to COM in a .net assembly, the better, and this represents the bare minimum.

To make debugging seamless, be sure to set the Debug Start Action to “Start External Program” and point it at your VB6.EXE file:

image

You’ll also need to make sure your addin is registered with VB6, so it will know to load it along with any other addins. You do that by creating a key like the “BookmarkSave.Connect” key below:

image

Be sure to change the “BookmarkSave.Connect” to whatever ProgID you’ve decided on.

Give it a whirl

With all that in place, you should be able to RUN your addin from VS2010, VB6 should start and your addin CONNECT object’s OnConnection method should be called.

Now it’s time to pull out my Duran Duran and SoundGarden discs and get to coding some good ol’ fashioned pseudo-OO VB6 goodness!

Determining Whether you’re in DesignMode in a Windows Phone 7 Project

1
Filed under .NET, Windows Phone 7

When you’re building usercontrols in a Windows Phone 7 project, it’s often necessary to know whether the code is running in Design Mode (i.e. being invoked by the Visual Studio IDE or by Expression Blend), or whether you’re actually running in the real program.

It’s a trivial matter, really, but it can be hard to remember exactly how to do it when I need it, so I wrapped it in an IsInDesigner function:

    Public Function IsInDesigner() As Boolean
        Return System.ComponentModel.DesignerProperties.IsInDesignTool
    End Function

Back In Business!

0
Filed under Uncategorized

Looks like I’ve finally gotten things sorted with WordPress and permalinks, the 404-handler.php and URLRewriting. Ugh. Many thanks to the guys at servergrid for being patient while I worked through all this to get things back online!

The Email Me Contact form even works again (finally!).

Direct integration of ILMerge with VB.net Projects

0
Filed under .NET, Error Handling, MSBuild, Troubleshooting

I’ve been working on a few utility type applications lately (more on them later, once they’re firmed up), but one thing I’ve found incredibly useful for certain projects is ILMerge.

If you’re not familiar with it, ILMerge is a utility that essentially can combine two or more .net assemblies into a single assembly, and reducing an application’s footprint is something I’m particularly passionate about!

In the past, I’ve always created postbuild steps that included executing ILMerge as just a command line post build process, but doing it this way has always been problematic. To start, debugging in the IDE tends to be compromised at best, and not possible at worst. Plus it just never felt clean.

In researching the problem, I ran across three blog posts that have provided more than enough info to get me past the Post Build process and actually integrate ILMerge directly into the build process itself, and one very intriguing alternative.

First, Scott Hanselman wrote about his experiences using ILMerge to merge a VB.net assembly into an otherwise C# project back in 2007. A great article and a fantastic first step.

Then, I came across Daniel Fortunov’s  article about integrating ILMerge into the VS build process. His example is also very good and a little cleaner, I’d say than Scott’s approach, but both articles are definitely worth checking out if you find yourself needing this kind of thing.

Lastly, Jeffrey Richter wrote a terrifically short but incredibly eye-popping article about a technique to load .net assemblies dynamically from binary resources baked into a single assembly at compile time. Very simple and clean. A great technique to have in your toolbox if the need ever arises.

For my part, I’ve used the ILMerge technique to merge Mono.Cecil.dll (a C# library from the mono project for directly altering .net assemblies) into a VB.net utility that can repackage portions of an assembly’s PDB file directly into the assembly’s EXE or DLL file, to supply line numbers during the rendering of an exception’s stack trace without actually have to provide a PDB (and all the additional metadata about your assembly) to your client. A fantastic debugging technique and one that I’ve been working with (off and on) for several years now. I’ll write about it in more detail later.

VB6 Menus Disabled

0
Filed under Troubleshooting, VB6

In my current job, I have to do some maintenance on some legacy VB6 code. Yeah, its archaic by .net standards, but there’s something….comforting I guess…. about VB6. I spent almost 10 years with that language, so at this point, I know it just about as good as anyone, save maybe Bruce Kenney or Matthew Curland.

At any rate, I’ve been working with it over the last few weeks and happened today to notice that the Bookmarks menu items were all disabled, even when the cursor was located somewhere where I should be able to set a bookmark. You can see the menu items in the screenshots below. Note that in these shots, then menu items are enabled properly. I didn’t think to grab clips before trying to resolve this.

image    image

At first, I thought the problem was with one of the Addins I’d been playing with (CodeSmart, MZTools, etc).

But disabling them didn’t make a difference. Of course, it’s completely possible that an addin did the damage and VB just never “fixed itself” but I have no way of knowing.

The Fix

After playing with several possibilities and even scanning through the registry, I ended up with this simple fix.

Right Click on the menu bar, select Customize, you’ll get this window.

image

For each of the items highlighted above (and the others if you suspect problems there too), click the item and click the RESET button.

That’s it!

Simple. No reboots required. You don’t even have to restart VB.