2 array questions
-
- Posts: 164
- Joined: Aug 28, 2005 21:06
- Location: irwin, pa
- Contact:
2 array questions
I need some help initializing an array containing strings.
Here's the code:
DIM steady_job(1 TO 8) AS STRING => ("yes", "yes", "no", "no", _
"yes", "yes", "no", "no")
When I attempt to compile, I get:
compiling: idbcxxxx.bas -o idbcxxxx.asm
idbcxxxx.bas(75) : error 7: Expected ')', found: ','
DIM steady_job(1 TO 8) AS STRING => ("yes", "yes", "no", "no", _
^
Any idea what I'm doing wrong?
Next question. I'm attempting to add some statistical analysis to my engine program. The above is just a test case to test my math. Here's what I need to do. At _compile_ time, I have no idea how many arrays the user will need, whether the elements of the arrays will be numeric or string or mixed, or how many elements each array will have. How can I make the arrays *VERY* dynamic to cover just about all eventualities?
Thanks again in advance.
Bill
;-))
Here's the code:
DIM steady_job(1 TO 8) AS STRING => ("yes", "yes", "no", "no", _
"yes", "yes", "no", "no")
When I attempt to compile, I get:
compiling: idbcxxxx.bas -o idbcxxxx.asm
idbcxxxx.bas(75) : error 7: Expected ')', found: ','
DIM steady_job(1 TO 8) AS STRING => ("yes", "yes", "no", "no", _
^
Any idea what I'm doing wrong?
Next question. I'm attempting to add some statistical analysis to my engine program. The above is just a test case to test my math. Here's what I need to do. At _compile_ time, I have no idea how many arrays the user will need, whether the elements of the arrays will be numeric or string or mixed, or how many elements each array will have. How can I make the arrays *VERY* dynamic to cover just about all eventualities?
Thanks again in advance.
Bill
;-))
As far as dynamic arrays REDIM works rather nicely.
For instance
DIM steady_job() AS STRING
DIM jobCount as LONG
jobCount = 0
DO
--Something about handing user input--
'Add new job
REDIM PRESERVE steady_job(jobCount)
steady_job(jobCount) = userInput
jobCount +=1
LOOP
REDIM means REDIMension, PRESERVE will tell freebasic to non-destructively resize the array. This means any existing data will remain up to the length of the new array.
For instance
DIM steady_job() AS STRING
DIM jobCount as LONG
jobCount = 0
DO
--Something about handing user input--
'Add new job
REDIM PRESERVE steady_job(jobCount)
steady_job(jobCount) = userInput
jobCount +=1
LOOP
REDIM means REDIMension, PRESERVE will tell freebasic to non-destructively resize the array. This means any existing data will remain up to the length of the new array.
-
- Posts: 164
- Joined: Aug 28, 2005 21:06
- Location: irwin, pa
- Contact:
array questions
Whoops! Mark up question #1 to monitor resolution (not to mention age and eyesight ;-)) Went back and rechecked help files and found curly braces not paran. Had to squint.
In regards to 2nd question, I'm not sure if it was answered or not. Mayhaps I should restate.
When I compile the program, I will have no idea how many arrays the user will need. Could be 3 or 4, could be 15 or 20.
Neither will I have any idea how many elements each array will have. Maybe 2 or 3, maybe 75 or 80.
Nor will I have any idea whether or not the array elements will be numeric or string. In my math test example, I'm using text but it could just as well be a 3 or a 3.1419572 or a yes or no. I need to make it as flexible as possible.
Can I make the array name a variable? Then tack a number on the end: e.g. array1, array2, array3, ... arrayn.
Anyone familiar with the ID3 algorithm? That's what I'm trying to implement.
Thanks again.
Bill
In regards to 2nd question, I'm not sure if it was answered or not. Mayhaps I should restate.
When I compile the program, I will have no idea how many arrays the user will need. Could be 3 or 4, could be 15 or 20.
Neither will I have any idea how many elements each array will have. Maybe 2 or 3, maybe 75 or 80.
Nor will I have any idea whether or not the array elements will be numeric or string. In my math test example, I'm using text but it could just as well be a 3 or a 3.1419572 or a yes or no. I need to make it as flexible as possible.
Can I make the array name a variable? Then tack a number on the end: e.g. array1, array2, array3, ... arrayn.
Anyone familiar with the ID3 algorithm? That's what I'm trying to implement.
Thanks again.
Bill
-
- Posts: 775
- Joined: Jul 01, 2005 18:45
Re: array questions
Basically what you want is a linked list. This way you can allocate new "variables" as well and keep track of them in a simple manner. You may also want to look into hashing algorythms, which, may provide a better solution then linked lists.TriumphRacer wrote:In regards to 2nd question, I'm not sure if it was answered or not. Mayhaps I should restate.
When I compile the program, I will have no idea how many arrays the user will need. Could be 3 or 4, could be 15 or 20.
Neither will I have any idea how many elements each array will have. Maybe 2 or 3, maybe 75 or 80.
Nor will I have any idea whether or not the array elements will be numeric or string. In my math test example, I'm using text but it could just as well be a 3 or a 3.1419572 or a yes or no. I need to make it as flexible as possible.
Can I make the array name a variable? Then tack a number on the end: e.g. array1, array2, array3, ... arrayn.
i was wondering this recently
gives me error
although i didnt like this because in a large one there will be wastage due to all elements being len 20
Code: Select all
DIM steady_job(8) AS STRING => {"yes", "yes", "no", "no", _
"yes", "yes", "no", "no"}
so i had to do something like thiscannot initialize dynamic arrays
Code: Select all
DIM steady_job(8) AS ZSTRING * 20 => {"yes", "yes", "no", "no", _
"yes", "yes", "no", "no"}
-
- Posts: 775
- Joined: Jul 01, 2005 18:45
This works for me:
Code: Select all
dim as zstring ptr test(0 to 1) => {strptr("hi"), strptr("not another one")}
print *test(0), *test(1)
sleep
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: 2 array questions
build your own dynamic variant data type (in size too).TriumphRacer wrote:Next question. ... Here's what I need to do. At _compile_ time, I have no idea how many arrays the user will need, whether the elements of the arrays will be numeric or string or mixed, or how many elements each array will have. How can I make the arrays *VERY* dynamic to cover just about all eventualities?
If you need more instructions let me know.
Joshy
Last edited by D.J.Peters on Dec 13, 2005 6:35, edited 1 time in total.
You could also do:
EDIT: oops, looks like some people beat me to it already :)
Code: Select all
DIM steady_job(8) AS ZSTRING ptr => {strptr("yes"), strptr("yes"), strptr("no"), strptr("no"), _
strptr("yes"), strptr("yes"), strptr("no"), strptr("no")}
Btw, just @ is enough, literal strings are zstring's so STRPTR has the same effect as VARPTR (or the @ address of operator).
Code: Select all
DIM steady_job(8) AS ZSTRING ptr => {@"yes", @"yes", @"no", @"no", @"yes", @"yes", @"no", @"no"}
-
- Posts: 164
- Joined: Aug 28, 2005 21:06
- Location: irwin, pa
- Contact:
array questions
[quote]
build your own dynamic variant data type (in size too).
If you need more instructions let me know.
Joshy
[/quote]
I'd be *very* interested in some help on this. As I've stated before, I'm not a pro programmer, just an amateur and I think I'm getting in over my head but the concept is a good one.
Thanks to all for bearing with a neophyte!
Bill
;-)))
build your own dynamic variant data type (in size too).
If you need more instructions let me know.
Joshy
[/quote]
I'd be *very* interested in some help on this. As I've stated before, I'm not a pro programmer, just an amateur and I think I'm getting in over my head but the concept is a good one.
Thanks to all for bearing with a neophyte!
Bill
;-)))
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: 2 array questions
With generic programming paradigms - in C-style languages (C, Pascal, etc.) this involves writing MACROs. You parameterize the type of element you need to store in the array, and let the compiler do the rest - duplicating virtually identical code for any and all element types you wish to include.TriumphRacer wrote:How can I make the arrays *VERY* dynamic to cover just about all eventualities?
I'm in the process of writing a set of tutorials on this subject, but here is an incomplete implementation of a generic array, which can be expanded to make it dynamically resizable upon adding/removing elements. It might be enough to get you started.
To answer your problem, I recommend setting up an array of arrays. If you do that dynamically, you can resize the number of data sets you want to evaulate by resizing the "master array".
Each array within the master array could be composed of unions. The unions in turn hold members, one for each of the data types (string, int, real, ...) you want to examine. For each of the arrays, record the array's data type and the number of entries in the data set, and you should be halfway there.
I recommend checking out the TYPE, UNION and DIM/REDIM entries in the online help.
Cheers, and good luck,
syzygy
Each array within the master array could be composed of unions. The unions in turn hold members, one for each of the data types (string, int, real, ...) you want to examine. For each of the arrays, record the array's data type and the number of entries in the data set, and you should be halfway there.
I recommend checking out the TYPE, UNION and DIM/REDIM entries in the online help.
Cheers, and good luck,
syzygy