[EDIT] RESOLVED!
IMO, it's bad to store flags as a string...
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?
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
I need something in vb:(!
Eibro's way is the hard way btw, if you ever switch to C++
RESOLVED:)!
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.
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?
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
ok;)
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*
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]"