Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : How to put special chars in string? uM
Author | Message | ||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
How do you put special characters, for instance, quote marks or 0xff, into a string with Micromite basic? As in Visual Basic: "Here's a quote: """ As in lua: "Here's a quote: \"" Or some other way? For 0xff I don't have any idea. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
Hi Lizby. Read up on the CHR$() Function. It returns a string of the character for the code you suppply. So to take your VB example above, in MMBasic it would be "Here is a quote: " + CHR$(34) Character 34 is the ascii code for " If you want character 0xFF in your string, it would simply be ... + CHR$(255) + ... H |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
Thank you very much. Once upon a time, say 20 years ago, I knew that. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
So what's wrong with this? dim cQuote len 1 as string cQuote = chr$(34) Running it in MMBasic for DOS, because I don't have a Micromite yet. This works: PRINT Chr$(34) Giving a " PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1985 |
the syntax in your DIM is wrong. it should look like DIM STRING cQuote LENGTH 1 If you are assigning a variable to act as a shortcut so you don't have to keep typing CHR$(34) , use a CONST instead like this: CONST q=chr$(34) hth |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5905 |
MMBasic for DOS is version 4.5 which doesn't have some of the newer string abilities such as short strings. You can still do Qt$ = chr$(34) print "This is a quote "+Qt$ Using the DOS version for testing is very handy but you will need to use the correct help file. If you do want to test with a later version of MMBasic, my test device is a MX170 currently running V5.2 Using TeraTerm connect to tassyjim.ddns.net port 3002 MMEdit has the address in it under the "connect" menu You won't be ably to test displays etc which limits it's use but there are a few regular users. Jim VK7JH MMedit MMBasic Help |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
use CONST instead like this: CONST q=chr$(34) That also doesn't work in the DOS version of MMBasic. But I figured it out. The DOS version of May 2014 (latest download) accepts the command, "DIM var as string", but doesn't then accept 'var = "A"'. You have to use the "$" suffix. So this works in DOS MMBasic: dim cQuote$ len 1 as string cQuote$ = chr$(34) print cQuote$ Unfortunate, but workable until I receive my Micromites. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
Thanks, Jim, As you see, I worked it out. Thanks for the offer of your Micromite. I had seen that, but would like to get my little program working here on my laptop. Among the things that DOS MMBasic throws a syntax error for is the "DIM AS" construct. DIM AS STRING cQuote Is not accepted. Working through it. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
I tried connecting with TeraTerm, port 3002. Do I connect with SSH, Telnet, or what? No joy. Also tried connecting with MMEdit. Not exactly sure what the steps are. This is what I got: [code] Starting process... Chat closed File manager closed Connection Handle: 93194416 0 Break... sending NEW Clearing... Clearing... Clearing... Clearing... Clearing... Checking device... MicroMite Version V5.2 detected Sending C:\dl\micromite\temp.bas Blocks:28 > Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Sending #1 / 28 Transfer Aborted Saving program [/code] PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5905 |
With Teraterm, use Telnet. When you tried with MMEdit, you started of OK but the xmodem transfer didn't go too well. Your end didn't receive the <ack> for the first packet. The path between us may not be too good but xmodem is usually good. You could try connecting with a Chat session and using the upload button. That uses autosave instead of xmodem. I am getting a "port is in use" when I try here but I assume that is you. There can only be one connection at a time. Jim VK7JH MMedit MMBasic Help |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3015 |
Ok, thanks. Bedtime here, though, so tomorrow I'll try again. What will happen when I try to connect to COM1? (Default of course is nothing useful to me.) PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5905 |
COM1 had nothing connected to it but I have now fitted a loopback so anything sent out COM1 is returned. This code demonstrates the port in use: Typing slowly returns one character at a time. Faster typing keeps the characters together. I left the code on the test micromite but by the time you wake up, someone might have changed it. VK7JH MMedit MMBasic Help |
||||
Print this page |