Page 1 of 2

learning PureBasic

Posted: Tue Sep 11, 2012 6:35 am
by oldefoxx
I'm just setting into learning PureBasic. Being an old hand at other BASICs, I found it
a bit hard to figure out where to start, because it is quite different in terms of the
syntax and names used from what I've dealt with before. It's almost like there
should be included a cross-reference between terms found in other BASICs and those
adopted for PureBasic to simplify the task of relearning as you progress.

PureBasic is not just a change in terms, but a refinement in what you get. That can
translate into "no exact parity" to "markably improved" over what you had before.
It's no exaggeration to say that you can end up with shorter source code, but then
in looking at source code, you have to read more into what you see to understand it.

The way I am making progress right now is unusual for me. Normally I begin with
some of the example or sample code, compile it, run it to see what it does, then take
a look at the guts of it to see what happened. But that was not working for me with
PureBasic, because I did not understand enough of what I saw to really pick up on it.

What I am doing now instead is reading through the Help system, portion by portion.
Something is underlined in blue, meaning it is a link to another portion, I make sure
to follow it when I've finished reading this part. Then I use the browser Back arrow
to go back until I am back in the Help section, and I go on to the next portion. I'm
not trying to memorize all this, I am just making note of what seems significant.
Once I get the feel for an area, I go on with the expectation that I can find my way
back when I need to later.

Something else the Help section is good for, is that often the example or sample
programs are embedded right in the Help file itself. You can copy and paste these
examples into their own files using the Editor, then compile and run them, and
that works pretty well.

But there is a gap. A series of programs that gradually introduce more aspects of
the language as you progress from one to the next. It's almost a crime that the
first program that most people get exposed to does nothing more that put the
words "Hello World!" on the screen in some manner. It should have at least asked
for a name from the person at the keyboard and said "Hello" to them as well. That
would have linked the ability to do I/O together in a personalized way.

The second program probably should have done something with numbers, as this
is a common use of computers, and as a consequence, worth pointing out. The
third program should have switched to handling strings and dealing a bit with
their contents and how they can be extracted, manipulated, identified, and put
to use. Perhaps the rudiments of putting together an address book.

The fourth program should delve into working with files, how to find them, how
to recognize their possible nature, how to open them, how to read their contents,
how to open output files, how to write to them, so that the nature of reading
and writing with files is essentially covered.

The fifth program probably should work to bring the first four chapters together
in a project, Actually making an address book program would be one purpose,
or getting into the matter of file tracking, working with drives and directory
structures, doing backups and restores, might be worthwhile objectives. You
might need several chapters to cover this area well.

I would expect that at some point the attention would turn to other areas,
such as:
(1) Communications between peers or client/server arrangements, and
the PCP/IP and UDP protocols. There was a time when serial and parallel
port protocols were called for as well, but I suppose it boils down to USB
now.
(2) Game Programming. This is not my area of interest, but it certainly
appeals to many.
(3) Video and audio applications. Goes beyond the scope of games, can
involve movies, clips, music, special effects, working with photographs,
creating or modifying new or existing expressions of art.
(4) Other areas where computers have gained at least a stephold. One
example might be robotics, or machines controlled by computers and
their software. Data mining, which is searching existing avenues of
communications for relevant data that can be extracted, stored, and
processed for later use.
(5) There is the benefits of making use of the mediums by which data
is being exchanged. The wireless world, or wired networks as examples,
and creating new and better tools to exploring or protecting these.

Here is something I've learned about programming that I have never
found expressed anywhere. It might take 8 times the effort to come up
with a suitable program to carry out a routine task, but the payback is
being able to use that program well into the future, which not only
saves time and effort, but let's the user capitalize on the very best
that the program developer was able to achieve in programming and
testing it to satisfaction. The developer had to come up to a high
degree of comprehension in what goes into doing the task to be able
to write a program to meet that objective, and this is going to be
reflected every time that program is used, even if used by someone
totally unfamiliar with the task or how to do it themselves.

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Tue Sep 11, 2012 1:32 pm
by spikey
Some work on a beginners guide has already been done and you can find the results in the help file, and it does cover many of the areas that you discuss - but its not that easy to find at the moment. You have to go to the Reference Manual's home/link page entry and look for the article titled "User guide - overview".

