BBC BASIC for Windows
« Variable Program Lesson: (John-hnckleyj) »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9: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: Variable Program Lesson: (John-hnckleyj)  (Read 922 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Variable Program Lesson: (John-hnckleyj)
« Thread started on: Apr 9th, 2016, 01:09am »

Sorry John..

Just to help you get to where I am.. This is important in these forums.

Variable use is very custom.. Variables have a specific use..

So not all variable types may fit an assignment.
Here is a program that shows how different variables work:

I may not be the best here, but I do serve an interpretation that a beginner can relate to because I am one here. ( started learning BBC Basic March 6, 2016)

My interpretation might be off, but I can get correction from others. Also, keep in mind that some of the subjects I learned here took days of study and digging through all the help manuals (including the technical help in BBC).

What I am trying to share is a jump start into stuff that beginners wouldn't normally get exposure to without doing long digging sessions in manuals.

I am sure I have corrected some of the most serious habits in my programming.. Although some bad examples remain in forum. ( I may fix them later)

Also, you may want to make sure your lower case keywords in BBC is off because if you are following what I do for strategy, I like using the lower case for words like circle, line, fill, and other keywords in functions and procedures..
Using Upper case was hard for me and still is, but a person should because it has benefits..
Also, I am looking for people like you to make a community team of programmers who want to work together.
Code:
      A%=3.14
      PRINT "A% is a Global variable that only holds whole numbers. So A% was 3.14 but now is: ";A%
      A%=-1000
      PRINT "A% also will hold a negative number ";A%
      A%=+100000
      PRINT "A% also will hold a postitive number ";A%
      PRINT "***************************************************************"
      a=3.14
      a#=3.14
      PRINT "a  will hold a decimal number ";a
      PRINT "a# will also hold a decimal number ";a#
      a#=-500
      PRINT "If a# is given -500 then you will see ";a#
      PRINT "***************************************************************"
      a%=-200000
      b%=+200000
      PRINT "a% will hold a negative number ";a%
      PRINT "b% will hold a positive number ";b%
      a%=3.14
      PRINT "If a% is assigned 3.14 you will see ";a%
      PRINT "***************************************************************"
      a&= 256
      PRINT "if a& is assigned a value of 256 then a&= ";a&;" Your limit is 255, so 256 wont work"
      PRINT
      PRINT "So the undisputed champion is : a or a#.. BUT they are not global variables."
 
« Last Edit: Apr 9th, 2016, 03:40am by michael » User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: Variable Program Lesson: (John-hnckleyj)(sorry
« Reply #1 on: Apr 9th, 2016, 02:03am »

This is the best reference on Variables.

http://www.cix.co.uk/~rrussell/bbcwin/manual/bbcwin2.html#variables

If there is a conflict between what is in the earlier post and this reference, believe the content of the manual section linked.

User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Variable Program Lesson: (John-hnckleyj)(sorry
« Reply #2 on: Apr 9th, 2016, 02:05am »

Thanks.
I constructed the program from the help section and Tutorial..

It doesn't have all the examples for everything but its the variable types I use at the moment.

Here is another link

http://www.bbcbasic.co.uk/bbcwin/tutorial/chapter04.html
« Last Edit: Apr 9th, 2016, 02:24am by michael » User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: Variable Program Lesson: (John-hnckleyj)(sorry
« Reply #3 on: Apr 9th, 2016, 02:23am »

The problem I have is that bits of it are, at best, misleading.
I don't know how you gathered the information but it is how you interpreted that information that seems to be the problem.

A% is a Static Integer variable. It does not tell you anything about it being global or not. The Static variables can be made LOCAL. Most of the library routines use mainly this static integer type as LOCAL variables for speed.

The special thing about A% through Z% is that they have fixed addresses and so get accessed faster. And because the address is fixed you can do other things that you can't do with other variables, but that is beyond the scope of a beginner.

a and a# Your descriptions are the same. Yes they can both hold decimals but that is just the trivial part.

a is a variant that can contain an integer or a floating point type.
a# is a double precision floating point type.

but all of this is in the manual section linked so I need not go on.

I should point out that the Tutorial's published date is 2006. BB4W has been updated many time since then so that there are more types and different precision in BB4W 6.02a than in the version that was in effect when that was written. The manual is the more up to date reference. The tutorial is mainly a "how to" and is still correct in that regard. The numerical result may be different because of the increased precision available now. That may not have been obvious, but now you know, and so can avoid any errors of interpretation because of this.
« Last Edit: Apr 9th, 2016, 02:37am by Zaphod » User IP Logged

Zaphod
Guest
xx Re: Variable Program Lesson: (John-hnckleyj)
« Reply #4 on: Apr 9th, 2016, 2:52pm »

I think it would be helpful if people took notice of this.

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin2.html#conventions

Of course, your programs will work for you without adhering to this formality. However, it might help others to understand the code without too much work. More importantly it would allow the Cross Reference Utility to be useful to you.

In Richard's absence I would like to ask that people posting programs run the Cross Reference Utility on them before posting and look for the warnings and details it produces. It will pick up or highlight many potential errors, typos, unused variables and so on. It would show the potential for names that maybe won't work with LOWERCASE keywords set. It is a very valuable tool that will often show up the problem you are having. And if the program passes the 'test' without warnings you have probably got a program that will make sense to others.
It does not check for logic errors, of course, but it often picks up the 'silly' mistakes that we all make.
It will tell you when variables are global, local or shared so you can think about the scope of the variables.

If anyone has a reference about how to use the 'scope' of variables in BB4W that would be useful to append or post. Or does anyone want me to write something?
User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Variable Program Lesson: (John-hnckleyj)
« Reply #5 on: Apr 9th, 2016, 5:16pm »

Can I reinforce Zaphod's comment? While everyone is welcome to program in their own style, it makes help more helpful if it has a standard format, and doesn't make assumptions like lowercase keywords (or not). Using correct scoping of variables is a good habit to get into, though I admit I often don't! I try to be good when I post here, though....

I'm pleased to see people offering, and accepting, help though - I think we need to work together to keep BB4W active.

Zaphod, if you want to offer us a brief guide to scope, I'm sure that would be valuable to lots of us.

Best wishes,

D
« Last Edit: Apr 9th, 2016, 5:17pm by DDRM » User IP Logged

hinckleyj
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 14
xx Re: Variable Program Lesson: (John-hnckleyj)
« Reply #6 on: Apr 10th, 2016, 8:46pm »

Thanks to Michael and Zaphod for all your help.

Appreciate the time you guys have taken to put this information up here.

Regards,

John
User IP Logged

hinckleyj
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 14
xx Re: Variable Program Lesson: (John-hnckleyj)
« Reply #7 on: Apr 10th, 2016, 8:50pm »

on Apr 9th, 2016, 2:52pm, Zaphod wrote:
If anyone has a reference about how to use the 'scope' of variables in BB4W that would be useful to append or post. Or does anyone want me to write something?


That would be most helpful if you have time?

Many thanks

John
« Last Edit: Apr 10th, 2016, 8:51pm by hinckleyj » User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Variable Program Lesson: (John-hnckleyj)
« Reply #8 on: Apr 11th, 2016, 12:51pm »

Here is the latest post on the scope of variables..

http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1460304820

( I would note that libraries have some Global variables too, and I am just working out what they are and what commands they are associated with in windows commands)
User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: Variable Program Lesson: (John-hnckleyj)
« Reply #9 on: Apr 11th, 2016, 2:05pm »

That is correct, you can have Globals in Libraries but it isn't very common and you would use names that would not occur in the user program.
Richard uses the @ in the name such as Q@% say, with the assumption that users don't use @ in variable names so there won't be a clash.

Eventlib has globals for the event queue, and Comlib has globals for transferring variant data but I don't think many others do, although I am sure there are some. They do use system variables which are, of course, global as being part of the language implementation and are predefined.

If you find yourself having to use several assigned globals in a library you are probably not on the right lines and it would be better to reorganize the code. The need for assigned globals in correctly written libraries is quite unusual.
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