PDA

View Full Version : How about String Variables?


mytekcontrols
- 5th November 2005, 08:43
I didn't see this one listed, and it is something that most Basics do support, but not PicBasic.

It is rather annoying having to do stuff like this:

For x = 0 to 12
LookUp x,["Hello World!"],y
Buffer[x] = y
Next x


When if you had String variables, you could accomplish the same thing like this:

Buffer = "Hello World!"


Now which would you rather do :confused:

Of course this is just getting started down that long and "stringy" road (wasn't that a Beatles song?) :).

And hey! What about some of these other nice string functions (as he drools):

<div align="center"><table width="575" cellpadding="4" cellspacing="0" border="1" bgcolor="#FFF8C7"><thead><tr><td align="center" bgcolor="#004BB0"><font color="#ffffff"><b>Function</b></font></td><td align="center" bgcolor="#004BB0"><font color="#ffffff"><b>Description</b></font></td></tr></thead><tbody><tr> <td><tt>Chr(int)</tt></td><td>Returns the ASCII character of the argument.</td></tr><tr><td><tt>InStr([start,] str1, str2)</tt></td><td>Returns the starting position of <tt>str2</tt> within <tt>str1</tt>, beginning at <tt>start</tt> if specified.</td></tr><tr><td><tt>InstrRev(str1, str2 [,start])</tt></td><td>Returns the starting position of <tt>str2</tt> within <tt>str1</tt> from the end of the string, beginning with <tt>start</tt> if specified.</td></tr><tr><td><tt>Join(list [,delimeter])</tt></td><td>Merges strings in the list, each separated by one space unless you specify a <tt>delimeter</tt> character.</td></tr><tr><td><tt>LCase(str)</tt></td><td>Returns the argument in all lowercase letters.</td></tr><tr><td><tt>Left(str, int)</tt></td><td>Returns the far-left <tt>int</tt> characters from the argument.</td></tr><tr><td><tt>Len(str)</tt></td><td>Returns the number of characters in the string. (Notice that <tt>Len()</tt> works on numeric arguments as well.)</td></tr><tr><td><tt>LTrim(str)</tt></td><td>Returns the string argument, without leading spaces.</td></tr><tr><td><tt>Mid(str, intStart [, intLen])</tt></td><td>Returns a substring of the argument, starting with the character at <tt>intStart</tt> and continuing until the entire the string is extracted or until the optional <tt>intLen</tt> characters have been extracted. <tt>Mid()</tt> is called the midstring function because it can return the middle portion of a string.</td></tr><tr><td><tt>Right(str, int)</tt></td><td>Returns the far-right <tt>int</tt> characters from the argument.</td></tr><tr><td><tt>RTrim(str)</tt></td><td>Returns the string argument, without trailing spaces.</td></tr><tr><td><tt>Str()</tt></td><td>Converts its numeric argument to a string with the numeric digits in the string.</td></tr><tr><td><tt>StrReverse(string)</tt></td><td>Returns the string argument that is completely reversed.</td></tr><tr><td><tt>UCase(str)</tt></td><td>Returns the argument in all uppercase letters.</td></tr></tbody></table></div>

Now before someone jumps down my throat, and says something like "well this and that really isn't needed" or "you know you can write some code to simulate that". Remember this is a WISH LIST, and I like to make BIG wishes :rolleyes:

gtvmarty
- 29th September 2009, 04:23
I'm in 100% agreement...perhaps the "One" thing i hate about picbasic is the severe lack of string-handling.
I would LOVE something as simple as a string buffer/variable to contain a value such as "Hello" etc.

In the meantime, who out there has other solutions for storing/handling strings???

I'm sure there's a few ways to store the string (as bytes) in the internal Ram and retrieve them as concatenated strings...

May your WISH come true :)
Marty.

mackrackit
- 29th September 2009, 06:01
I am curious about the application using a MCU where that type of string handleing :) would be needed?

The serial and LCD commands can work with strings via arrays now.
I see most people using a MCU for monitoring/control of something. Just wondering what you have in mind?

gtvmarty
- 6th October 2009, 09:40
Who would waste time with code-consuming arrays when you could use something like "Buffer = "Hello World!" as shown above.

In recent coding i've played with, i've had the need for using 2character strings, it would seem inefficient to use several for-next arrays for only 2 characters.

Why can't a buffer be assigned to xx-amount of ram locations and be given a name or symbol that can be called upon by name?

Don't get me wrong, Picbasic Pro is EXCELLENT, but has a LONG way to go ;)
I can't believe many of the simple tasks i used to do with GWbasic 25+ years ago, still isn't supported in Picbasic....

Marty.

mackrackit
- 6th October 2009, 14:02
Don't get me wrong, Picbasic Pro is EXCELLENT, but has a LONG way to go ;)
I can't believe many of the simple tasks i used to do with GWbasic 25+ years ago, still isn't supported in Picbasic....

Marty.
Wow! I did not know that GWbasic worked with the architecture of a MCU. :)

gtvmarty
- 7th October 2009, 03:32
U must have had the older version :D

Wow! I did not know that GWbasic worked with the architecture of a MCU. :)

circuitpro
- 10th October 2009, 19:43
Strings are needed ALL THE TIME! I wish PBP would face the music and implement them! Every other compiler I see has them, why not PBP? (And No, I don't want to switch because I've got years and $ invested in this one.)

mackrackit
- 10th October 2009, 19:55
Strings are needed ALL THE TIME! I wish PBP would face the music and implement them! Every other compiler I see has them, why not PBP? (And No, I don't want to switch because I've got years and $ invested in this one.)
Like I asked before, what type of project would you do that needs this?
I am not trying to be difficult, I just have not had the need beyond what is already there.

It might be fun/interesting to write a library/include to handle some of this stuff. If an example of it's usage was given I might give it a go...

circuitpro
- 11th October 2009, 05:00
Well, my last embedded project was a remote control for some specialty plasma monitors. The language used in the remotes uses exclusively strings for control. As I said before in another post, strings are a fact of life, get over it. Just as numbers, and variables, strings are used in everyday life and becoming more and more necessary for any kind of efficient programming. Rediculious little FOR...NEXT loops to parse out a string character by character are S T U P I D and a waste of time. IMO. Words are a fact of life. Adjust.

Darrel Taylor
- 11th October 2009, 06:33
Now that the "Warm Fuzzies" are flowing ... :)

With PBP 2.60 ...
The ARRAYREAD and ARRAYWRITE commands are quite useful for dealing with Strings.
<br>

circuitpro
- 11th October 2009, 19:02
Sorry, I just feel so strongly about this and struggle every time a new project comes up because of these features lacking in PBP. I guess I'm a ranter! Sorry.

Charles Linquis
- 18th October 2009, 21:11
I, too would like strings. I create extensive menus and text messages. Some of the same messages have to be output to

1. Serial Port (uses HSEROUT
2. Network Port (uses HSEROUT2)
3. LCD

Even with arrays, it is hard to output hundreds of different messages to each. Now, I duplicate the messages. Not code efficient.

tr6coug
- 11th November 2009, 01:33
Like I asked before, what type of project would you do that needs this?
I am not trying to be difficult, I just have not had the need beyond what is already there.

It might be fun/interesting to write a library/include to handle some of this stuff. If an example of it's usage was given I might give it a go...

Here's an example and something that I'm working on now. I am debugging a program that will read 3 axes of an accelerometer via A/D conversion. The sampled value is a number and I'd like to convert it to an array of text that I can send to the USB port. The pic is enumerating as a USB serial port so I can read it via a terminal program.

Anybody know an efficient way to convert a 10-bit value to a number string?

Darrel Taylor
- 11th November 2009, 02:33
Anybody know an efficient way to convert a 10-bit value to a number string? Sure ... If you have PBP 2.60?ARRAYWRITE MyArray,[DEC4 MyValue]

Or for 3-axis ...ARRAYWRITE MyArray,[DEC4 Xaxis, DEC4 Yaxis, DEC4 Zaxis]
____________
DT
http://www.pbpgroup.com/files/SIGIMG/Upgrade.gif

tr6coug
- 11th November 2009, 04:18
OK, cool.

Looks like its a good time to pay my $25 and upgrade from 2.46. BTW, I used your interrupt based USB servicing include file. Works great. Thanks for sharing that.

Darrel Taylor
- 11th November 2009, 06:30
Looks like its a good time to pay my $25 and upgrade from 2.46.
http://www.picbasic.co.uk/forum/images/icons/icon14.gif &nbsp; I should start charging meLabs a commission on upgrades. :)
BTW, I used your interrupt based USB servicing include file. Works great. Thanks for sharing that.

Excellent! You're Welcome! and thanks for the "User Review" ... :D

Cheers,

polymer52
- 30th January 2010, 12:20
Like I asked before, what type of project would you do that needs this?
I am not trying to be difficult, I just have not had the need beyond what is already there.

It might be fun/interesting to write a library/include to handle some of this stuff. If an example of it's usage was given I might give it a go...

I send a lot of strings to LCD's and some of the "STD" basic string functions would be really handy. Of coarse strings suck up a bunch of memory but Constantly used strings can be stored in EEProm and called when needed.