User Tools

Site Tools


17.10 LCDNumber

The class LCDNumber (gb.qt4.ext) implements a component that displays the digits (digits) to be displayed like an LCD screen. In a 7-segment display element, each segment can be switched on or off. Each digit is displayed in a separate 7-segment display element. The digits 0 to 9 and a dot as well as the letters A, b, C, d, E and F are displayed in hexadecimal display mode.

The LCDNumber component is considered obsolete since Gambas 3.4. It is recommended to use the LCDLabel component → Chapter 17.16 LCDLabel instead of the LCDNumber component. The author does not share this opinion, because at least the following reasons speak for the use of the LCDNumber component - in view of the possibilities of the LCDLabel component:

  • The display of the number (type Float) can be decimal or for the subrange of integers also binary or hexadecimal!
  • By evaluating the property LCDNumber.Overflow (read-only), you are able to dynamically increase the display range by increasing the number of digits to be displayed.
  • A border can be added, which can then be formatted in four different border shapes.
  • No segments interfere in the display if they are not visible.


Figure 17.10.1: Binary display of integers with LCDNumber

17.10.1 Properties LCDNumber

The following table describes selected properties of the LCDNumber component:

LCDNumberData typeDefaultDescription
.DigitsInteger1This property is used to set or read the number of digits to be displayed.
.ModeInteger1Specifies the display mode (hexadecimal (0), decimal (1), binary (3)) or reads the mode.
.Overflow Boolean-Indicates whether the number is too large to be displayed exactly (read-only)
.SmallDecimalPointBooleanFalseDetermines or sets how the decimal point is displayed. If this property is TRUE, the decimal point is inserted between two digits.
.StyleIntegerOutlineSets or returns the style. Constants: LCDNumber.Outline (0), LCDNumber.Filled (1) and LCDNumber.Flat (2)
.ValueFloat0Sets or returns the value to be displayed in the LCDNumber component.

Table Selected Properties

3 constants are provided for the display mode:

  • 0 → LCDNumber.Hexadecimal,
  • 1 → LCDNumber.Decimal,
  • 3 → LCDNumber.Binary.

17.10.2 Example LCDNumber

In the project, the number (LCDNumber1.Value) is generated from the range [0,10] by a rotary knob (Dial component) and displayed in a component LCDNumber in decimal display mode. The same applies to the project extension where the display element LCDNumber was exchanged for an LCDLabel:


Figure Decimal display with LCDNumber

B3 LCDLabel

Figure Decimal display with LCDLabel

' Gambas class file
Private $iRatio As Integer = 10
Public Sub Form_Open()
  Dial1.MinValue = 0
  Dial1.MaxValue = 100
  Dial1.PageStep = 10
  Dial1.Step = 1
  Dial1.Value = 25
  Dial1.Wrap = False
  LCDNumber1.Digits = 3
  LCDNumber1.SmallDecimalPoint = False
  LCDNumber1.Mode = LCDNumber1.Decimal
Public Sub Dial1_Change()
  LCDNumber1.Value = Dial1.Value / $iRatio
  If LCDNumber1.Value >= 9 Then
     LCDNumber1.Background = &HFFBFBF
     LCDNumber1.Background = &HF5FFE6
Private Sub GetOverflow()
  If LCDNumber1.Overflow = True Then
     Message.Error("Die Zahl ist zu groß, um exakt angezeigt zu werden.")
     Inc LCDNumber1.Digits

The procedure GetOverflow() takes effect depending on the preset number of digits and the mode used. In the event handler Dial1.Change(), the background colour of the display element LCDNumber is changed from light green to light red when the value to be displayed reaches or exceeds the limit value 9:

B4 GrenzBereich

Figure Display in the limit range with LCDNumber


The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k17/k17.10/start.txt · Last modified: 01.10.2023 by emma

Page Tools