Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / [DBPro] Tutorial - Variables

Author
Message
Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 28th Jul 2007 10:31 Edited at: 28th Jul 2007 20:01
This tutorial and more can be found at DarkDev.


--------------------------------------------------------------
-Part 1-
Introducing the variables
--------------------------------------------------------------


Some variables can contain numbers, and some contain other things.

The limit as to how high and low numbers in a variable can go is from..
-2147483617 to 2147483617


There are three common types of variables in the DBPro language.
1. Integers
2. Reals/Floats
3. Strings

Each one of those variables can be used differently, and store different things.

It is important you know the difference between those three variables, for it will come in handy in the future.






--------------------------------------------------------------
-Part 2-
The Integer
--------------------------------------------------------------


Integers are a type of variable that store whole numbers.

They can be positive or negative.
Negative number example: -56
Positive number example: 1097


Integers can not contain decimal points or decimal values. They can only be whole numbers.
Integer: 125
Not an Integer: 125.36



Storing integers in DBPro is easy. All you have to do is assign them to an integer variable like so:

MyInteger = 55
OtherInteger = -768


You can also create an integer variable from other variables

MyInteger = 55
HisInteger = 98
OurInteger = MyInteger + HisInteger



Now you know what an integer is, how to store it, and how to use it.






--------------------------------------------------------------
-Part 3-
The Real/Float
--------------------------------------------------------------


Reals and floats are the same thing, but people more commonly use 'float' instead of 'real'.

Floats and reals are exactly like Integers, except that they can have decimal points and decimal values...

Real: 427
Real: 427.0234


Storing reals in DBPro is just like storing integers.
The only difference is that in front of the variable name, you place a number sign '#'...

MyReal# = 801.987
OtherReal# = -768.99


You can also create a real or float variable from other variables

MyReal# = 801.987
HisReal# = -768.99
OurReal# = MyReal# + HisReal#



Now you know what a real/float is, how to store it, and how to use it.






--------------------------------------------------------------
-Part 4-
The String
--------------------------------------------------------------


String variables are different than Integers and Reals.
Strings contain words and letters and numbers in the form of a sentence.

You can store a string variable like this...

MyString$ = "Hello World, I am 58 years old."


Notice that I placed a money sign '$' in front of the variable name to make it a string.
Also notice that when storing the sentence of the string, I surrounded it with quotation marks. This shows that it is string information.


You can also create a string variable from other variables

MyString$ = "Hello World, "
HisString$ = "I am 58 years old."
OurString$ = MyString$ + HisString$



Now you know what a string is, how to store it, and how to use it.






--------------------------------------------------------------
-Part 5-
Declaring variables (without '$' or '#')
--------------------------------------------------------------


As you now understand, to create a string you use '$', and for Reals/Floats you use '#'.

There is a method used commonly that you can use to avoid adding those symbols.


All you have to do is add 'as string' or 'as float' or 'as integer' in front of the variable name.


Say your string is called 'MyString$', and this is your code...

MyString$ = "Hello everyone!"



Here is an example of declaring without symbols...

MyString as string
MyString = "Hello Everyone"



The same goes with Reals/Floats and Integers.
The only problem is, you cant say 'as real', you can only use 'as float'...

MyString as string
MyString = "Hello Everyone"
MyReal as float
MyReal = 17.68
MyInteger as integer
MyInteger = 9786



Now, you understand how to declare variables without signs.



But, there is more!
In another tutorial, you will learn about something called a 'function'.
When you want to use a variable in a function, you put 'Global' before you declare it, like this...

Global MyInteger as integer
MyInteger = 5







--------------------------------------------------------------
-Part 6-
Conclusion&Extras
--------------------------------------------------------------


Now that you know the three common variables used in DBPro, you can be on your way to the next tutorials or continue your project.

There is more, though.
Some functions in DBPro allow you to convert an integer to a string, and a string to an integer...

Converting an integer to a string: STR$(MyInteger)
Converting a string to an integer: VAL(MyString$)



An example of converting an integer to a string...

MyInteger = 55
MyString$ = STR$(MyInteger)

The variable 'MyString$' now contains "55".




An example of converting a string to an integer...

MyString$ = "98"
MyInteger = VAL(MyString$)

The variable 'MyInteger' now contains 98.







Now, the tutorial is over.

vorconan
16
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 28th Jul 2007 12:26
Nice tut Xenocythe. I'm sure it will come in useful to many newbies.


Zotoaster
17
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 28th Jul 2007 13:59
Very nice. May I give some input?

There is infact a limit to ho high or low numbers can go. That is -2147483617 to 2147483617 if I remember correctly.

Also, perhaps a mention of how integers change into floats during calculations, i.e.

integer + integer = integer
integer + float = float
float + integer = float
float + float = float


I think you should also say about how variables can created like "myint as integer" and "mystring as string"

And we can't forget about local and global variables

All in all, good tutorial. Great for beginners. When I started I had no idea what they ment by a variable

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Commander in Chief
16
Years of Service
User Offline
Joined: 15th Apr 2006
Location: Carbondale, PA, USA
Posted: 28th Jul 2007 15:32
I agree with Zotoaster. You should mention that Reals are more commonly addressed as Floats. Also include that you can do this to declare a variable.

MyReal as Float
MyInteger as Integer
MyString as String




---PlasmaArts---
www.plasmaarts.co.nr - www.plasmaarts-games.co.nr
Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 28th Jul 2007 19:36
Sixty Squares
16
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 28th Jul 2007 20:04 Edited at: 28th Jul 2007 20:05
Maybe you could add a more advanced section to the tutorial covering the following variable types. Although to tell the truth the only ones I use are dwords and booleans... I don't know HOW to use the rest of them...

-Boolean
-Byte
-Double Float
-Double Integer
-Word
-DWord


^^^There are probably more I've forgotten (or don't know about ). Nice tutorial though It really explains variables and what they can do well.

Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 28th Jul 2007 20:27
Thanks

I might make a new tutorial later on for those kind of variables.
This is just basic for the most common

Don Malone
19
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 29th Jul 2007 06:06 Edited at: 29th Jul 2007 06:11
Quote: "Storing reals in DBPro is just like storing integers.
The only difference is that in front of the variable name, you place a number sign '#'...

MyReal# = 801.987
OtherReal# = -768.99"


I believe you mean behind the variable name. Nice tutorial

Quote: "All you have to do is add 'as string' or 'as float' or 'as integer' in front of the variable name.


Say your string is called 'MyString$', and this is your code...

MyString$ = "Hello everyone!""

Quote: "MyString as string"


I believe you may have reversed your meaning here as well. I like the tutorial very much. It should be very helpful to anyone that takes the time to read it. Thanks

Making nothing for the forth straight year.

Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 29th Jul 2007 07:00
Thanks

Look forward to more tutorials from me


But the thing is, we read from left to right. Technically, the sign is in front of the variable name.

Don Malone
19
Years of Service
User Offline
Joined: 27th Apr 2003
Location: Birmingham, Alabama
Posted: 29th Jul 2007 13:35
It is a minor thing as your examples clearly show what you want to get across. I just wanted to mention it to you to get your feed back.

Thanks for the good tutorial on variables.

Making nothing for the forth straight year.

Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 30th Jul 2007 00:14
No problem And thanks for the great comments!

TDK
Retired Moderator
20
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 30th Jul 2007 20:02 Edited at: 30th Jul 2007 20:05
Quote: "But the thing is, we read from left to right. Technically, the sign is in front of the variable name."


So reading that way, what do you read first - the $ or the variable name?

If it's the variable name, then the $ sign comes after!

You also have an integer listed as a float:

Quote: "Floats and reals are exactly like Integers, except that they can have decimal points and decimal values...

Real: 427
Real: 427.0234"


427 is an integer. 427.0 is a float.

Variables For Beginners

TDK_Man

Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 30th Jul 2007 21:20
Oh, sorry TDK, you are correct

Commander in Chief told me integers and floats are the same.

Thanks!

Profit
16
Years of Service
User Offline
Joined: 19th Feb 2006
Location: United States
Posted: 30th Jul 2007 22:02
I was under the impression that "val" could return a float as well.

common people are walking in line.

Mitsu Fly Ride.
Sasuke
16
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Jul 2007 22:25
"Val" only returns a float(help files are incorrect). There have been problems with returning integers in the past with "Val", but it's not always the case.
TDK
Retired Moderator
20
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Aug 2007 01:34
VAL returns the numerical value of a number in string format. It's nothing really to do with integers or floats.

The type of variable you get back depends on the variable name you use (casting).

If you want a float, then use a float variable - otherwise use an integer.



Will print 1.234.



Will print 1.

TDK_Man

Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 1st Aug 2007 02:43
Your too good, I may as well not write another tutorial

Kieran
16
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 1st Aug 2007 12:12 Edited at: 1st Aug 2007 12:13
Very nice tutorial xeno

Maybe you could mention why they can only store numbers at that limit.

for example: Integer = 8-bit? cant remember but if you go really in-depth you would have all that junk. Maybe its not important though. also in your number limit you have
-2147483617 to 2147483617
I think its something like this
-2147483618 to 2147483617 (the second integer is 1 lower, I recall it being because 0 is a number)
Im not sure if DBP can have unsigned integers or not but unsigned integers remove negative numbers from being stored to give higher positive numbers.

PS: Sorry for all the really in-depth stuff, i've learnt it through learning C++

indi
20
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 1st Aug 2007 16:25
trying should be rewarded.

TDK
Retired Moderator
20
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 2nd Aug 2007 04:10
Quote: "trying should be rewarded"


Indeed!

Tutorials should be 100% accurate, but anyone can make a typo or get some small detail wrong.

The main thing is that if errors are pointed out, they are corrected by the author before too many people read the tutorial. And that includes my tutorials too!

TDK_Man

Sixty Squares
16
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 3rd Aug 2007 04:33 Edited at: 3rd Aug 2007 04:35
Quote: "The main thing is that if errors are pointed out, they are corrected by the author before too many people read the tutorial. "


@TDK: I've found an error in all of your tutorials. Each and EVERY one of them has the same error, and its becoming quite a problem. All of your tutorials are just too perfect and helpful. I just thought I would point that out considering what you said in your previous post.

Xenocythe
17
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 3rd Aug 2007 06:06


I feel like a kid at school who got these cool new shoes, and everyones crowded around me, then TDK comes by with a huge gold chain and everyone goes to him

Nah just messin, yeah your right TDK

Libervurto
16
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 3rd Aug 2007 20:34
@TDK
Quote: "Will print 1."

Watch were you're putting those full stops!

@Xeno
Your tut was pretty good (though I prefer TDK's), one thing I would suggest is explaining what a variable is and why it is used in the first sentence.
e.g.
Quote: "Almost all programs use variables. Variables are used to store data: this data can be a string, integer or number. Storing data in a variable allows you to change the variable's value as and when you need to..."


Your signature has been erased by a mod because it was rubbish.

Login to post a reply

Server time is: 2022-12-01 11:03:27
Your offset time is: 2022-12-01 11:03:27