Results 1 to 2 of 2

Thread: Do you know: Logical variables

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Do you know: Logical variables

    Zak has asked (thanks a lot for this) to improve Split function in order to split a string buffer into its single characters when String Delimiter is null. See request: http://www.thinbasic.com/community/p...hp?issueid=276

    I've already implemented it and it will be present in next release but in the meantime I've taken this request as an excuse to refresh the possibility to use thinBasic logical variables when you need to give a different meaning to a an already allocated memory area of ... whatever.

    The following example illustrates a way to consider each single byte of a dynamic string an element of a byte array and an element of a single char at the same time.

    MyArrayOfChars and MyArrayOfBytes arrays are logical arrays because using the AT clause of the DIM keyword they share the same memory location of sBuffer string.

    Important is to remember that when you change the content of a logical variable you change the content of the shared memory but when a logical variable is destroyed (because, for example, out of scope) original shared memory remain there.

    Ciao
    Eros


    Uses "console"
    Dim sBuffer As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
    Dim MyArrayOfChars(Len(sBuffer)) As String * 1 At StrPtr(sBuffer)
    Dim MyArrayOfBytes(Len(sBuffer)) As Byte       At StrPtr(sBuffer)
    Dim lCounter As Long
     
    For lCounter = 1 To UBound(MyArrayOfChars)
      PrintL Format$(lCounter, "000") & " " & MyArrayOfChars(lCounter) & " " & MyArrayOfBytes(lCounter)
    Next
    WaitKey
    
    Last edited by ErosOlmi; 06-05-2011 at 17:46.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    logical arrays ....
    this is a very usefull example, thank you Eros
    zak

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •