Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:26 30 Apr 2024 Privacy Policy
Jump to

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 States
Posts: 3015
Posted: 11:37am 14 Jan 2017
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1985
Posted: 11:54am 14 Jan 2017
Copy link to clipboard 
Print this post

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) + ...

HEdited by CaptainBoing 2017-01-15
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 12:02pm 14 Jan 2017
Copy link to clipboard 
Print this post

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 States
Posts: 3015
Posted: 01:58pm 14 Jan 2017
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1985
Posted: 02:21pm 14 Jan 2017
Copy link to clipboard 
Print this post

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)

hthEdited by CaptainBoing 2017-01-16
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5905
Posted: 02:54pm 14 Jan 2017
Copy link to clipboard 
Print this post

  lizby said  
Running it in MMBasic for DOS, because I don't have a Micromite yet.

This works: PRINT Chr$(34)

Giving a "

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 States
Posts: 3015
Posted: 02:59pm 14 Jan 2017
Copy link to clipboard 
Print this post

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 States
Posts: 3015
Posted: 03:01pm 14 Jan 2017
Copy link to clipboard 
Print this post

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.


Edited by lizby 2017-01-16
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 05:36pm 14 Jan 2017
Copy link to clipboard 
Print this post

  TassyJim said  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

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: Australia
Posts: 5905
Posted: 05:51pm 14 Jan 2017
Copy link to clipboard 
Print this post

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 States
Posts: 3015
Posted: 06:43pm 14 Jan 2017
Copy link to clipboard 
Print this post

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: Australia
Posts: 5905
Posted: 07:51pm 14 Jan 2017
Copy link to clipboard 
Print this post

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.

  Quote   ' com port test
' com1 has a loop back installed

OPEN "com1:38400, 256, gotData, 1" AS #1

DO
k$=
INKEY$
IF k$<>"" THEN doKey
LOOP
CLOSE #1
END

SUB doKey
cmd$ =
""
DO
PAUSE 300 ' allow for slow typing
cmd$ = cmd$+k$
k$=
INKEY$
LOOP UNTIL k$="" OR k$ = CHR$(13) ' wait for CR or timeout
doCMD
END SUB

SUB doCMD
' send the entered text out com1
PRINT #1, cmd$
PRINT "sent:"+cmd$
END SUB

SUB gotData
PAUSE 200 ' wait for the rest of the data to arrive
IF LOC(#1)>0 THEN
reply$ =
INPUT$(LOC(#1),#1)
PRINT "Reply:"+reply$; ' print the reply to console
ENDIF
END SUB



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


To reply to this topic, you need to log in.

© JAQ Software 2024