I raised this issue with Andre last week when I came to retest the sample code under the latest beta and he agreed with me and said he would talk to Fred about it too, with any luck this will lead to a change...

I had writers block when it came to an article for string manipulation though as I couldn't really think of anything to include that wasn't included in the help articles for the individual string functions already - suggestions welcome...

Kale also released his PB beginner's book under the creative commons license - however that license precludes it being incorporated into the PB package as I understand it, but have a look at http://www.purebasic.fr/english/viewtop ... 14&t=37059 Read the caveats carefully though as it was written for an earlier version and the sample code is no longer fully up to date.

Krylar wrote a book on programming 2D games - he's just in the process of updating it.
http://www.purebasic.fr/english/viewtop ... 16&t=41122

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Tue Sep 11, 2012 4:30 pm
by BorisTheOld
oldefoxx wrote:I'm just setting into learning PureBasic. Being an old hand at other BASICs, I found it
a bit hard to figure out where to start, because it is quite different in terms of the
syntax and names used from what I've dealt with before. It's almost like there
should be included a cross-reference between terms found in other BASICs and those
adopted for PureBasic to simplify the task of relearning as you progress........
We've had the same experience, but luckily my experiences with Assembler, macro languages, and language conversion programs, have given me some insights into why PB is the way it is.

It only took us a few weeks to get used to the syntax and to the rules for passing pointers to procedures. In fact, as soon as we had the "light bulb" moment we could see all kinds of capabilities that were not immediately apparent -- such as implementing OOP.

Our single biggest issue is not with the PB language, but with the help files. To be honest they are poorly organized, incomplete, and quite un-helpful. And there seem to be subtle differences between the online version, the IDE versions, and the standalone versions.

For example, look at the section on structures. Lots of examples and some links to SizeOf and ClearStructure. Ok so far, so follow the link to ClearStructure and one comes to a page called Compiler Functions (whatever they are!). Scroll down to the bottom of the page and one finds not only ClearStructure, but InitializeStructure and CopyStructure. Oops, that's the first I've heard about those, so let's look in the index. And what do we find? Nothing - for all three. We only realized that InitializeStructure existed when we saw it somewhere in a small piece of code -- and I can't even remember where.

So because of this we've been putting together our own in-house help file. We've also been assembling a list of reserved words, since we can't rely on the help index to be complete. But PB isn't alone in having poor documentation. Gambas, FreeBasic, Q7Basic, and many more, are just as bad. Sadly, gone are the days when software documentation filled an entire shelf and was actually helpful.

PB is a powerful language that can be used for professional grade applications. It's too bad that the sloppy documentation makes it look amateurish.

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Wed Sep 12, 2012 5:21 am
by oldefoxx
I began a substantial reply that really got into some of the areas where string
processing can have a substantial benefit, and I was including code as well.
PureBasic has changed some since I really worked with it last, and I have quite
a bit to relearn in order to do well at this. That is one of my objectives now.

I liked HotBasic because it really combined the old QuickBASIC with the newer
RapidQ, sort of giving you the best of both worlds in terms of syntax and words
used. But HotBasic has inherant flaws that only become apparent with continued
and extended use, and the developer is so hyped on having it together that he does
not listen to criticism now, so the only thing to do is leave it and go on. This is not
my opinion alone. If a compiler is unable to give you consistent results with the
code you develop, then you waste a lot of time searching for problem sources and
trying to find fixes for what should not be a problem in the first place.

I've much higher hopes for PureBasic. Looking it over in some detail, I find that it
pretty much has it all together. It's a bit more expensive than HotBasic, but I believe
you are getting more for your buck. Way more if you are looking for a wide variety
of possible applications, libraries, and yet an easy to learn consistency in what it
does and how it works. I just expect or hope that the stability is there when I get
into actually pulling together applications. I believe it will be, because PureBasic
seems to get high marks for many things, and it has been around for awhile now.

But if I had to be frank about it, I would have to say that it is less of a BASIC dialect
than it is its own unique method of pulling in elements of writing code and getting
them to fit together. One aquaintence describes is as a cross of Basic and C++, by
which he means the power of C++ but the readability of a terse form of Basic
Whatever its roots, it looks do-able. Now you might need to focus on learn-able.

Here is the thing about processing strings. You have to know what the either have
in them, or you need to know what to expect that might be in them. You ask a person
for their name and do an input, you expect to get back their name. If you want just
the first name, then ask for the first name. If you want the name they go by, then
you should ask for something like "What name are you known by? ", so that you get
their handle or nickname instead.

If you look at source code in a text file, you probably need to know that it is from a text
file but that it is source code. Why? Because then you can process the contents of the
file in accordance with rules of the language that makes use of it. Many BASICs make
the mistake of having their source files have the extension of .BAS, unless they are
include files, in which case they may have the extesion of .INC. But the rules for all
BASICs is not the same, and if you do not know the rules for the BASIC that this .BAS or
.INC file was intended for, you cannot police the file properly and render its contents
correctly. PureBasic instead uses the extension .PB for its source files, or .PI for its
include files. The only BASIC it might get confused with as far as extensions go is
PowerBasic, which has the same initials, but most PowerBasic users still use the BAS
and INC that other BASICs use. So it is a good distinction that sets PureBasic apart.

But why care about source files and include files anyway? Well, the PureBasic editor
does something that not all other BASIC editors are able to do. It identifies PureBasic
keywords and renders them into a preferred case and color so that they stand out. If
you wanted an editor for another BASIC to do the same, you would probably end up
having to write your own formatter (a.k.a. reformatter) to do the job. Think of all that
this would entail: Searching the source or include file for keywords, so having a complete
list of keywords to use for the purpose. Having a version of the list ready in the case
that you want to use anything from it. Making replacements everywhere indicated. And
oh, by the way, skipping over string constants and comments when you do this. Those you
do not want to change.

.Is there anything else that a formatter/reformatter might need to do? Well, indentation
of lines can help make source code more readable, and this involves rules as well. You
might want all non-keywords set to either UPPER or lower case, to make them more evident
as well. Fine. Any rules you want. After all, this is your formatter or reformatter, right?

But let's move on. Say there is some office paperwork that you wanted to have the PC
file in a large datafile on one of your drives. How is it going to manage that? First, you
have to get it into the computer in electronic form. There are scanners for doing this, but
they only scan in a full detail picture of the document. Characters are not characters in
this mode, they are just collections of black, white, gray, or various colored dots, what we
call pixels (for picture elements). You can file the picture away, but you cannot search for
it, because none of the information on it can be read by the computer in this format. What
you find you must do is use OCR (Optical Character Recognition) software with the scanner
to get at least some of its contents into character codes that the PC software can work with.

If the OCR software is good, and the document is clean and has high contrast as well as good
layout, you might get perhaps 98% of its contents into character format inside the PC. Now
there are many factors here that can make it harder, such as a difficult to read font, the font
is too small or too large, the contrast between letters and the background is too low, and
the paper may be somewhat smudged or defaced, and some of the characters may be missed
outfight or translate incorrectly. You can sit down with a keyboard and monitor and the paper
afterwards and make manual corrections, but this can be a long and tedious job. You may
decide to skip it and have the PC file it as best it can.

Here is the thing: What is the computer going to do next? Only your program knows, and that
depends on what you programmed it to do. So what would you expect it to do next? Now
remember, you have most of the contents of the document in a text file now, so you can try
to examine those contents for anything that can help. How about dates and phone numbers?
Those are often good choices: Dates might have a format like Jan 12, 2012 or 1/12/2012 or
01/12/2012 or maybe 01-12-2012. You could probably think of a few more date formats as
well. Phone numbers have their own formats, like (832)-943-2105, 832-943-2105, or even
832.943.2105, or if it is a local number, just 943-2105. The trouble is, all the possible number
combinations make it difficult to narrow down your search for these. The trick is, to change
the letters into just one or two letters, and all the digits into just one digit. Suppose we
change the letters "BCDEFGHIJKLMNOPQRSTUVWXYZ" into "A"s, and the small letters
"bcdefghijklmnopqrstuvwxyz" into "a"s instead. Then we change "012345678" into "9"s.

The first date now becomes "Aaa 99, 9999". It's not so hard to recognize that might be a date.
If you also allow for "Aaa 9, 9999", you have an excellent chance of pinpointing a date. If you
go further and allow for "9/9/9999", "99/9/9999", and "9/99/9999", you have a good chance of
catching a date if there is one there. Of course someone could enter "January 12. 2012, and
all your efforts would be in vain. Unless you also allow for Aaaa " to "Aaaaaaaaa" as possible
indicators of a month's name. I mean there is no majic way of doing this stuff, you have to
focus on all the variations that you might have to expect.

I'm going to do this part in blocks so that you might get a better idea of what could be a
treasuretrove of information about the document you want to file:

Code: Select all

                                                                                           Aaaaaaa 9, 9999
     
                                                                                             A. A. Aaaaaaa
                                                                                        AAAAAAA, AAAAA, &
                                                                                           AAAAAAAAA A.A.A.
                                                                                         999-A  Aaaaaaaaaa AA
                                                                                   Aaaaa Aaaaaaa, AA 99999-9999


Aaaaaa A. Aaaaaaaaa
9999 A 99aa Aaa.
Aaaaaaaaaaaa,AA 99999
                                                                                        aa:AA999-9A9-A99A-9999
Aaaa Aa. Aaaaaaaaa,

Aaaa aa aa aaaaaa aaa aa aaa aaaaaaa aaaa aa aaaa aaaaa-aaaaa Aaaaaaa Aaaaa Aaaaaaaaa aaa aaaaaa
You may consider the above to be totally unreadable, but actually your trained eye should pick out certain
things that you could program for as you prepare the document for filing. For instance, can you discern a
possible date? How about a likely return address? How about the likely name of the person who decided
to send this letter to you? How about the address it was addressed to? How about a possible reference
number that might be important later? Even without being able to view the original at this point, you have
quite a bit of data already to associate with this filing. By going back to the original, the program can copy
what appears to be important over to a header for the file, making it easier to find it later using an
appropriate search tool.

We are only scratching the surface of what string processing can involve. One area that really bothers a lot
of people is the idea of data mining, of taking the correspondence that takes place continuously over the
internet and stripping it down to what many people consider to be essentially personal information and either
using that themselves or selling it to other parties so that they can make use of it. When the Social Security
system was set up, the law guaranteed that the SSAN we each get would never be used for personal
identification. But laws change, and now it's either your SSAN or your driver's license, and in some states,
it amounts to the same thing

Data mining is treated as a legitimate business interest, but it has been abused, there is no doubt of that.
What it is is taking data, which comes in character strings, and getting something out of it. For instance,
there is all sorts of new discoveries and news coming out each day, and we are overwhelmed with the
sheer extent of new things to learn. How do you keep up? Where do you start? The answer to questions
like that may rest in a programmer's hands somewhere, and it may be up to him, or her, to take us to the
next level. Now you might expect that this is more likely to happen for an existing or future hand held
device of some sort, but those devices have their limitations to deal with. They may work well for people
continually on the go that have slack time periods to fill in, but a real computer such as a laptop or
desktop offers many advantages that can come into play in the right hands.

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Wed Sep 12, 2012 8:03 am
by Josh
@oldefoxx

I don't know, but i think since about 30 years we use continuous text on computers. That means, that you make a manual line break only at the end of a chapter.

In this case, your detailed texts would also be readable for people, don't use the browser in full screen.

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Wed Sep 12, 2012 2:07 pm
by spikey
I think the point of this topic is getting a bit lost now...

Yes its possible to do all those things in PB - I know I've written functions that do just that. However in addition to the string functions, I also used regular expressions, memory functions and API calls to get the job done - and that's my point.

