Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2006, 08: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?

 
Old January 16th, 2006, 09: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




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 01: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.