March 28, 2024, 12:36:02 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Temperature Conversion

Started by GWS, November 30, 2012, 11:11:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

November 30, 2012, 11:11:52 PM Last Edit: December 02, 2012, 09:56:58 AM by GWS
Hi folks,

Here's a little application just for fun, which might be useful figuring out
just how cold it's getting as Winter arrives - or how warm it's got to get before
you can put an open-collar shirt on again ..  ::)

Nice and easy in Creative Basic ..  :P

best wishes, :)

Graham



Tomorrow may be too late ..

AdrianFox

December 01, 2012, 06:15:47 AM #1 Last Edit: December 01, 2012, 10:12:11 AM by AdrianFox
Nice little program and very useful to those of us who still don't really 'think' in centigrade.  After ten years in France I now use centimetres and metres with abandon,  but I still don't really 'know' how warm or cold 11C or 32C actually are!

I'm thinking of teaching myself Creative Basic this winter  having bought the program several years ago when Paul was doing one of his 'buy everything' sales, but I've never really got to use it. How confusing is  it likely to be for somebody more familiar with IWBasic?  Any suggestions for a good starting project?
I will of course be working my way through your enormously helpful lessons, for which much thanks.

:)
Adrian Fox

GWS

Hi Adrian,

Nice to find someone interested in CB ..  :)

I think you will find most of the instruction set is the same, and there's a good help system.
I use it all the time, 'cos I can never remember the syntax ..  ::)

Just open the User Guide on the Help menu in the IDE - and use the Contents, Index and Search tabs to find the instruction you're planning to use.  Doc did a helpful user guide as well - I'm sure it's still around.

Some things are different and catch me out most of the time ..

Opening a window for example.
In IWB it's ..


OPENWINDOW w,0,0,800,600,@MINBOX|@MAXBOX|@SIZE,0,"IwBasic Title",&Handler


In CB it's just ..

WINDOW w,0,0,800,600,@MINBOX|@MAXBOX|@SIZE,0,"CBasic Title",Handler


I'm sure there was a reason for changing the command to OPENWINDOW rather than just WINDOW, and for introducing the & before the message subroutine name - but it's just more things to remember.

Then in IWB, all subroutines have to end with RETURN and ENDSUB - whereas CB only requires the RETURN statement.  IWB also requires you to use () after a subroutine name, even if no parameters are used.
CB subroutines only have the name (unless there really are some parameters).

Just to be perverse, IWB has moved around the parameters of the INSTR command so they are different to CB, so watch out for that.

Otherwise I think you'll find CB less pernickity.  Being an interpreter, it's easy to just click the Green arrow when you think you're ready to try something - and away it goes.  No compilation or linking needed.

The debug system is very helpful.  Just place a STOP command at a good place in your program, and you will be able to open the Build - Show Variables menu to display the contents of all your variables and arrays at that point.  You can then press F5 to step on one statement at a time to see what happens to all your values. I've found it a life saver for figuring out why something isn't working.

By the way, I don't know which version of CB you have - I still use Version 1.01 myself, since the later versions were not tested as thoroughly as the original, and some folk have found problems.

If you need the original version, it is still available from IonicWind if as an existing user, you request it.

It's getting late here for me, so if you don't mind, I'll look into your query about projects and the DirectX zip tomorrow ..

best wishes, :)

Graham


Tomorrow may be too late ..

Doc

Nice little program Mr. Graham!
Living here in that states and not being involved with either science or academia, I am usually at a loss when it comes to the Centigrade temperture scale and/or metric dimensions for the most part.... generally speaking, I have the head in the sand/lazy american syndrome.  ::)

@Adrian
Like Graham, I too am (have always been) a huge fan of Creative, although I've recently begun trying to use IWB a little these days. Creative is a really nice little piece of dev software, more than capable of handling the majority of applications that aren't specifically requiring speed of operation or heavy crunching. I've found that a very large portion of Windows/GUI based apps do not have those kinds of requirements.

Without the compile/build/test routine always required, it's both a breeze and pleasure to work with!

-Doc-

GWS

I'm back  :) .. I work funny hours here now I'm getting old .. middle of the night is a good time. ::)

I'll take this a bit at a time to avoid overload for Adrian - think simple Basic and you won't go far wrong.

Just take a look at the code for the temperature program for instance ..

Everything I write starts with a small block of variable type declarations:


def w:window
def wstyle,i,num,point,minus:int
def in,out,xbegin,ybegin,run:int
def a$:string


.. and I like to use AutoDefine "off" so it requires every variable to be defined.

Next you will see the statements to set up the Window and the user controls. Sometimes I put all these in a subroutine at the end of the program to keep the flow of the main program tidy.  It's just a matter of preference.

Then there's often a few initialising statements and always the closing block to the END statement:


point = 0 :' no decimal entered
minus = 0 :' no minus sign

run = 1

WAITUNTIL run = 0
CLOSEWINDOW w
END


Then you find the all important 'messages' block which is where all the work is done, and finally any number of subroutines used by the main program.  That's it - all you ever need for a program. :)

In fact, I keep a folder on my hard drive just to keep bits of code I've gathered over the years which often come in useful.  Two in particular get me over the 'blank piece of paper' situation to just get started. 

