Hi All
I have a form with about 20 check boxes and I want to persist their state to
a single integer. That is to say, I want to set their Checked property to a
particular bit value contained in an integer (32 possible values)
The following methods (translated from VB6) should help with this?:
Public Sub BitSet(ByVal iValue As Integer, ByVal Bitnum As Integer, ByVal
State As Boolean)
Try
If State Then
iValue = iValue Or CType(2 ^ Bitnum, Integer)
Else
iValue = iValue And Not CType(2 ^ Bitnum, Integer)
End If
Catch : End Try
End Sub
Public Function BitGet(ByVal iValue As Integer, ByVal Bitnum As Integer) As
Boolean
Return CBool(iValue And CType(2 ^ Bitnum, Integer))
End Function
However, there could be some better way to do this in VB.Net (2005). The
whole thing is about user permissions for an inhouse application.
I have had a look at the BitArray class, but find myself somewhat confused
on how to persist this to a database, or read back that value.
If someone could give me some help or a hint, I would be most appreciative.
Thank you 2 2207
Harry,
Is your database schema already decided? I had a look at a similar system
and I found myself becomming tied up in knots with my stored procedures.
Eventually I went for a table with one bit column for each permission in any
given row. Then I explicitly loaded them into boolean variables from the
database. My enumeration doesn't have to worry about bit manipulation and
neither do my stored procedures. Of course the first idea is always to
store a group of permissions in a single integer, but then what happens if
you need more than 32 or 64 bits of information here? You will need two,
then three, etc. Much better to store this information in a database table
explicitly, because you can mix and match types - if for example instead of
a permissions bit, you want some number (MAX or MIN) or some other data
types.
( Assume an enumeration called PermissionsEnum , that stores the column index
for each item in the set of permissions.
Also assume I have just executed a "GetPermiss ions ( name )" stored
procedure against the database. Finally, assume
a class called DataPermissions that exposes boolean properties for each
permission ).
If DataReader.HasR ows = True Then
DataReader.Read ()
thePermissions = New DataPermissions
thePermissions. ID =
DataReader.GetI nt32(DataPermis sions.Permissio nsEnum.ID)
thePermissions. Name =
DataReader.GetS tring(DataPermi ssions.Permissi onsEnum.Name)
thePermissions. CanReadCritical =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanRea dCritical)
thePermissions. CanAddIM =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanAdd IM)
thePermissions. CanAddIP =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanAdd IP)
thePermissions. CanAddAP =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanAdd AP)
thePermissions. CanAddLP =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanAdd LP)
thePermissions. CanDeleteIM =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanDel eteLP)
thePermissions. CanDeleteIP =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanDel eteIP)
thePermissions. CanDeleteAP =
DataReader.GetB oolean(DataPerm issions.Permiss ionsEnum.CanDel eteAP)
....
....
Else
' Failed....
End If
Hello Harry,
Check out the BitConverter class.
-Boo
Hi All
I have a form with about 20 check boxes and I want to persist their
state to
a single integer. That is to say, I want to set their Checked property
to a
particular bit value contained in an integer (32 possible values)
The following methods (translated from VB6) should help with this?:
Public Sub BitSet(ByVal iValue As Integer, ByVal Bitnum As Integer,
ByVal
State As Boolean)
Try
If State Then
iValue = iValue Or CType(2 ^ Bitnum, Integer)
Else
iValue = iValue And Not CType(2 ^ Bitnum, Integer)
End If
Catch : End Try
End Sub
Public Function BitGet(ByVal iValue As Integer, ByVal Bitnum As
Integer) As Boolean
Return CBool(iValue And CType(2 ^ Bitnum, Integer))
End Function
However, there could be some better way to do this in VB.Net (2005).
The whole thing is about user permissions for an inhouse application.
I have had a look at the BitArray class, but find myself somewhat
confused on how to persist this to a database, or read back that
value.
If someone could give me some help or a hint, I would be most
appreciative.
Thank you This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim Hubbard |
last post by:
I have some C# code that is supposed to wrap the defrag APIs and I am trying
to convert it to VB.Net (2003). But, I keep having problems.
The C# code is relatively short, so I'll post it here.....
--------
//
// a set of simple C# wrappers over the NT Defragmenter APIs
//
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
--------------------------------------------------------------------------------
Hello,
I have a very simple problem but cannot seem to figure it out. I have a
very simple php script that sends a test email to myself. When I debug
it in PHP designer, it works with no problems, I get the test email. If
|
by: Clint Olsen |
last post by:
I had this crazy idea to use stdarg macros to copy data in a generic
fashion, regardless of type. However, I'm not sure it will work in part
due to the ANSI C default argument promotions and the fact that va_arg
requires a type to decide how far to advance to subsequent arguments. So,
essentially what I want in the variable argument function is something that
just assigns to a character type, and then copy a predefined number of
bytes to...
|
by: bruce.james.lee |
last post by:
hi
i have a problem with integer subtraction in C.
printf("%d", c < (a - b));
a is got from a #define and is 0x80000000 and b is got from input and
is also 0x80000000.
c is ffffffff (-1).
Now, this should print 1 (true) but it prints 0!
If I modify this to
d = c < (a - b);
|
by: Chua Wen Ching |
last post by:
Hi there,
I saw this article here in vb.net.
http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx
and
http://www.opennetcf.org/forums/post.asp?method=ReplyQuote&REPLY_ID=3922&TOPIC_ID=2224&FORUM_ID=35
| |
by: Shaggyh |
last post by:
hi im needing help with a program im writing to do subnetting
i was on before about it and i got some help.
the code below wont work for me and i cant think of why not.
i was wondering if anyone out there can help, even come up with a better way
of doing this..
i have 2 files..
here is my first file..
// a library assembly i.e. dll
|
by: Martin Ho |
last post by:
Hi Everyone,
I have this code of Mersenne twister, which produces the random
numbers, one of the fastest codes as far as I know to produce random
numbers.
Anyways, it's writen in c# and I need to translate it to vb.net.
I tried some translators and I can't get it to work.
Could someone help me?
This is the code:
|
by: rob |
last post by:
Would somebody be kind enough to convert this code to VB.Net for me?
private string GetRtfImage(Image _image) {
StringBuilder _rtf = null;
// Used to store the enhanced metafile
MemoryStream _stream = null;
// Used to create the metafile and draw the image
|
by: ransoma22 |
last post by:
I developing an application that receive SMS from a connected GSM
handphone, e.g Siemens M55, Nokia 6230,etc through the data cable.
The application(VB.NET) will receive the SMS automatically, process and
output to the screen in my application when a message arrived. But the
problem is how do I read the SMS message immediately when it arrived
without my handphone BeEPINg for new message ? I read up the AT
commands, but when getting down...
|
by: marsguy85 |
last post by:
a program that repeatedly request an integer from the user and displays the integer as a binary number. It should terminate when the value 9999 is entered. A typical run might look like:
Enter integer: 16
00000000000000000000000000010000
Enter integer: -1
11111111111111111111111111111111
Enter integer: 9999
Try various values including negative and check that they are correct – the storage of signed numbers in binary was discussed in the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |