BasicsTutorial/Variables

Last-modified: 2009-11-28 (土) 21:33:48

Variables

変数

Now we get onto one of the most important things in most coding.
現在、我々は大部分のコーディングで最も重要なもののうちの1つの上に着く。
Variables are stores for numbers and text, if you have done algebra then you will be familiar with the concept of letters representing numbers.
変数は数値とテキストを格納するためのものである、あなたが代数学をしたならば、あなたは数を表している文字の概念に精通している。
Here’s how it works.
それが働く方法は、ここにある。

変数の種類

intVar=10
floatVar#=10.10284
stringVar$=”Hello 1234”

Basically, using the = operator assigns the word before it the value after it.
基本的に、= オペレーターを利用することは、それの後の語を、前の語に値を割り当てる(代入)。
The first variable, intVar, is an integer variable, integer variables can store whole or integer numbers, that means that they don’t have anything after the decimal point.
最初の変数(intVar)は、整数変数(integer)、変数がまるごと保存することができる整数 そしてそれが小数点の何も持たないことを意味する整数数値である。
Integer variables do not have any symbol after them.
整数変数は、それらの後部に、少しのシンボルも持たない。

The second line is a floating point variable, or a float for short.
第2の行は、略して、浮動小数点変数またはフロート(float)である。
This means they can store numbers which have a decimal point, like 1.1 or 0.2846.
これは、それが(1.1または0.2846のような)小数点を持っている数を保存することができることを意味する。
They are defined by having a # symbol after them.
それは、それらの後部に、#シンボルを持つことによって定義される。

The third line is a string variable, this means that it can store text, which is characters inside quote marks, as we found out with the PRINT command.
3本目の行は文字変数(string)である(それがテキストを保存することができる)。そして、我々がPRINTコマンドで発見したので、それは引用マーク(“)の内側のキャラクタである。
Strings are defined by placing a $ sign after them.
文字列は、それらの後部に、$の印を置くことによって定義される。
You can give a string a value of nothing by using var$=””.
あなたは、var$=””を用いて文字に何も「無い値」を与える。ヌルと呼ばれる。

All of these different types of variable are known as data types.
これらの異なる種類の変数の全ては、データ型として知られている。
This is because they store different types of data.
これは、それがデータの異なる型を保存するからである。

Now the above code doesn’t do much so lets make DBPro print those values onto the screen.
現在、上記のコードはあまりしなくて、それで、DBProをスクリーンの上へそれらの値をプリントさせる。

intVar=10
floatVar#=10.10284
stringVar$=”Hello 1234”
Print intVar
Print floatVar#
Print stringVar$
Wait key

And the values are printed onto the screen.
そして、値はスクリーンの上へプリントされる。
We’ll find out why this is useful in a moment.
我々は、これがなぜすぐに役に立つかについて知る。

変数名

Variables should always have names that relate to what they are being used for, for example this code stores information about someone, their name, age, money in wallet and hair colour.
変数には、それが使われているもの(たとえば誰かに関するこのコード店情報、それの名前、年齢、髪色と財布のお金)に関するものである名前が常になければならない。

name$=”Fred”
age=45
money#=12.35
hairCol$=”Brown”

All of those variables names describe what they are storing, this is handy for seeing what your code does, like remarks.
それらの変数名の全てはそれが何を保存しているかについて述べる、これはあなたのコードが何をするかについて見ることに便利である、コメントのように。
Variables should also be short, to make your code easier to read, and quicker to type.
変数は短くもなければならない。そして、あなたのコードを読み込むのがより簡単で、タイプするのがより速くする。
That is why I’ve shortened hairColour$ to hairCol$.
そういうわけで、私は hairCol$に hairColour$を短くした。
Also it is good practice to separate the different words in your variables somehow, to make them easier to read.
また、どうにか、あなたの変数で異なる語を切り離すことは良い実行である。そして、それらを読むのがより簡単にする。
Some people would write:
一部の人々は書く:

hairCol$=”Brown”

With a capital letter showing the start of a new word, whereas some people use:
新語、ところが、数人は 始まりを大文字で示して使う:

hair_col$=”Brown”

It depends on your personal preference.
それは、あなたの個人の好みに依存する。
I will be using the first throughout this tutorial since I think it looks neater.
私はそれがよりきちんとしているように見えると思う時から、私はこのチュートリアルを通して最初のものを使っている。

PRINT文

Oh yeah, while we’re at it lets expand on the PRINT command.
ああはい、我々がそれである間は、PRINT命令を詳述する。

sentence$=”nice sentence”
Print “This is a ”,sentence$
Wait key

With the PRINT command you can separate variables and text that you want to print on the same line with a comma.
PRINTコマンドで、あなたはあなたがコンマ(,)で同じ行にプリントすることを望む変数とテキストを切り離すことができる。
This saves having to do 2 print statements with a semi-colon.
これは、セミコロン(;)で2つのプリント命令文をしなければならなくてセーブする。
You could combine all sorts of things, here is an example.
あなたはいろいろなものを結合することができた、例はここにある。

range=30
randomNum=rnd(range)
someWords$="  Blah Blah Blah"
print "This is a random number from 0 to ",range,".
Here it is...
",randomNum," and another...
",rnd(87),someWords$
wait key

As you can see, you can combine strings (in quotes), variables and commands like RND(), which return numbers so they are exactly like variables.
ご覧の通り、あなたは(引用句で)文字列を結合することができる、変数と命令はRND()に合う、それが正確に変数のようであるように、それを値を返す。

Also look at the second line, the variable range has replaced the number in RND().
また、第2の行を見る、変数rangeは、RND()で数と入れ替わった。
That’s the thing about variables, to the computer they ARE a number or string, so any place a number can be used, so can a variable.
それは、変数についてのものである、どんな場所ででも数が使われることができるように、コンピュータにとって、それは数または文字である変数。