<p>With only two days, stick to variants. VBScript works fine even though all it has is variants. Python is in effect much the same (dynamic typing where type is an attribute of the thing named rather than of the name itself) which is one of the reasons why Python has become more popular for teaching the basics of programming. By design, VBScript is a simplified version of VBA designed for light-weight programming. It is telling that when Microsoft developers were deciding how to create a streamline version of Visual Basic, they decided to just stick with variants. In 2 days you won't have enough time to delve into the semantic issues which type declarations would raise.</p>

<p>If you go this route, I would recommend still emphasizing the importance of using <code>Option Explicit</code> and explicit <code>Dim</code> statements, even though they would be in some sense superfluous. You could at least mention other types, and tell the students that if they want to master VBA programming they will need to learn about such things. </p>

<p>A compromise possibility would be to use <code>Variant</code> for non-object types but introduce <code>Range</code> and <code>Worksheet</code> variables for objects. The explicit declaration of these types might remind students that they need to <code>Set</code> the values of those variables rather than simply assign to them, and would also introduce them to IntelliSence.</p>

CC BY-SA 3.0
2017-08-26T16:13:10.577Z
2017-08-26T16:13:10.577Z
John Coleman
<p>As you are teaching business people, not computer scientists (though what I say may also be true for teaching them). I would start on the more practical.</p>

<p>Teach them stuff that is useful. <code>Date</code>, <code>Currency</code> (Don't use float types for currency, it will cost you your job, and someone a lot of money), <code>Decimal</code> (A float type with base 10 radix: it has less unexpected behaviour), and <code>string</code>.</p>

<p>Integer has some value, but manly for performance. If when doing loops you use <code>foreach</code>, then integers are not needed. Also looping is simpler and safer.</p>

<p>Booleans are only needed when doing conditionals, and conditionals are over used.</p>

<hr>

<h1>In addition:</h1>

<h2>Static or dynamic</h2>

<p>If you teach not to declare types first, then that is what you will get.</p>

<h2>Assignments</h2>

<p>We often teach assignment early, this is crazy. In structure and interpretation of computer programming, they covered almost everything I know, and then started to apologise, because they were about to introduce assignment (mutation). As soon as you introduce assignment, you make is very hard to reason about how a program works.</p>

<p>I have taught types when teaching functions. Functions take values (of a type), and return values (of a type). This in some ways looks like assignment, but is not. It is safer, and makes code easier to understand.</p>

CC BY-SA 3.0
2017-08-25T12:48:24.703Z
2017-08-25T12:48:24.703Z
ctrl-alt-delor
<p>Which variable types are the bare minimum to teach non-programmers who want to be able to create and modify simple VBA (MS Office) macros?</p>

<p>I start by showing them the concept of variables through using an Excel cell as a temporary storage, then using undefined variables, then show them a simple <code>Dim SummedValue</code> with no type declaration. Then comes the types, and I always struggle.</p>

<p><code>String</code>, <code>Integer</code>, <code>Boolean</code>, <code>Double</code> seem the most important, but maybe <code>Long</code>(integer) is better, or just <code>Double</code> is enough for all the numbers? Also, <code>Object variables</code> are important too with the <code>Set</code> statement. I don't bother showing them <code>arrays variables</code>. Or am I better of telling them to use <code>Variant</code> for everything?</p>

<p>They will be making simple macros for themselves, maybe a few colleagues. Usually start off from a recorded code. They should be able to read and comprehend other's macros too.</p>

<p><strong>Context:</strong></p>

<p>I regularly hold intensive company VBA trainings. These are typically 2 day long trainings (yes, I know, totally not optimal, but I can rarely make the organizing HR understand this). So, 2 days Beginner Training, where I teach them the basics from macro recording through modifying the existing code to the IF statement. Then in a few weeks it is followed by a 2 days long Intermediate Training. This is where I teach them the variables and loops - and make them practice a lot.</p>

CC BY-SA 3.0
2017-08-25T12:58:44.760Z
I don't have enough insight here for a full answer, but I think a valuable lesson is the danger of relying on Excel models built by amateurs for serious financial analysis. Buggy VBA can kill you. There are some horror stories around, I'm sure.
Buffy
CC BY-SA 3.0
2017-08-25T13:03:42.277Z
@Buffy Oh yeah, I have heard some of those stories during my travels. Luckily VBA is mostly used for automating mundane tasks in big corporations.
vacip
<curriculum-design><variables>
Intensive basic VBA course - which variables to teach?
# Intensive basic VBA course - which variables to teach?

(Asked by: username_0 on 2017-08-25)

Which variable types are the bare minimum to teach non-programmers who want to be able to create and modify simple VBA (MS Office) macros?

I start by showing them the concept of variables through using an Excel cell as a temporary storage, then using undefined variables, then show them a simple `Dim SummedValue` with no type declaration. Then comes the types, and I always struggle.

`String`, `Integer`, `Boolean`, `Double` seem the most important, but maybe `Long`(integer) is better, or just `Double` is enough for all the numbers? Also, `Object variables` are important too with the `Set` statement. I don't bother showing them `arrays variables`. Or am I better of telling them to use `Variant` for everything?

They will be making simple macros for themselves, maybe a few colleagues. Usually start off from a recorded code. They should be able to read and comprehend other's macros too.

**Context:**

I regularly hold intensive company VBA trainings. These are typically 2 day long trainings (yes, I know, totally not optimal, but I can rarely make the organizing HR understand this). So, 2 days Beginner Training, where I teach them the basics from macro recording through modifying the existing code to the IF statement. Then in a few weeks it is followed by a 2 days long Intermediate Training. This is where I teach them the variables and loops - and make them practice a lot.

**Tags:** curriculum-design, variables

> **Comments:**
> **username_1**: I don't have enough insight here for a full answer, but I think a valuable lesson is the danger of relying on Excel models built by amateurs for serious financial analysis. Buggy VBA can kill you. There are some horror stories around, I'm sure.  
> **username_0**: @username_1 Oh yeah, I have heard some of those stories during my travels. Luckily VBA is mostly used for automating mundane tasks in big corporations.  

---

## 2 answers

### Answer by username_3 on 2017-08-25. Score: 3

As you are teaching business people, not computer scientists (though what I say may also be true for teaching them). I would start on the more practical.

Teach them stuff that is useful. `Date`, `Currency` (Don't use float types for currency, it will cost you your job, and someone a lot of money), `Decimal` (A float type with base 10 radix: it has less unexpected behaviour), and `string`.

Integer has some value, but manly for performance. If when doing loops you use `foreach`, then integers are not needed. Also looping is simpler and safer.

Booleans are only needed when doing conditionals, and conditionals are over used.

---

# In addition:

## Static or dynamic

If you teach not to declare types first, then that is what you will get.

## Assignments

We often teach assignment early, this is crazy. In structure and interpretation of computer programming, they covered almost everything I know, and then started to apologise, because they were about to introduce assignment (mutation). As soon as you introduce assignment, you make is very hard to reason about how a program works.

I have taught types when teaching functions. Functions take values (of a type), and return values (of a type). This in some ways looks like assignment, but is not. It is safer, and makes code easier to understand.


---

### Answer by username_2 on 2017-08-26. Score: 2

With only two days, stick to variants. VBScript works fine even though all it has is variants. Python is in effect much the same (dynamic typing where type is an attribute of the thing named rather than of the name itself) which is one of the reasons why Python has become more popular for teaching the basics of programming. By design, VBScript is a simplified version of VBA designed for light-weight programming. It is telling that when Microsoft developers were deciding how to create a streamline version of Visual Basic, they decided to just stick with variants. In 2 days you won't have enough time to delve into the semantic issues which type declarations would raise.

If you go this route, I would recommend still emphasizing the importance of using `Option Explicit` and explicit `Dim` statements, even though they would be in some sense superfluous. You could at least mention other types, and tell the students that if they want to master VBA programming they will need to learn about such things.

A compromise possibility would be to use `Variant` for non-object types but introduce `Range` and `Worksheet` variables for objects. The explicit declaration of these types might remind students that they need to `Set` the values of those variables rather than simply assign to them, and would also introduce them to IntelliSence.


---

