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.

Code Snippets / Mimicking multi-datatype arrays.

Author
Message
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 6th May 2005 11:52
Ever need to store more than one datatype in an array? You can do it with strings.

For this, we will be making an array to store a person's name, age, and height (meters), using strings, integers, and reals.

In DarkBasic, datatype indicators are as follows:
String: $
Real: #
Integer: None, but we will use ! in this tutorial.

We will do this for 5 people, and are storing three subdimensions.
We will be using a string datatype for the array.



Now we need to apply names to the people. Subdimension 1 will store names.
In order to later determine what datatype is used, we will add a prefix to all strings in this array. Since the name will be a string, we will use the $ prefix. The prefix is the first character in the string.



Next, we will define the age of the people using integers with the prefix !, but we will still enter data as strings.



The last data we will enter is the height in meters of the people. This will be done in real numbers with the # prefix.



Finally, we retrieve data from the array in the correct datatype. You can either code a method yourself or use the functions below.

Determine the datatype:

If the prefix indicates an integer, the value is 1; if real, 2; if string, 3. If none of these are present, the value is 0.



All that's left to do is print this data to the screen. Your final code should look something like this:


RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th May 2005 13:18
Very creative. I am going to have to play around with this.

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th May 2005 19:51
Mr Schnell, I presume you're using DB Classic? Your method is a good way to get around the limitations.

Don't forget, one of the IDEs lets you create TYPEs, and in DB Professional TYPEs are standard...



BatVink

Login to post a reply

Server time is: 2025-05-16 15:13:31
Your offset time is: 2025-05-16 15:13:31