BBC BASIC for Windows
« variables - using already defined »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: variables - using already defined  (Read 537 times)
larry
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 2
xx variables - using already defined
« Thread started on: May 3rd, 2014, 03:54am »

Ok so total newbie to the whole BBC basic. Just started studying it a few months ago in earnest. I wrote before in various other languages and now want to try this one out.

Looked at the character definition program out of the help and compiled it to exe. Then decided to make the suggested modifications. That's where it all went south. How is it that I can create a procedure that uses already declared variables and it says no such variable? Also, how do I make global assignments. I tried the obvious command global varname, but it did not color it in like it does on keywords so I guessed that that wasn't right.


There is a variable in the original program called Grid% which acts like an array but it is never declared as such. That is the variable giving me the error when I try to use it in my procedure.
Any help received will be greatly appreciated, and once I've gotten my feet wet so to speak, I might be able to learn enough to help the next newbie out.
« Last Edit: May 3rd, 2014, 03:57am by larry » User IP Logged

Ever standing ready to snatch defeat from the jaws of victory. smiley
rtr
Guest
xx Re: variables - using already defined
« Reply #1 on: May 3rd, 2014, 09:46am »

on May 3rd, 2014, 03:54am, larry wrote:
Also, how do I make global assignments.

Variables are global by default in BBC BASIC, so any variable that you have not explicitly declared as LOCAL or PRIVATE, and is not a formal parameter, is global (see below). Sometimes, for clarity, I add a REMark listing the global variables accessed by a function or procedure, but that's only for my benefit.

Quote:
There is a variable in the original program called Grid% which acts like an array but it is never declared as such.

It is. Here is the line in which it is declared (it's the very first line of the program after the initial comments):

Code:
    DIM Grid%(8,8) 

Because it's never declared as LOCAL or PRIVATE, and is not a formal parameter, it's a global array.

Quote:
That is the variable giving me the error when I try to use it in my procedure.

My best guess is that you've added a space between Grid% and the opening parenthesis, which BBC BASIC doesn't like. If it's not that you'll need to list some code illustrating the problem.

Richard.

Note: Variable scoping in BBC BASIC is similar to what it is in C, i.e. variables can be seen by any 'inner' function unless they are explicitly declared as local. However, being an interpreted language the scope is dynamic (determined at run time) rather than the static lexical scoping of C.
« Last Edit: May 3rd, 2014, 10:12am by rtr » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls