Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulating READ/DATA

Status
Not open for further replies.

bsisko

Programmer
Oct 9, 2000
85
US
In most BASIC programming, there is a structure known as read/Data
It goes something like this.


Read a

Data 1,2,3,4,5,6
Data 7,8,9,10,11,12

etc.

In my C++ programming, I've been using databases for my data for so long, as well as arrays for data that I use them exclusively now.

Recently, a VB programmer asked me was there a way to simulate the read/data statements in C++ without using the database method. I have no answer for him. Do anyone else.
Just curious.


Bug in your code! Need a quick fix fast!
Need Help from a programming expert! Click on the site below. We're here to help!
 
BYTE Read(BOOL Reset)
{
const BYTE The_Datas[] = {1,2,3,4,5,6,7,8,9,0}; // Fill in the datas to read
static WORD Index = 0;
if(Reset || (Index >= sizeof(The_Datas)-1)) Index = 0; // Reset the Index-pointer when wrap-around occurs or by command
return(The_Datas[Index++]);
}

Comment: x = Read(FALSE) will read sequentially from the The_Datas[] array, when last position is read it starts all over.
x = Read(TRUE) will reset the Index to 0 and thus return the first data in the array.

Totte
Keep making it perfect and it will end up broken.
 
Hey, thanks Totte,

I hadn't expected a reply so quickly. How long have yo been programming in C++? What type of software do you usually develop?


Bug in your code! Need a quick fix fast!
Need Help from a programming expert! Click on the site below. We're here to help!
 
Well, i'm a "hardware programmer", i design microprocessor solutions hardware and do the programming in ANSI C (real-time) so i'm well known with the tricks and twists of accessing hardware, i've been doing that for the last 10 years.

Whenever i need to do something usefull in a PC i use BCB6.

I use some PIC-processors too for simpler tasks.

Totte
Keep making it perfect and it will end up broken.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top