The objective of the exercise was to create a beginner's guide and to keep the articles brief. I put it to you that combining all of those subjects in one topic would be inappropriate for a beginner's guide, as it would make it a) too long and b) too complex for a beginner. The object of the exercise was to show how to create something basic and provide links to more complex resources.

There is something else that I would like to take issue with too...
If you find a fault in the documentation - you should take the time to report it - don't grumble and leave it for someone else to do, because someone else may not notice it. I've been on the receiving end of that particular trick many times before - and the answer, if I'd been given the opportunity, would have invariably been "well if someone had told me there was a problem I'd have fixed it ages ago".

Writing good documentation is a VERY, VERY difficult task and, once you've written it, your troubles are only just beginning because you are then chasing your own tail trying to keep it up to date for ever onwards, even more so if multiple languages and/or media are involved...

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Wed Sep 12, 2012 3:13 pm
by BorisTheOld
@oldefoxx

I can see now why us old-timers needed lots of shelf space for our documentation. :wink: :lol:


@spikey
spikey wrote:There is something else that I would like to take issue with too...
If you find a fault in the documentation - you should take the time to report it - don't grumble and leave it for someone else to do, because someone else may not notice it. I've been on the receiving end of that particular trick many times before - and the answer, if I'd been given the opportunity, would have invariably been "well if someone had told me there was a problem I'd have fixed it ages ago".
In learning about PB we did things by the book. We read articles, we followed links, we read the forums, and we read the multiple versions of the help files. And we've all been programming long enough to know that we should RTFM before we complain.

It's taken us two years to find out what we didn't know and what aspects of the documentation need improvement. So we're now putting in our 2-cents worth.

And as for letting someone else do all the work -- as I've stated in several places on these forums, we're in the process of putting together a web site devoted to PB, which will include our improvements to the PB documentation. So although we're doing it for our own benefit, there's no reason why it shouldn't be shared with the rest of the PB community.

Re: learning PureBasic

Posted: Thu Sep 13, 2012 4:03 am
by oldefoxx
I recognize the validity of complaints against my approach to covering the use of strings.
We don't all share the same experiences, and I am writing from the viewpoint of someone
that has used strings in this manner. Others haven't. So they don't agree. That, and I do
write in length, as my mind and thoughts probe in depth such topics.

Here is the main point. As my signature indicates, I want people to stop and think. I do
not expect them to always agree with me. I was not putting forward material to actually
go into a manual, I was trying to convey the idea that you need to get over some idea of
what a knowledge of string manipulation can bring about. Would you expect an apprentice
to understand carpentry if he, or she, had not already seen what carpentry can produce?
The same with knitting, cooking, painting, writing, or any craft that you want others to
appreciate and set out to learn. Yes, there should be chapters on using the APIs, on the
use of regular expressions, perhaps on apply PCs to problems in algebra, geography,
trigonometry, even differential equations. Or just in resizing a recipe from one for four
people to one for 17. Computer and calculator books used to do this. And you know what
was learned? People that did not do those things in real life felt they had no need to get
into those subjects at all. What people might want to be able to do is calculate mortgage
and interest rates so that they could compare loans and returns on savings.

I was trying to give examples of how portions of the contents of strings can be used to
identify a part of the contents of those strings, on the assumption that if you can deduce a
part of what a string might hold, you can work with that information in a meaningful manner.
I did not say nor infer that this was something everybody would want or need to do. But if
you haven't worked with strings, then you don't know. Now here is another quick example
of manipulating string contents: Work out a way that you can encode and decode the
contents of a file's length of a string, so that nobody else can decode it unless they have
your secret key.

