# Dumb Visual BASIC question

**URL:** <https://boards.straightdope.com/t/dumb-visual-basic-question/451497>\
**Category:** Factual Questions\
**Created:** [June 2, 2008, 4:43pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497 "2008-06-02T16:43:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [June 2, 2008, 4:43pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/1 "2008-06-02T16:43:58Z")

</div>

I have a utility I support that’s written in Visual BASIC (6.0, if neccessary) that I’m trying to add a checkbox to. Well, the checkbox is in the dialog just fine, but I’m having trouble adding the supporting code to the appropriate source file.

Call the screen widget selectCheckbox. I try to manually add a subroutine called selectCheckbox() to the from source file, but I get a message saying an identical routine ‘already exists in an object module from which this object module derives’.

A search through the project for selectCheckbox turns up nothing. I cannot find a way to create a stub subroutine from either the graphic editor, or the properties page for the checkbox I added.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)\
**Post date:** [June 2, 2008, 5:26pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/2 "2008-06-02T17:26:36Z")

</div>

It may be that selectcheckbox is a reserved word - does it let you do it if you call it, say, SelectBanana?

---

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [June 2, 2008, 5:35pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/3 "2008-06-02T17:35:57Z")

</div>

[QUOTE=Mangetout]  
It may be that selectcheckbox is a reserved word - does it let you do it if you call it, say, SelectBanana?  
[/QUOTE]

I’ve tried several variations of the name, all with the same result. I also tried making the sub a differrent name than the checkbox itself, which failed rather spectacularly when I tried to compile.

---

<div class="post-metadata">

**Author:** ![cmkeller](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cmkeller/32/118_2.png) [@cmkeller](https://boards.straightdope.com/u/cmkeller)\
**Post date:** [June 2, 2008, 5:42pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/4 "2008-06-02T17:42:48Z")

</div>

I don’t understand that last bit - you had a checkbox with one name and a subroutine with another name, and this failed on compile?

---

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [June 2, 2008, 5:53pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/5 "2008-06-02T17:53:06Z")

</div>

[QUOTE=cmkeller]  
I don’t understand that last bit - you had a checkbox with one name and a subroutine with another name, and this failed on compile?  
[/QUOTE]

That’s me, thinking in Visual C/C++, where I can create a widget and name the service routine pretty much what I want, within bounds of a few limitations. I have a problem at times working outside of my comfort zone.

The properties page for the widgets forces the routine to be named the same as the widget itself.

---

<div class="post-metadata">

**Author:** ![VunderBob](https://avatars.discourse-cdn.com/v4/letter/v/839c29/32.png) [@VunderBob](https://boards.straightdope.com/u/VunderBob)\
**Post date:** [June 2, 2008, 7:30pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/6 "2008-06-02T19:30:19Z")

</div>

Found the answer to my problem. If I double click the widget while in the graphic edit mode, the sub is stubbed in the source code file AT THE TOP. I was trying to add it manually at the bottom.

:smack:

---

<div class="post-metadata">

**Author:** ![cmkeller](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cmkeller/32/118_2.png) [@cmkeller](https://boards.straightdope.com/u/cmkeller)\
**Post date:** [June 2, 2008, 8:03pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/7 "2008-06-02T20:03:14Z")

</div>

I’m still confused. In my experience, when you double-click a VB control to add code to it, it doesn’t create a function with the exact name of the control, but rather, with a combination of control name/event (e.g., CheckBox1\_click). Is this VB6 you’re using?

---

<div class="post-metadata">

**Author:** ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)\
**Post date:** [June 2, 2008, 10:06pm UTC](https://boards.straightdope.com/t/dumb-visual-basic-question/451497/8 "2008-06-02T22:06:27Z")

</div>

It does - if you want to attach the code to a different event of the control, you just need to switch to the ‘events’ tab of the properties inspector and select the appropriate entry there - and it will create a subroutine stub.

But the naming of that subroutine - even though VB creates it based on the name of the control, to help you understand your code - is in fact arbitrary. The click event of checkbox1 need not point to a sub called checkbox1\_click - it could be named anything (within the usual constraints, that is) - also, you can point more than one event at the same subroutine - again, but visiting the events property page for the control and selecting the subroutine against the appropriate event.
