const string arrays

General discussion on mikroBasic.
Post Reply
Author
Message
shish
Posts: 168
Joined: 05 Oct 2006 16:01
Location: Cheshire, UK

const string arrays

#1 Post by shish » 09 Sep 2007 18:42

i'm trying to get a constant string array to work and i'm not having much luck, i'm using it for menu items to be shown on an lcd

i have 9 items of 16 chars each declared, if i omit the '[16]' it doesn't compile.

Code: Select all

     const MSG_MainPRO as String[9][16] = ("Refresh Rate","Datalog Rate","Log Mode","Save CSV File","Save BIN File","Averaging","Backlight","Datalog File","Exit")
within my code: ('Program_Value' is a byte value of the menu item i want to display)

Code: Select all

lcd_out(2,1,MSG_MainPRO[Program_Value])
it compiles but i get nothing on the display, where am i going wrong?
[i]A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams.[/i]

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: const string arrays

#2 Post by yo2lio » 09 Sep 2007 19:36

Hi,
shish wrote:

Code: Select all

     const MSG_MainPRO as String[9][16] = ("Refresh Rate","Datalog Rate","Log Mode","Save CSV File","Save BIN File","Averaging","Backlight","Datalog File","Exit")
This combinations not work in this version of MikroBasic & MikroPascal.

Work around :

Code: Select all

program case_msg

const MSG_MainPRO1 as String[16] = "Refresh Rate"
const MSG_MainPRO2 as String[16] = "Datalog Rate"
const MSG_MainPRO3 as String[16] = "Log Mode"
const MSG_MainPRO4 as String[16] = "Save CSV File"
const MSG_MainPRO5 as String[16] = "Save BIN File"
const MSG_MainPRO6 as String[16] = "Averaging"
const MSG_MainPRO7 as String[16] = "Backlight"
const MSG_MainPRO8 as String[16] = "Datalog File"
const MSG_MainPRO9 as String[16] = "Exit"

dim Program_Value as byte
    text_20 as string[20]
    
Sub Procedure Get_Msg(dim location as byte, dim byref msg as string[20])
  select case location
    case 0 msg = MSG_MainPRO1
    case 1 msg = MSG_MainPRO2
    case 2 msg = MSG_MainPRO3
    case 3 msg = MSG_MainPRO4
    case 4 msg = MSG_MainPRO5
    case 5 msg = MSG_MainPRO6
    case 6 msg = MSG_MainPRO7
    case 7 msg = MSG_MainPRO8
    case 8 msg = MSG_MainPRO9
  end select
End Sub
    
main:
  Lcd_Init(PORTD)                  ' initialize  (4-bit interface connection)
  Lcd_Cmd( LCD_CURSOR_OFF)         ' send command to LCD (cursor off)
  Lcd_Cmd(LCD_CLEAR)               ' send command  to LCD (clear LCD)
  Program_Value = 0
  while Program_Value < 10
    Get_Msg(Program_Value,text_20)
    Lcd_Out(2,1,text_20)
    inc(Program_Value)
    delay_ms(2000)
  wend
End.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

shish
Posts: 168
Joined: 05 Oct 2006 16:01
Location: Cheshire, UK

#3 Post by shish » 09 Sep 2007 19:40

thanks yo2lio

i was doing this to 'clean up' some previous code i'd written to do it, i thought it would make it much simpler... i'll just go back to what i had previously!

thanks for taking the time to write out code though!
[i]A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams.[/i]

Kalain
Posts: 1093
Joined: 11 Mar 2005 18:26
Location: Aubenas, France

#4 Post by Kalain » 09 Sep 2007 22:01

shish wrote:thanks yo2lio

i was doing this to 'clean up' some previous code i'd written to do it, i thought it would make it much simpler... i'll just go back to what i had previously!

thanks for taking the time to write out code though!
I was doing the same. (cleaning some code and got some problems)
Have a look here it will help.
http://www.mikroe.com/forum/viewtopic.php?t=11480
Alain

MAN
Posts: 437
Joined: 11 Jan 2006 18:32
Location: Brasil

#5 Post by MAN » 09 Sep 2007 22:21

Hi shish;

If you are using P16 family see this example http://www.mikroe.com/forum/viewtopic.php?t=11310 and get the Lib_MDStrArray ftp://www.ttelecom.com.br/pub/mcl_lib/ that can drive this strings constants. But if you are using P18 I suggest that you use RAM array.
at the moment, mB not drives correct multi dimensional const strings with dynamic index but this function lets you control this. Maybe this lib helps you.
Working with you, for you!
MAN

shish
Posts: 168
Joined: 05 Oct 2006 16:01
Location: Cheshire, UK

#6 Post by shish » 09 Sep 2007 22:23

thanks Kalain, it was your post that prompted me to start improving my code
[i]A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. Douglas Adams.[/i]

Post Reply

Return to “mikroBasic General”