You can get programs of encoding and decoding the contents of files, but that means there is
always somebody out there that knows the secret means of decoding what you wrote at some
point in the future. Leonardo da Vinci wrote his notebooks in reverse, so that you would have
to hold them up to a mirror to read them normally. Some have suggested this was to protect
the ideas he put down in them, but nobody knows for sure. We generally assume that if a
document on a desk is turned away from the person on the other side of the desk, that they
cannot read it. When I was young, I read an account concerning a former statesman for
the the United States in which it was reported that he could walk into your office, and you
might think the documents on your desk were safe from viewing because they were upside
down to the person standing before you, but he had no problem with reading them both
upside down and backwards to the way we normally view docunents. I can't remember
which statesman was involved though. This goes back many decades.

Want to know when you have a good encoding/decoding technique down? Take a string of, say
4,000 spaces and nothing else in it. Encode it and show it on the screen. If you can spot a
repeated pattern occurring in place of the 4,000 spaces, your scheme is weak and repeats
too often. Each space character only has one bit set in it. Hiding that bit, moving it out of
position, putting other bits in there to mask it, and having this escape notice and still be
decoded back to the original 4,000 spaces is a real challenge. Fortunately you have the
power of a PC to help you in this task. Unfortunately, those that want your secrets can put
thousands, even tens of thousands times that power to work against you. You had better
be awfully lucky or awfully smart in order to succeed.

No matter how clever or lucky you get, your weak point is the program created. If you let
others get their hands on that program, they will break your code by unravelling the
methods you used to hide your secrets. Any good secrets program is going to have a hidden
key that is used to encode and decode the contents. Modern methods use huge primary
numbers that range against each other, and you use one primary number to encode (or
encrypt) the message, and only the holder of the other primary number can decode (or
decrypt) it.

Sounds easy or hard, depending on how you look at it, but with the increasing power of
computers, and mathematics that pinpoint primary numbers on a routine basis, it could
be just a matter of time before the one to reveal the contents is uncovered. As a
consequence, you may have messages encoded/encrypted multiple times, so that one good
decoding/decryption cannot be recognized because it does not reveal the real contents.
This technique uses multiple primes for each stage of the encryption process, and an
exact order of multiple primes for the decryption process. It is also very slow because of
the extensive range of numeric values involved, and the exacting results required.

Imagine the difficulty of finding three primary numbers and using them in the right sequence
to try and unravel one message, and doing this over and over until that one message is
finally broken. How many thousands of years might that take? How about investing an
army of PCs via the internet and having each of them carry on part of this work for you?
You get an army of 10,000 PCs working at this, you might break that message in a decade
or so, perhaps too late to be of any real benefit to you. But the number, speed, and power
of computers is on the increase. Your army of PCs may increase into the 100 thousands.

This is part of the world we are increasingly a part of. Do you need secrets kept? Are
you part of a group that wants its secrets kept? Then keep them off of computers, or
learn how to user computers and software to hide what needs to be kept hidden.

intended audien

Re: learning PureBasic

Posted: Thu Sep 13, 2012 5:23 am
by oldefoxx
Just to let you know.

I'm one boy who found secret codes a matter of real fascination when I was young. I also
saw that they needed specific sets of circumstances to be effective.

The unbeatable code was the one that was based on a particular edition of a a book, and
which book was the secret Words from the book were referenced by page-line-word
references, so you might see something like 119-23-7 to point to the word "ideal". If you
did not have the right book, you did not find the right word.

Prisoners resort to a different coding technique, where position on the page or where the
word appears in a sequence are used. They write these words into statements that are
crafted to make the words illusive. Prison guards have unmasked such methods at times,
but the practice apparently still flourishes.

PCs make such techniques juvenile. Instead of one book, they can use hundreds or thousands
once they are rendered into electronic form. Or they can instead make use of shared
documents or files. They can also go multi-level, where you take information from one layer
and use it at a different layer. Decoding is just reversing the whole process.

The one statement or operation that nearly everybody jumps on for encoding/decoding is the
XOR function. It reverses all designated bits, and the same process works in reverse which
keeps it simple. However, it is well known, and therefore not sufficient in its own right.

Secrets are part of every organizational structure. Things that only a few are intended to have
access to. The rise in terrorists cell structures was designed to make sure that no one person
knew enough other members to jeapordize the whole organization. The means of getting
information and instructions back and forth between separate cells also had to be protected.

