• Welcome to Valhalla Legends Archive.
 

Adding to DB

Started by Insecure, May 16, 2004, 12:46 AM

Previous topic - Next topic

Insecure

[EDIT] RESOLVED!

DarkMinion

IMO, it's bad to store flags as a string...

Insecure

Quote from: DarkMinion on May 16, 2004, 12:51 AM
IMO, it's bad to store flags as a string...
imo? and what do you sugest?

Eibro

Quote from: Insecure on May 16, 2004, 12:54 AM
Quote from: DarkMinion on May 16, 2004, 12:51 AM
IMO, it's bad to store flags as a string...
imo? and what do you sugest?
A bitfield is best. I'm not sure how you'd implement such in VB, but it's something like this in C/C++.union Flags
{
   DWORD dwFlags;
   struct {
        unsigned flag1 : 1; // name this whatever
        unsigned flag2 : 1;
   };
};

// ...
Flag myFlags;
myFlags.flag1 = TRUE;
if ( myFlags.flag2 ) // flag2 is set
   // dosomething
Eibro of Yeti Lovers.

Insecure

I need something in vb:(!

DarkMinion

Eibro's way is the hard way btw, if you ever switch to C++

Insecure


DarkMinion

This is what I do in C++...if you get proficient enough with VB you might be able to port it

This struct will store a user:


struct User{
   char szMask[32];
   unsigned long dwFlags;
};


Then using my list class I will construct a list of users, which will be my database:


List<User *> Database;


I use these functions to manipulate flags:


bool CheckFlag(unsigned long dwMask, char bFlag)
{
   if(bFlag < 'A' || bFlag > 'Z')
      return false;
   return !!(dwMask & (1 << (bFlag - 'A')));
}

int GetAllFlags(unsigned long dwMask, char *lpszBuffer)
{
   int iCount = 0;
   for(int i = 'A'; i <= 'Z'; i++){
      if(CheckFlag(dwMask, (char)i)){
         lpszBuffer[iCount++] = i;
      }
   }
   lpszBuffer[iCount] = 0;
   return iCount;
}

void SetFlag(unsigned long *dwMask, char bFlag)
{
   if(bFlag < 'A' || bFlag > 'Z')
      return;
   *dwMask |= (1 << (bFlag - 'A'));
}

void RemoveFlag(unsigned long *dwMask, char bFlag)
{
   if(bFlag < 'A' || bFlag > 'Z')
      return;
   *dwMask &= ~(1 << (bFlag - 'A'));
}


I add items to my db like so:


User *p = new User;
strcpy(p->szMask, "whatever");
SetFlag(p->dwFlags, 'A'); //or whatever
Database.Add(p);


You *can* port this to VB if you know what you're doing, I'll leave that up to you.

MyndFyre

Quote from: Insecure on May 16, 2004, 03:11 AM
RESOLVED:)!

How about leaving your question up so that future people might benefit from your wisdom?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

CrAz3D

Quote from: Myndfyre on May 16, 2004, 05:11 AM
Quote from: Insecure on May 16, 2004, 03:11 AM
RESOLVED:)!

How about leaving your question up so that future people might benefit from your wisdom?
Not to forget the answer
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Insecure


ChR0NiC

#11
Quote from: Insecure on May 16, 2004, 12:46 AM
[EDIT] RESOLVED!

I remembering doing this and as a result, I got a lecture and such from the Admins.

*awaits Admin lecture*

Spht


BinaryzL

#13
Called a user type in vb

Public UserDB() As db ' Dynamic Array '

Private Type db
   strUsername As String
   strFlags as String ' Or whatever you want '
End Type

Ex.
UserDB(intIndex).strUsername = "Binary[zL]"