The following code shows some minor problems in Jabaco
|
Jabaco 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
|
Option Explicit
Public Sub Command1_Click()
Dim c As Char
Dim cArr(1 To 10) As Char
Dim cArr2() As Char
Dim s As String
' initializer with scalar (= non-array) function call compiles OK
Dim i As Integer = myInteger()
' initializer for Integer() does not compile
' Dim iArr() As Integer = myIntegerArray()
' initializer for Char() does not compile
' Dim cArr2() As Char = myCharArray()
cArr2 = myCharArray()
Debug.Print "Chr(cArr(2))=" & Chr(cArr2(2))
' the following statement does not compile
' "Auto conversion 'String' to 'Char' is not supported!"
' c = Chr(65)
' Char can be set to an Integer value
c = 65
Debug.Print "c=" & Chr(c)
' what happens in an overflow situation?
' least-significant 16 bit are assigned
' higher bits are ignored
c = &H87654321
Debug.Print "c=" & Hex(c)
' CChar() seems to be the only way to set a Char to a literal String/Char value
c = CChar(Asc("A"))
cArr(1) = c
'
' cArr(1) returns the ASCII code rather than the Char
s = Chr(c) & Chr(cArr(1))
Debug.Print "cArr(1)=" & cArr(1)
Debug.Print "Chr(cArr(1))=" & Chr(cArr(1))
Debug.Print "CChar(cArr(1))=" & CChar(cArr(1))
Debug.Assert s = "AA"
Debug.Print s
s = CChar(cArr(1))
For i = 2 To Ubound(cArr)
c = cArr(i - 1) + 1
cArr(i) = c
s = s & CChar(cArr(i))
Next i
Debug.Print s
End Sub
Private Function myCharArray() As Char()
Dim cArr(1 To 2) As Char
cArr(1) = CChar(66)
cArr(2) = CChar(67)
myCharArray = cArr
End Function
Private Function myInteger() As Integer
myInteger = 999
End Function
Private Function myIntegerArray() As Integer()
Dim iArr(1 To 2) As Integer
iArr(1) = 11
iArr(2) = 22
myIntegerArray = iArr
End Function
|
Summary "wish list":
- It should be possible to initialize array variables with a function call
- Assignments of String variables to char variables should assign the first character
- Range overflows in Char assignments should be detected rather than silently chopped-off
- Char array entries should evaluate to a Char rather than to an Integer
- It should be possible to assign Char arrays and String variables to eachother
(this might require a bit of thinking! What happens if the array is too small? What happens with a null or empty String?)
Greetings
A1880