basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 05:22
Home Help Search Calendar Login Register
News: Have you got suggestions for BasicProgramming.org? Let's hear them!
Interested in creating your own programming language? Check out the QDepartment group!

+  BASIC programming forum
|-+  Basic Coding
| |-+  General Basic Programming
| | |-+  Q&A
| | | |-+  Yabasic - Data
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Reply Print
Author Topic: Yabasic - Data  (Read 288 times)
Mainchip
Guest
« on: Mar 27. 2008, 18:48 » Reply with quote

Hi guys,

I was just wondering if this was possible:

Code:
Label members
read member_name$,member_age,member_eye_colour$
data John,100,blue
data Jim,50,green
data Jane,25,brown

Is it possible for me to print on screen Jane's details without printing out anyone else's?

Thank you,

Mainchip.
Report to moderator   Logged
Cybermonkey
Global Moderator
Hero Member
*****
Offline Offline

Posts: 931



WWW
« Reply #1 on: Mar 28. 2008, 06:16 » Reply with quote

In this case I would choose an array. So you can access the variable by its index. In this case you can use a for-next-loop to read the datas. Example (I don't know for sure if yabasic's index starts with 0 or 1):
Code:
DIM member_name$(3)
DIM member_age(3)
DIM member_eye_colour$(3)
for i = 1 to 3: rem // so index starts with 1 here ...
read  member_name$(i),member_age(i),member_eye_colour$(i)
next
rem // print out Jane's details
print  member_name$(3),member_age(3),member_eye_colour$(3)
data John,100,blue
data Jim,50,green
data Jane,25,brown
Report to moderator   Logged

Best wishes,
Cybermonkey
Mainchip
Guest
« Reply #2 on: Mar 28. 2008, 08:04 » Reply with quote

Hi,

Thanks for your reply, this will work fine thank you,

What does this line do?

Code:
for i = 1 to 3:

And yabasic does start at 0  Wink

Thank you,

Mainchip.
« Last Edit: Mar 28. 2008, 08:04 by Mainchip » Report to moderator   Logged
Cybermonkey
Global Moderator
Hero Member
*****
Offline Offline

Posts: 931



WWW
« Reply #3 on: Mar 28. 2008, 10:32 » Reply with quote

Ok, first, if Yabasic starts at 0 you can also write

Code:
for i=0 to 2

But before, you only have to DIM the arrays at (2)[i.e. value from 0 to 2 = three values]. This will save memory, although in this case it isn't necessary I think ...
Ok, next:
Quote
What does this line do?

Code:
for i = 1 to 3:
This is a loop. Every command between FOR and NEXT is executed i-times.
FOR i=1 to 3
First run: i has got the value of 1
NEXT -> Now the value of i is increased by 1 (or alternatively by a STEP given in the FOR statement: Example: For i = 1 to 10 STEP 2)
Second run: i has now the value of 2
NEXT -> Now the value of i is increased by 1
And so on ... until the second value (in this case 3) is reached.
Report to moderator   Logged

Best wishes,
Cybermonkey
Mainchip
Guest
« Reply #4 on: Mar 28. 2008, 11:35 » Reply with quote

Ah, cheers for that  Wink makes more sense now lol

Mainchip.
Report to moderator   Logged
Pages: [1] Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!