There is another circumstance where secrets and cells might rise, and that is where government
becomes too strong and too intrusive into what people can do and how they live or what they
are allowed to believe. Governments can, have, and will leverage every means at their disposal
to make sure that they and they alone endure in power. As technology grows, they have more
and more means to accomplish this. You will likely face a day when you or your children will have
tracking devices implanted in their bodies so that they can always be tracked. When they become
adults, those implants will still be registering somewhere.

The recognition that these are increasingly the times ahead keep me disturbed, because this is
bad news for everyone that will be impacted, and I don't see it sparing many. Already you have
parents wanting their children implanted as a way of fighting back against the fear that their
child may be taken someday.

A gun may give you a degree of power. Belonging to a gun club or organization may lend you more
power. Having a PC also gives you a degree of power. Being connected by the Internet gives you
access to resources that just having a PC does not provide. Programming, such as with PureBasic,
gives you the ability to extend what the PC and the Internet provide.

I'm not a survivalist. I don't have stockpiles of goods or a bunker to go hide in somewhere. But
my home was broken into a couple of days ago, and I was here, but unable to prevent it. I get
around with a walker, have no sense of balance, and cannot manage on just my feet. And this is
in a society that is unable to provide jobs to people who need them, unable to do more than put
them on welfare or unemployment, and unemployment runs out. What do they do then? Quit
living? I don't think so. They turn on people like me to take what they want, which we spent our
lives earning. Because our government is so screwed up, I see more times like this ahead.

So forgive me if I make a point of delving into some of the things that I see confronting us as time
moves forward. If you are going to have the full use of your PC and the internet, now or later, you
need to focus on where not just your interest lead you, but what your interests exposes you to.

Re: PureBasic Docs- Ideas/Help needed for a "We start" chapt

Posted: Thu Sep 13, 2012 5:48 pm
by Thorium
spikey wrote: There is something else that I would like to take issue with too...
If you find a fault in the documentation - you should take the time to report it - don't grumble and leave it for someone else to do, because someone else may not notice it. I've been on the receiving end of that particular trick many times before - and the answer, if I'd been given the opportunity, would have invariably been "well if someone had told me there was a problem I'd have fixed it ages ago".
I did report errors in the help file, none was been fixed.
For example the incompatiblity of the packer lib on different OS. The help states the lib uses JCALG1, which is only true for x86 Windows.

Re: learning PureBasic

Posted: Thu Sep 13, 2012 8:50 pm
by oldefoxx
One of the other BASICs I've used solved the matter of how far to carry the Help file
system this way: They put one person in charge of the whole thing. They picked the
right man, because they ended up with a Help file system that is beyond peer. The
person in charge eventually moved on, and the person taking his place did not do
quite as good a job, but it was still a good system because of the groundwork that
had been laid down initially.

You find something that needs improving, who do you address your complaints to?
Posting it on a forum like this is no guarantee that the right person will pick up on
the posting. Take me for instance. I only read the few threads where I've posted
something myself, assuming I am still looking for the right answer. I don't spend
time tracking a bunch of threads on the expectation that sooner or later I will find
a post that I need to deal with myself.

You want a good Help file system, but one person out there to head it up. Seems
PureBasic has a pretty good Help file system, and that cannot have been by chance.
You want a good beginner's manual, you probably need one person heading the whole
thing up again. That person doesn't have to write the whole manyal themselves, but
they would have to pull the effort together to be sure it got done.

Re: learning PureBasic

Posted: Mon Sep 17, 2012 11:29 pm
by oldefoxx
Something I feel that would benefit anyone having a background in some other BASIC would
be a cross reference of what is common in other BASICs and how or what you would use
instead in PureBasic. Here is an example of what I mean: Most BASICs recognize INSTR()
as an instruction for finding a substring inside another string. But you look in PureBasic,
and there is no INSTR() function. So what is there in its place? Would you think to look
for FindString()? For what it does, it is a replacement, though the parameters passed are
in a different order.

