QB64 Phoenix Edition
Fixed STRING variables or better say semi-variables - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: Official Links (https://qb64phoenix.com/forum/forumdisplay.php?fid=16)
+--- Forum: Learning Resources and Archives (https://qb64phoenix.com/forum/forumdisplay.php?fid=13)
+--- Thread: Fixed STRING variables or better say semi-variables (/showthread.php?tid=3282)



Fixed STRING variables or better say semi-variables - TempodiBasic - 12-14-2024

Hi friends
here I share just some thinking about variable of type STRING and of FIXED lenght

in QBasic and in QB64 is possible to create variables of type STRING with a fixed lenght.
wiki di STRING

There is some little differences between STRING and FIXED STRING.
1. The last type cannot be initializated as a void string o null string because it must keep its fixed dimension.
2. the fixed string cannot add value in tail because it must keep its fixed dimension
so in runtime it cannot recursively modify itself 

please run this code to get the experience of this behaviour
Code: (Select All)

Dim a As String * 8, b As String, c As String * 2, d As Integer
' initialization to a void/null string
a = ""
b = ""
c = ""
Print "    a          c            b"
Print ">" + a + "<", ">" + c + "<", ">" + b + "<"

' filling the string variable
For d = 1 To 10
    a = a + LTrim$(Str$(d))
    c = c + LTrim$(Str$(d))
    b = b + LTrim$(Str$(d))
Next d
Print ">" + a + "<", ">" + c + "<", ">" + b + "<"
End

Can be this enough interesting to note into wiki of STRING?

thanks for feedbacks


RE: Fixed STRING variables or better say semi-variables - Pete - 12-15-2024

You can fill them to capacity with MID$...

Code: (Select All)

Dim a As String * 8, b As String, c As String * 2, d As Integer
' initialization to a void/null string
Print "    a          c            b"
Print ">" + a + "<", ">" + c + "<", ">" + b + "<"

' filling the string variable
For d = 1 To 10
    Mid$(a, d, 1) = LTrim$(Str$(d))
    Mid$(c, d, 1) = LTrim$(Str$(d))
    b = b + LTrim$(Str$(d))
Next d
Print ">" + a + "<", ">" + c + "<", ">" + b + "<"
End

Pete

- I took an IQ test. The results show I 'm re-gifted.