edit names of variables


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Posts
    72

    Default edit names of variables

    hello

    as a beginner i have a - probaply - simple problem :

    defined some variables like s1 = 12, s2 = 134 and so on

    now in a for...next loop i want do work with this variables. on each loop which is counted with "i" its necessary to take the specified variable. so on run one its s1, on run two its s2 and so on.
    because i work with a case statement to extract all the variables (i need many on each loop) i've got an code-cross-boundary-warning. (pbp 2.4.4)

    the question: is it possible to build the name of the variable on the run instead a stiff code part. some thing like "s" and counter i merged to the name of the variable "s1"? or is it possible to build an array with the values and to refernce the record on each loop?
    sorry, i can't find any information on the pbp-compiler manual...

    greetings & thanks for a help

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hein?!? Not sure if i understand everything here.

    Is it possible for you to post your code here? Will be more simple for us if we see what you made.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jan 2005
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    so the code seems so :

    FOR i = 1 TO 35 !!!
    SELECT CASE i
    CASE 1

    PORTC = s1+z1

    ....

    CASE 2

    PORTC = s2+z1

    ....



    so and this 35 times... now i had found a solution with an array.

    but i'm interested if it is possible with string manipulation too. so can i write something like that (php style) :

    CASE 3
    PORTC = "s".i+z1 ' same like PORTC = s3+z1 ?

    "s" declares a string, the point merge them with counter i and results as s3


    i have order a book about pic basic pro and waiting for. but i hadn't found a good basic reference online. does anyone know a good introduction to the syntax?

    thanks again

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    o.k. for sure you can do it with an array or if your PIC has an internal EEPROM you can use it with WRITE/READ statement
    Code:
    MyArray VAR byte[35]
    
    MyArray[0]=1
    MyArray[1]=2
    MyArray[2]=3
    MyArray[3]=4
    MyArray[4]=5
    '.....
    MyArray[34]=35
    
    Start:
          For i = 0 to 34
              PORTC=MyArray[i]+z1
          Next
    With internal EEPROM
    Code:
    Mydata var byte
    data @0,1,2,3,4,5,6...............35
    
    Start:
          For i = 0 to 34
              READ i,MyData          
              PORTC=MyData+z1
          Next
    both will do the same result. The last one will eat less of your code space. Hope this help you
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  2. Replies: 1
    Last Post: - 2nd November 2006, 23:24
  3. Variables not appearing in Watch Window MPLabv7.3
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2006, 14:36
  4. How to tell which PICs can handle 16 bit variables?
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2005, 08:44
  5. Problems with variables
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th December 2004, 18:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts