Visual Basic .NET Radio Buttons get auto-clicked

I was up until 01:20 this morning debugging code in VB.NET 2010. For hours I thought there was something amiss with my math or logic when a calculation in a secondary window which was affected by Radio Buttons kept giving an erroneous result.

The Problem – Visual Basic .NET Radio Buttons

At first I thought I was trying to use public variables in the wrong way and completely re-wrote the code only to get the same error. Eventually I found for myself by debugging with several breakpoints that when the secondary window was opened there was an automatic click on one of the Visual Basic .NET Radio Buttons (RadioButton1).

I was able to look up the problem and found it was a known issue in some circles. I was also given a hint on how to resolve it. This is my eventual code – not perfect for my purpose yet but the problem is fixed (see sidebar instructions to enlarge it):

Visual Basic .NET Radio Buttons

The Solution

Observe my comments in the code above and note that I have declared a Boolean variable “prohibitclick” as True. Then after the All_Buttons_Click subroutine is called “prohibitclick” is tested and when True the whole subroutine is bypassed. This only needs to be done once when the window is opened so after the first pass “prohibitclick” is set to False. From then on when a real click occurs the code will be executed.

Reference

The answer to the problem was found here.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.