Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 16th, 2006, 07:26 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Representing multiple items with a single value?

I don't know the proper term for it, but there's a methodology in which items are assigned a value, and the value representing each successive item is double that of the last...

Item1 = 1
Item2 = 2
Item3 = 4
Item4 = 8
Item5 = 16
Item6 = 32
Item7 = 64

such that a value of 65 can only be a combination of Items 1 and 7. The only way I can think of decoding the combined value is using a [code language=vbscript]Select Case[/code] statement, but in the example above, 127 cases would be required. There has to be a better way! Can someone please point me toward it?

Reply With Quote
  #2 (permalink)  
Old January 16th, 2006, 08:32 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Figured it out - needed to use a bitwise comparison. Here's the code in case it helps anyone...

Code:
' Item 1 = 1
' Item 2 = 2
' Item 3 = 4
' Item 4 = 8
' Item 5 = 16
' Item 6 = 32
' Item 7 = 64
x = InputBox("Enter a number between 1 and 127...")
items = "init"
If (x AND 1) = 1 Then
    items = "Item 1"
End If
If (x AND 2) = 2 Then
    If items = "init" Then
        items = "Item 2"
    Else
        items = items & ", Item 2"
    End If
End If
If (x AND 4) = 4 Then
    If items = "init" Then
        items = "Item 3"
    Else
        items = items & ", Item 3"
    End If
End If
If (x AND 8) = 8 Then
    If items = "init" Then
        items = "Item 4"
    Else
        items = items & ", Item 4"
    End If
End If
If (x AND 16) = 16 Then
    If items = "init" Then
        items = "Item 5"
    Else
        items = items & ", Item 5"
    End If
End If
If (x AND 32) = 32 Then
    If items = "init" Then
        items = "Item 6"
    Else
        items = items & ", Item 6"
    End If
End If
If (x AND 64) = 64 Then
    If items = "init" Then
        items = "Item 7"
    Else
        items = items & ", Item 7"
    End If
End If
MsgBox items
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple views of single table jatatman ASP.NET 3.5 Basics 1 June 2nd, 2008 01:34 AM
Multiple Projects under Single Solution gadhiav ASP.NET 1.0 and 1.1 Professional 2 October 20th, 2005 04:26 AM
multiple selects -single where clause collie SQL Server 2000 3 January 21st, 2005 12:27 AM
Multiple domains on a single IP qazi_nomi Classic ASP Basics 24 September 22nd, 2004 06:41 PM
Single or Multiple application. Gibs_poovath General .NET 7 May 25th, 2004 07:54 AM



All times are GMT -4. The time now is 08:18 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.