Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:18 06 Jul 2025 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 : Arrays when saving memory

Author Message
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 09:50am 19 Jul 2016
Copy link to clipboard 
Print this post

I have an array based on ASCII values. The lowest I want to use is a space (32) and highest is a y (121). Rather than dimensioning the array to 121, which I'm doing at the moment, I'd like to dimension it in such a way that it uses less memory. If it is possible, what is the syntax for giving an upper *and lower* bound?
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 12:12pm 19 Jul 2016
Copy link to clipboard 
Print this post

Simple... Use a -32 offset of the ASC value of the character. A SPACE (32) would yield 0 and y (121) would give you a value of 89.

--Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 12:15pm 19 Jul 2016
Copy link to clipboard 
Print this post

Herry, I am not sure that I understand your question exactly but you would dimension the array for the number of entries that you will need not the values of the entries.
Graeme
 
Herry

Senior Member

Joined: 31/05/2014
Location: Australia
Posts: 261
Posted: 12:19pm 19 Jul 2016
Copy link to clipboard 
Print this post

Graeme. No, for the purpose of another part of my code I definitely want to use ASCII as the subscripts.

I have also now found that Option base can only be set to 0 or 1

Justplayin. Yes, that is the solution I just came up with when washing my hands!

Many thanks both!
Senior?!  Whatever it says, I'm a complete and utter beginner...
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 11:34pm 07 Oct 2016
Copy link to clipboard 
Print this post

A tiny keyboard test using = as RET, < as BS and touching the text area as clr.




Print "LCD Backpack 3"
Print "tiny keyboard.bas"
Option base 1

RTC gettime
SetPin 15, intl,touched

Dim rcolor(2) = (RGB(red),RGB(yellow))
Colour RGB(blue), RGB(blue)
Dim my$=""

CLS
Font 1, 2
Box 0, 0, MM.HRes-1, MM.VRes/2-10, 8, , RGB(yellow)

initkb

Do

If kp Then
Select Case k$

Case "="
Print my$
Text 9,MM.VRes/6," ",,1,2,RGB(red),RGB(yellow)
my$=""

Case "<"
'Print "you pressed BS"
If Len(my$)<>0 Then my$=Left$(my$,Len(my$)-1)

Case Chr$(12)
'Print "clear LCD text area"
Text 9,MM.VRes/6," ",,1,2,RGB(red),RGB(yellow)
my$=""

Case Else
If Len(my$)<17 Then my$=my$+k$

End Select

Text 9,MM.VRes/6,my$+"_ ",,1,2,RGB(red),RGB(yellow)
kp=0

End If

' This is where the main work is to be done.

Text MM.HRes/2,30,Date$+" "+Time$,cm,1,2,RGB(red),RGB(yellow)

Loop


Sub touched
tx=Touch(x):ty=Touch(y)-yos
itx=(tx\32)+1:ity=(ty\32)-2

If (tx<1) Or (ty<1) Then Exit Sub
' touch text area to clear
k$=Chr$(12)
kp=1

PWM 2,1200,55:Pause 50:PWM 2,STOP 'Beep

If Not (ty =>100) Then Exit Sub

Text 10+(itx-1)*32,4+(ity+2)*32+yos,key$(itx,ity),,,,RGB(black),RGB(white)

Do While Touch(x) <> -1: Loop

Text 10+(itx-1)*32,4+(ity+2)*32+yos,key$(itx,ity),,,,RGB(black),RGB(brown)

k$=key(itx,ity)

End Sub


Sub initkb

Dim string key(10,4)= ("1","2","3","4","5","6","7","8","9","0","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","=" ,"Z","X","C","V"," "," ","B","N","M","<") length 1


yos=15


For y=1 To 4
For x=1 To 10
RBox (x-1)*32,(y+2)*32+yos, 32, 32,,RGB(yellow),RGB(brown)
'a quick patch for the space bar
If key(x,y)=" " Then RBox (4)*32,(6)*32+yos, 64, 32,,RGB(yellow),RGB(brown)
Text 10+(x-1)*32,4+(y+2)*32+yos,key(x,y),,,,RGB(black),RGB(brown)
Next x
Next y

End Sub





Edited by Quazee137 2016-10-13
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025