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.

Newcomers DBPro Corner / Array help

Author
Message
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 12th Feb 2016 04:33
Using dbpro.
Iv'e always avoided arrays because they confuse me I usually write to files but I need to learn.

First attempt and I cannot get it to work no matter what.

DIM checklist$(170)
for files= 1 to checklist quantity()
checklist$(files)=checklist string (files)
next

I tried replacing files with a number and my checklist with an actual "string" lots of tinkering but nothing so far
A child\'s dream never dies.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 15th Feb 2016 02:44
Hi,
The CHECKLIST QUANTITY() command is used after a proper 'PERFORM CHECKLIST.....' command. There are several things that you use this command for. Some examples:
PERFORM CHECKLIST FOR DISPLAY MODES
PERFORM CHECKLIST FOR GRAPHICS CARDS
PERFORM CHECKLIST FOR FONTS

After you use one of the above commands, then you use CHECKLIST QUANTITY() to determine how many results there are. What you are doing is not what CHECKLIST QUANTITY is intended for.

After you dimension an array, you would store data in that array (examples are: numbers, characters, strings, etc). Then to write the data from the array to your hard drive, you check to see if the file exists. If it does, you would want to delete it so you can write the new data. You then open the file to write and then use a for-next loop to write the contents of the array. Once everything is written, you close the file.

An array such as checklist$(170), would typically be a string array. You could say checklist$(1) = "Chris": checklist$(7) = "smerf" etc.

Here is a way you can do it:


Run the code and it should write the file to your hard drive in the same place where you save the project and source files.

To load it back in you could do the following:

This code prints any array element that is not a null string(i.e. ""), just to demonstrate to you that they are there.

I hope this is helpful and was what you were interested in. If you need anything else, just post.



So many games to code.....so little time.
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 15th Feb 2016 08:51
Thank you lbfn, forums seem to be so dead lately. As far as the checklist goes Ive never known it to work any other way even wrote a nice little browser using it that way. its attached
A child\'s dream never dies.

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 15th Feb 2016 12:55
I couldn't get your program to run. Could you make an .exe of it and post it?

From the help files:
CHECKLIST STRING$
This command will return the string from the specified item number in the checklist after a PERFORM CHECKLIST command has been performed.



So many games to code.....so little time.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 15th Feb 2016 16:32 Edited at: 15th Feb 2016 16:52
This snippet uses the checklist functions to write the available display modes to a file. An array is a indexed variable. The line in the snippet - write string 1, checklist string$(i) looks like it's an array. Instead it is a indexed function. Hope this clears things up.

Edit: To be more precise, a function that uses an index as a parameter.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 22nd Feb 2016 08:19 Edited at: 22nd Feb 2016 08:26
lbfn theres an attached rar/zip file. I didn't include exe in the original post sorry . I use it in all my programs built it in its own while loop inside a function. have to run source from the program.dba not the file browser if you try to compile it. suppose I could have just ran it from the same file.
http://s18.postimg.org/kgy5pnw7d/Untitled.png
A child's dream never dies.

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 22nd Feb 2016 08:56
Okay, I ran the .exe and it does work. When I tried to load it into DBP, it would only allow me to load the 'program' code. The 'THEUNF~1' file is a backup and won't load obviously. Looking at the .dba files, I see in the 'file browser.dba' file that you use 'perform checklist for files' followed by CHECKLIST QUANTITY() and CHECKLIST VALUE A() and CHECKLIST STRING$().

So.....this is inconsistent with your code in the original post.




So many games to code.....so little time.
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 23rd Feb 2016 02:23
I haven't been clear I apologize thinking about to much I suppose. I want to put my checklist string$() results "just file names" into an array,"in memory " without writing files to the hard drive.
file management can get tedious for me. .I tried to follow some basic examples of creating arrays but I couldn't get it to work with the checklist string$(). all three of the above examples involve .txt files would like to not read or write files if possible.
A child's dream never dies.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 23rd Feb 2016 03:37
If I’m understanding you correctly, you mean something like this. This will store the file name of all files in the project folder to an array. Because I do not know how many files there will be, I am allocating the array dynamically. This can be made more sophisticated by iterating through each sub-folder as well.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 28th Feb 2016 04:05
exactly what I needed wicked thank you so much. also believe it or not I had no idea "not" was a command.
A child's dream never dies.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 28th Feb 2016 05:37
I can believe that, it’s not a commonly used command. I prefer to use – if (file exist(a$)) as opposed to - if file exist(a$) = 1. Unless I specifically want to check if the value equates to one. So, when I want to check for the opposite, I use the not command. Also, I do not like variable suffices, instead I declare variables - a as string. But that’s neither here nor there.

enjoy
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 29th Feb 2016 07:21
A little off topic from my original post but I was hoping for some input on a program I want to build. How would I go about declaring a few types, atoms for example oxygen, carbon, hydrogen. and assigning each one a value for atomic mass, base charge, ion charge.
there could be thousands of different atoms and each one would have to store its unique states so I could calculate two atoms as they collided to see if there would be a bond or not over and over and over.

A child's dream never dies.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 1st Mar 2016 02:00 Edited at: 1st Mar 2016 02:45
The first thing you need to do, is declare a user defined data type. Let us call it s_ATOM.



Now, dimension an array of type; s_ATOM.
If the total amount of atoms will be constant, you can define the contant and dimension the array of that size.



If you need a variable size user defined type array, you can use a dynamic array. Dimension the array without a size.



Dark Basic Profesional arrays keep a internal index. With dynamic arrays you can insert or delete array elements at the beginning, end or anywhere else in the array. You can also write functions to sort or search the array. Here is a list of commands for full control over dynamic arrays.



The only thing left do do is fill the array with data and use that data however you see fit.

smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 13th Mar 2016 11:58
thank you so much for your time wicked
A child's dream never dies.

Login to post a reply

Server time is: 2024-11-23 15:29:40
Your offset time is: 2024-11-23 15:29:40