Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
String Length

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
Paul Lamar



Joined: 14 May 2010
Posts: 46

Posted: 21 May 2010, 14:11 PM    Post subject: String Length Reply with quote

Hi Don,

How do I get Option StriingSize to work
I want to send out a 1500 character string without CR or LF.

This one does not work. The string is no where near 1500
characters. It is being truncated for some strange reason.
What am I doing wrong?

Thanks for all your hard work. We are making good progress.

Paul Lamar



Paul5-scre-shot.jpg
 Description:

Download
 Filename:  Paul5-scre-shot.jpg
 Filesize:  90 KB
 Downloaded:  1636 Time(s)

Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 21 May 2010, 15:36 PM    Post subject: Re: String Length Reply with quote

Paul Lamar wrote:
How do I get Option StriingSize to work
That option only affects certain types of string definitions. By default, all String variables are of the "allocated string" type. If you turn this off (Option AllocStr Off) then Option StringSize tells how much data space should be set aside for each string defined. However, it would be unwise, even if it were possible, to set the default string size to 2000 characters.

Paul Lamar wrote:
I want to send out a 1500 character string without CR or LF.
Note that String variables are limited to 255 characters maximum. See the Fundamental Data Types table. However, that limitation doesn't prevent you from sending long sequences of characters out the serial port. How you might send a particular sequence depends on the source of the data for the character sequence. An example of what I think you wanted in your test case is shown below. Note that the semicolon at the end of the Debug.Print prevents a CR/LF from being sent.
Code:
Sub Main()
  Dim x as Integer
  For x = 1 to 1000
    Debug.Print "6, ";
  Next x
End Sub

One of the challenges for people that are accustomed to writing applications for larger computers (mainframes, minicomputers, PCs) it to change the way they think about RAM use when writing a microcontroller application. On the larger computers, RAM can often be considered to be of (practically) infinite size. On a microcontroller, RAM should be considered a precious and severely limited commodity. This perspective will affect how you define your data elements and how you write the code for any particular use case.

Another possible solution is to add directly to the output queue the data that you want to send. If you were sending the data out a serial port other than Com1, you would be obliged to define and initialize the output queue and add the data directly to the queue (there is no Debug.Print equivalent for Com2). The input and output queues for Com1 are pre-defined and are not directly accessible but you can get access to the queues. The code below shows how to access the default output queue for Com1. This example code does exactly the same thing as the previous example; it just uses a different mechanism to accomplish the result.
Code:
Dim defCom1Queue() as Byte Based Register.TxQueue

Sub Main()
  Dim x as Integer
  For x = 1 to 1000
    Call PutQueueStr(defCom1Queue, "6, ")
  Next x
End Sub

If the character sequence is more complex, you can expand on the idea of the previous example. In the example code below, the first one thousand integers are output with comma separation.
Code:
Dim defCom1Queue() as Byte Based Register.TxQueue

Sub Main()
  Dim x as Integer
  For x = 1 to 1000
   If (x > 1) Then
     Call PutQueueByte(defCom1Queue, Asc(","))
   End If
   Call PutQueueStr(defCom1Queue, CStr(x))
  Next x
End Sub
Back to top
Paul Lamar



Joined: 14 May 2010
Posts: 46

Posted: 21 May 2010, 18:09 PM    Post subject: Reply with quote

I have a ZX1280n with a 64K static ram on board.
Is that not useful for storing strings?

I am not familiar with the term Queue.
Is that like a first in first out stack stored in RAM?

Thanks

Paul Lamar
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 21 May 2010, 18:46 PM    Post subject: Reply with quote

Paul Lamar wrote:
I have a ZX1280n with a 64K static ram on board. Is that not useful for storing strings?
Yes, and it is. Part of the available RAM is used for statically allocated strings (and other statically allocated variables), part is used for the execution stack (and local variables) and another part, the heap, is used for storing the content of dynamically allocated strings. As I mentioned, however, the String data type in ZBasic is limited to a maximum 255 characters, partly for historical reasons. For more information about the implementation of the String data type and details of how RAM is partitioned, see the links below.

String Data Type Details
Controlling the Heap Size and Main() Task Stack Size

Of course, you are free to create your own data structures or classes for managing large sequences of characters.

Paul Lamar wrote:
I am not familiar with the term Queue. Is that like a first in first out stack stored in RAM?
It is. For a general description of the queue data structure, see the Wikipedia Article on Queues. For information about queues specific to ZBasic, see the Section 3.4 Queues in the ZBasic Refererence Manual.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group