Here's one for setting up a skeleton console window - very useful for testing bits of code ..

' Creative Console skeleton ..
openconsole
cls




do:until inkey$<>""
closeconsole
end


And here's my skeleton for a normal Window ..


' Creative Skeleton window

def w:window
def wstyle,i:int

wstyle = @minbox

' open a window ..
window w,-600,0,600,400,wstyle,0,"Creative Basic",messages
setwindowcolor w,rgb(0,60,190)
centerwindow w

control w,"B,Exit,(600-70)/2,310,70,30,0,1"


run = 1

WAITUNTIL run = 0
CLOSEWINDOW w
END

SUB messages
select @class
case @idclosewindow
run = 0
case @idcontrol
select @controlID
case 1
run = 0
endselect
endselect
RETURN


Those two bits of code get you going whatever program you've got in mind - it's just a matter of adding the other bits needed for the rest of your application.

You get all the functionality to program Windows applications in about 5 Mbytes, compared to Microsoft's offerings which fill huge GigaByte chunks of your disk.

Doc ..  :) thanks for your continuing support - with Aurel on the side, that makes three of us Creative aficionados  :)

I think I've located Doc's useful document .. (he'll tell me if I'm wrong) .. I've attached it here as CBGuide.zip

There's also a list of CBasic constants which you might find a useful reference. I've attached that as CBConstants.zip

I'll press on looking into your other queries now - back in a while ..  ;D

all the best, :)

Graham




Tomorrow may be too late ..

Doc

QuoteI think I've located Doc's useful document .. (he'll tell me if I'm wrong)

Heh... I only wish I were capable of that.   ;)

I'm not certain who actually wrote that document or I would have given proper credit for sure. All I did on my end was to make the front cover graphic, reformat all of the pages, adding a "click-able" table of contents. I appreciate that you posted the files though, since I had lost my personal copy of the manual. The reference for the constants are very useful.

-Doc-

GWS

Ha!  :) .. you did a lot of work on it, so to all who read it, it's Doc's document  ;D ;D

I think it's about time I copied some more stuff to DVD's.  If ever my hard disk dies, a lot of good things would disappear with it  ::)

Cripes, it's -4 degrees Centigrade here this morning  (that's 25 degrees Fahrenheit you know  ;D )
I'm not a fan of Winter - too cold to do much.

all the best, :)

Graham
Tomorrow may be too late ..

GWS

Adrian,

I think this bit will complete my answer to your questions ..  :)

About projects ..

I would advise starting slow until you get the feel for the language.  It's not difficult, but all languages take a bit of getting used to.  If you get stuck please ask any questions you have.

There are lots of example programs from games to applications, on this forum and those which come with the CB language.

Load one or two of these that catch your eye, and play around with them - change the colours, the sizes of windows and controls, maybe alter the logic - have a bit of fun with them.  That saves you having to invent your own code from scratch, which might be a bit daunting until you find your feet.

Have a look round the Net - there are many sites where you will find code in some other dialect of Basic which you can try to convert and make the applications work in Creative.  Lots of fun to be had there - it's a never ending source of ideas.

Of course, feel free to modify or extend any of the programs I've posted - they're there to be used by anyone as they wish.  If you come up with any interesting variations, post them so we can all enjoy ..  :)

best wishes, :)

Graham
Tomorrow may be too late ..

AdrianFox

Thanks for your very helpful tips and encouragement and for fixing the corrupted zip file.   I will take your advice in working progressively through the posted programs as suggested, though after an evening 'playing' with Creative I can see some of the reasons why you and a few others prefer it.   I particularly like the 'Run' option which is such an instant way to check the code is ok.

:) :)


Adrian Fox

GWS

One thing I forgot to mention ..  ;D

The maths in Creative is very easy to use - and accurate.

Not many folk will know that it's capable of 4 dimensional arrays.  They use memory up fast though. ::)

This was added when a user many years ago, doing analysis of sound transmission through the Earth, needed some high power maths. ::)


' Creative Console skeleton ..
openconsole
cls

def a[2,2,3,2], b[2,4]:int

a[1,1,2,1] = 3
b[1,1] = 4

x = a[1,1,2,1] * b[1,1]

print "x = ",x


do:until inkey$<>""
closeconsole
end


I don't think many programming systems can do that.

You won't find SIN, SIND, FSIN, and FSIND - there's just SIN of an angle - and it works just fine, like all the other trig functions.

In fact there's none of the struggling to decide variable types and typecasting.

Creative Basic does all it's calculations in double precision, and converts the answer to the receiving variable type.  How neat is that ?

Just thought I'd mention it ..  :D

best wishes, :)

Graham
Tomorrow may be too late ..

GWS

Having bragged about the accuracy of Creative's maths - it won't help you if you don't declare your variables correctly in the first place ..  ::)

I'd just noticed a slight error in the temperature program.  If you enter the boiling point of water in Centigrade which is 100 degrees C - the result in the Fahrenheit box apears as 211  (it should be 212) :-[.

We're slightly low  :o 

Reason is, I forgot to define the conversion ratio 5/9 or 9/5 as Double precision.

I've corrected it, and the program has been updated in the first post.

Good Grief !  ::)

Graham
Tomorrow may be too late ..