Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Insecure on May 16, 2004, 12:46 AM

Title: Adding to DB
Post by: Insecure on May 16, 2004, 12:46 AM
[EDIT] RESOLVED!
Title: Re:Adding to DB
Post by: DarkMinion on May 16, 2004, 12:51 AM
IMO, it's bad to store flags as a string...
Title: Re:Adding to DB
Post by: 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?
Title: Re:Adding to DB
Post by: Eibro on May 16, 2004, 01:14 AM
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
Title: Re:Adding to DB
Post by: Insecure on May 16, 2004, 01:17 AM
I need something in vb:(!
Title: Re:Adding to DB
Post by: DarkMinion on May 16, 2004, 03:07 AM
Eibro's way is the hard way btw, if you ever switch to C++
Title: Re:Adding to DB
Post by: Insecure on May 16, 2004, 03:11 AM
RESOLVED:)!
Title: Re:Adding to DB
Post by: DarkMinion on May 16, 2004, 03:12 AM
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.
Title: Re:Adding to DB
Post by: 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?
Title: Re:Adding to DB
Post by: CrAz3D on May 16, 2004, 09:57 AM
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
Title: Re:Adding to DB
Post by: Insecure on May 16, 2004, 11:14 AM
ok;)
Title: Re:Adding to DB
Post by: ChR0NiC on May 16, 2004, 11:25 AM
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*
Title: Re:Adding to DB
Post by: Spht on May 16, 2004, 11:44 AM
Quote from: Insecure on May 16, 2004, 12:46 AM
[EDIT] RESOLVED!

Don't do that.
Title: Re:Adding to DB
Post by: BinaryzL on May 16, 2004, 01:45 PM
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]"