basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 03:40
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
| | | |-+  Reading Data
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Reply Print
Author Topic: Reading Data  (Read 162 times)
Katogoon
Newbie
*
Offline Offline

Posts: 14



« on: Jun 10. 2009, 08:10 » Reply with quote

Hello everyone,

I have been looking at Yabasic for a few hours today and it seems interesting, I have come across data in the manual and thought I'd give it ago. Here is what I have:
Code:
Label test
Read Name$, Age
Data "Katogoon", 19
Data "John", 25
Data "Smith", 63

As you can see I am storing names and ages. What I am trying to do is figure out how I can print Johns data on screen like so:
Code:
Name$ = "John"
Age = 25
Print Name$, " is ", Age, " years old."

Without the use of Variables though. (I think thats the correct term).

Report to moderator   Logged

I don't suffer from insanity. I enjoy every minute of it.
Jacob
Sr. Member
****
Offline Offline

Posts: 414


« Reply #1 on: Jun 10. 2009, 08:54 » Reply with quote

I don't know if understood what you was trying to do right, but anyway...

I would search through all the data (and add some sort of way to determine that you're at the end without counting all the data) and then report back whether the name was found or not. So something like this could be what you were looking for:

Code:
name$=""
age=0
target_name$="jake"

restore my_data

repeat
read name$,age
until( name$ = target_name$ or age < 0 )

if( age < 0 ) then
print "did not find ",target_name$
else
print name$, " is ", age, " years old."
fi

label my_data
data "john", 19
data "jim", 40
data "jake", 34
data "", -1
Report to moderator   Logged

"The truth is rarely pure and never simple."  - Oscar Wilde
syzygy
Full Member
***
Offline Offline

Posts: 205



« Reply #2 on: Jun 10. 2009, 09:17 » Reply with quote


Hi Katogoon,

I don't think what you want is possible.

Information stored in DATA lines must be read into a variable first before it can be processed: A READ operation is the only way to access DATA information directly.

Or I misunderstood something...

Syzygy
Report to moderator   Logged
Katogoon
Newbie
*
Offline Offline

Posts: 14



« Reply #3 on: Jun 10. 2009, 09:25 » Reply with quote

Thank you both for your posts, I'm not sure if what I was asking for is possible to only print the information I wanted out of my data structure.

However the method Jacob posted there could work with what I wanted to do, as I can search for the required name and gather the information that way using the repeat loop.

Thanks a lot,
Katogoon.
Report to moderator   Logged

I don't suffer from insanity. I enjoy every minute of it.
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!