How to keep track of each unique record in a type?

Archives Forums/BlitzPlus Programming/How to keep track of each unique record in a type?

BachFire(Posted 2003) [#1]
Hello,

I'm creating a program, where I have to keep track of each record created with the "New" command.

I have used these Type -> New commands before, but only in conjunction with the For -> Each commands, where you don't need to keep track of Each of them.

Well, in my case, each New record is unique. How do I go about this.

Is there a simple example somewhere. I have searched for some help here (blitzbasic.com) on newsgroups and on the internet in general.. I can't find anything.. All I can find is the For -> Each thing..

Can someone help me with this?

Goodnight people (need to sleep).. ;)


Anthony Flack(Posted 2003) [#2]
It might help if you say exactly what it is you're trying to achieve here.


BachFire(Posted 2003) [#3]
Sorry, if I wasn't too clear. I am VERY tired. I was supposed to go to bed some hours ago, but I have been trying to solve this problem since last post. It's now 4 o'clock in the morning. This damn Blitz is stealing my time.... Ya gotta love it.. ;) Okay, now I'm just wasting your time, so let's cut to the chase..

All right, what I'm trying to do, is some database kind of stuff, about my logins and passwords for different internet sites (like this site).

I have a bunch of Text Fields, and one big List Box. The Text Fields are stuff like "Site Name", "Site URL", "Login" and "Password". I fill out these Text Fields with the proper information, then click a button. Then the plan is, that the Site Name (or something relevant) will appear in the List Box. Then if I click it in the List Box, the information I entered before will appear in the Text Fields, where I entered it.

Of course, information for multiple sites can be entered, stored, and later selected in the List Box for viewing/editing.

I hope that cleared it up for you. ;)

Now I'm REALLY off to bed! Nitie nite.. ;)


dynaman(Posted 2003) [#4]
Sounds like you still just use the for each, till you find the one that matches your key. I guess I'm missing something...


RexRhino(Posted 2003) [#5]
BachFire:

Well, unless you are going to be storing thousands of sites, and have to read thousands of sites every second, I don't think there is any problem with iterating through all your records. Just do a for/next loop, checking if the internet site name in the record type matches the one in the text field.

However, one way to speed things up (NOTE: I wouldn't do it this way, it probably wouldn't speed things up noticably for what you are doing. It would probably speed things up by 66% percent, more or less depending on your array size, but 66% of 1 millisecond isnt much of a differnce.):

Create an array of types, and create a same sized array of ints (the array of integers is to store if a record exists, because there is no TypeExists() command! If a record exists for a specific index, set it to true, if not false).

Then, you hash your internet site name to get an index for your array, and simply write to or read from that record. (remember to check if a record exists and to create a new record if it doesn't already exist).


Michael Reitzenstein(Posted 2003) [#6]
because there is no TypeExists() command!


format_code('
If Instance.TypeName = Null
')


RexRhino(Posted 2003) [#7]
Michael:

That is an undocumented command... supposedly we can't count on that remaining in Blitz.


Floyd(Posted 2003) [#8]
That's just the keyword Null.

Of course it's documented.

Actually, since it was supposed to indicate TypeExists, it should be

format_code('
If Instance.TypeName <> Null
')


skn3(Posted 2003) [#9]
or..
format_code('If Not Instance.Typename = Null')

;)