Gambas France BETA


Pas de compte ? Incription

MaskBox

À propos de ce code

Un exemple de nos amis allemands.
Traduction en français et italien
Démonstration des MaskBox

Code source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
' Gambas class file

PUBLIC sMaske AS STRING
PRIVATE sSubject AS STRING
PRIVATE sPattern AS STRING

PUBLIC SUB Form_Open()

FMain.Center()
FMain.Resizable = FALSE

mboxTime.Mask = "00:00" & (" Uhr")
mboxCurrency.Mask = "########0<!,00 €"
mboxColor.Mask = "&H![0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]&"
' mboxPictureSize.Mask = "### x ### px" ' Alternative
mboxPictureSize.Mask = "[0-9][0-9][0-9]x[0-9][0-9][0-9][ ]px" ' 999 x 100
mboxPoint3D.Mask = "P(!#0|#0|#0)" ' Koordinaten im Intervall 00..99

END ' Form_Open()

'*********************************************************************

PUBLIC SUB MBGroup_Activate()

SELECT LAST.Tag
CASE "T"
lblValue.Text = MBGroupCheck(mboxTime.Text, "T")
CASE "G"
lblValue.Text = MBGroupCheck(mboxCurrency.Text, "G")
CASE "F"
lblValue.Text = MBGroupCheck(mboxColor.Text, "F")
CASE "B" ' Default
lblValue.Text = MBGroupCheck(mboxPictureSize.Text, "B")
CASE "3D" ' Default
lblValue.Text = MBGroupCheck(mboxPoint3D.Text, "3D")
END SELECT

END ' MBGroup_Activate()

PUBLIC SUB MBGroup_DblClick()

MBGroup_Activate()

END ' MBGroup_DblClick()

PUBLIC FUNCTION MBGroupCheck(sMBText AS STRING, sTag AS VARIANT) AS STRING

DIM aMatrix AS String[]

SELECT sTag
CASE "T"
sSubject = Replace(sMBText, " Uhr", "")
' Stunden gibt es von 00-19 Uhr und von 20-23 und 24 Uhr ist 00:00 Uhr
' Minuten von 00 bis 59
sPattern = "^([01][0-9]|2[0-3]):[0-5][0-9]$" ' hh:mm
' sPattern = "^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$" ' hh:mm:ss mit Sekunden
IF Match(sSubject, sPattern) = TRUE THEN
RETURN "Zeit-Eingabe O.K."
ELSE
RETURN "Zeit-Eingabe falsch!"
ENDIF ' Match(sSubject, sPattern) = True ?
CASE "G"
sSubject = sMBText
sPattern = "^[ 0-9]+,[0-9]{2}( €)$"
IF Match(sSubject, sPattern) = TRUE THEN
RETURN "Geldwert-Eingabe O.K."
ELSE
RETURN "Geldwert-Eingabe falsch!"
ENDIF ' Match(sSubject, sPattern) = True ?
CASE "F"
sMBText = Replace(sMBText, "&H", "")
sMBText = Replace(sMBText, "&", "")
sSubject = sMBText
sPattern = "^[0-9a-fA-F]{6}$"
IF Match(sSubject, sPattern) = TRUE THEN
mboxColor.Text = "&H" & Upper(sMBText) & "&"
RETURN "FarbWert-Eingabe (hex) O.K."
ELSE
RETURN "Farbwert-Eingabe falsch!"
ENDIF ' Match(sSubject, sPattern) = True ?
CASE "B"
sSubject = Replace(sMBText, " px", "")
sPattern = "^[0-9]{3}x[0-9]{3}$"
IF Match(sSubject, sPattern) = TRUE THEN
RETURN " Bildgrößenangabe O.K."
ELSE
RETURN "Bildgrößenangabe falsch!"
ENDIF ' Match(sSubject, sPattern) = True ?
CASE "3D"
sMBText = Replace(sMBText, "P(", "")
sMBText = Replace(sMBText, ")", "")
aMatrix = Split(sMBText, "|")
RETURN "x = " & aMatrix[0] & ", y = " & aMatrix[1] & ", z = " & aMatrix[2]
END SELECT

END ' MBGroupCheck(...)

PUBLIC FUNCTION Match(Subject AS STRING, Pattern AS STRING) AS BOOLEAN

DIM rRegex AS Regexp
' Die Komponente gb.pcre (Perl Compatible Regular Expression) muss eingebunden sein
rRegex = NEW Regexp(Subject, Pattern)
IF rRegex.Offset = -1 THEN
RETURN FALSE
ELSE
RETURN TRUE
ENDIF ' rRegex.Offset = -1

END ' Match(...) As Boolean

Commentaires