Now things like Left(), Right(), Mid(), Ltrim(), Rtrim(), Trim() in place of Left$(), Right$(),
Mid$(), LTrim$(), RTrim$() or Trim$() is easy enough to follow. Just drop the signature $
that has been stuck to them forever.

So that is the easy part. I reckon you are not going to find an exact match for everything,
after all, PureBasic is a pretty extensive language in its own right. But something of a
cross-reference would make it easier to move from other BASICs to PureBasic. And maybe
help with moving some source code over as well.

Re: learning PureBasic

Posted: Tue Sep 18, 2012 3:43 am
by oldefoxx
Okay. In recognition of the fact that you generally don't get very far in programming
until you learn to work with files, and by that I mean drives, folders, and the files
themselves, I decided to write my own approach to how to do this. Now mind you, I
did not invent what I am about to show you. It is scattered around in various places
and other people have done as much and more, but this is my approach. Take it or
leave it as you see fit. My hope is that it serves to help those just getting up to
speed with PureBasic. I mean it doesn't really get into the language in a deep way,
but it does show you how to tie things together to get some type of result.

Code: Select all

Global folders.s, files.s, crlf.s = Chr(13)+Chr(10)
Global nfolders.l, nfiles.l, nused.q

Procedure.l FindFiles(drivenpath.s, pick.s)
  Protected c.l, d.l, e.s, f.s, g.s
  nfolders = 0: c = 0
  g = drivenpath
  If Right(g, 1)<> "\": g + "\": EndIf
  g + crlf
  Repeat
    d = FindString(g, crlf)
    If d = 0: Break: EndIf
    e = Left(g, d-1)
    g = Mid(g, d+2)
    d = ExamineDirectory(#PB_Any, e, pick)
    If d
      While NextDirectoryEntry(d)
        f = DirectoryEntryName(d)
        nused + DirectoryEntrySize(d)
        If DirectoryEntryType(d) = #PB_DirectoryEntry_Directory
          If f<>".." And f<>"."
            g + e + f + crlf
            nfolders + 1
          EndIf
        Else
          files + e + f + crlf
          c + 1
        EndIf
      Wend
      FinishDirectory(d)
    EndIf
  ForEver
  nfiles + c
  ProcedureReturn c
EndProcedure

Procedure.s cmm(number.q)
  Protected sum.s, a.l = 3
  sum = Str(number)
  While a<Len(sum)
    sum=Left(sum,Len(sum)-a)+","+Right(sum,a)
    a+4
  Wend
  ProcedureReturn sum
EndProcedure



Procedure WalkDrives()
  Protected a.l, b.l, d.s
  For a = Asc("C") To Asc("Z")
    d = Chr(a) + ":\"
    nfolders=0: nused=0
    b = FindFiles(d, "")
    If b: Print(Left(d,2)+" has "+Str(nfolders)+" folders\subfolders and "+Str(b))
          PrintN(" files on it ==> "+cmm(nused)+" bytes."): EndIf
  Next
EndProcedure

OpenConsole()
EnableGraphicalConsole(1)
ConsoleTitle("PureBasic - Checking Drives, Folders, Files, and Bytes used.")
ConsoleColor(15,1)
ClearConsole()
walkdrives()
PrintN("")
PrintN("All the drives from C: to Z: have been checked.")
While Inkey()=""
  Delay(100)
Wend
End 

Re: learning PureBasic

Posted: Tue Sep 18, 2012 3:37 pm
by blueb
Nice oldefoxx, the Console is not the first thing I think about
when I need to approach a problem.

A few color commands makes the screen much more appealing and easier on the eyes.

"There's efficiency in simplicity"

--Bob

Note:
Since you are 're-starting' your PureBasic career you might want to use
the default extension for numbers .i instead of .l

Re: learning PureBasic

Posted: Tue Sep 18, 2012 3:49 pm
by bosker
But unfortunately the program doesn't work.
My drive C: has at least 35000 folders, 280000 files and more than 140Gb used.

The program reports...
C: has 286 folders\subfolders and 183 files on it ==> 7,556,145,493 bytes.