Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 19 / 68

Constants (Const)

This lesson covers declaring constants with VB.NET's Const, with the aim of handling values that must not change safely.

Const name As Type = value declares a constant. Once set, it cannot be rewritten later in the program — unlike a variable, attempting to change it is a compile error.

The sample code defines the maximum score as Const MAX_SCORE As Integer = 100 and uses it in a message. Writing a constant name in capitals with underscores, as MAX_SCORE, is a convention shared by many languages.

A common early stumble is choosing between a variable and a constant. Using a constant for values that do not change during the program (a tax rate, a maximum) prevents overwriting them by mistake.

In professional work, gathering fixed configuration values into constants makes the intent clear and means a change only touches one place.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)