Sign in to follow this  
Followers 0
Zithen

database output question

9 posts in this topic

I have a small text based database that was created a while ago. going through the notes one of the fields was checkboxes with there values in the sequence of 2,4,8,16,32... now the problem was the field could have multiple items checked and the values where added to equal what was stored in the field. now i have seen this before done in different things, but never acutally done this my self. I am just looking for a place to start on getting this infromation display out.

so if check box 1 and 4 was checked the value would be 20, but with that how do i go about getting a viewer to show check box 1 and 4 shown?

if i didnt explain this enought ( i have a history of that =/) let me know

Share this post


Link to post
Share on other sites



so if check box 1 and 4 was checked the value would be 20, but with that how do i go about getting a viewer to show check box 1 and 4 shown?

You must think of the original program's logic. If the values 1 + 5 give us 20, which values give us 40 and so on?

If you know this, you can write down a function to do the job for you automatically, otherwise a number is only a number.

Share this post


Link to post
Share on other sites

You must think of the original program's logic. If the values 1 + 5 give us 20, which values give us 40 and so on?

If you know this, you can write down a function to do the job for you automatically, otherwise a number is only a number.

yeah i am not 100% positive on this. i talked to a friend and he said that it would be converting Decimal to Binary, but wasnt sure on how or if that was correct. all i know is that say there was 4 check boxes, box1 = 2 box2 = 4 box 3 = 8 box 4 = 16, and if you had box 1, 3 and 4 checked the value would be 26.

i was just handed it and told to creat a visual way to show the check boxes that were checked, thought autoit would be a good quick way to do it. but i dont really know where to start on this

Share this post


Link to post
Share on other sites

yeah i am not 100% positive on this. i talked to a friend and he said that it would be converting Decimal to Binary, but wasnt sure on how or if that was correct. all i know is that say there was 4 check boxes, box1 = 2 box2 = 4 box 3 = 8 box 4 = 16, and if you had box 1, 3 and 4 checked the value would be 26.

i was just handed it and told to creat a visual way to show the check boxes that were checked, thought autoit would be a good quick way to do it. but i dont really know where to start on this

the binary solution is a good one. so if you convert the values of selected check boxes to binary, then combine them with a BitOr() you'd be able to check on any of the checkboxes with a BitAnd(). To follow your example, say boxes 1 and 4 are checked, the value would be 18 (not 20).

the binary equivelant of the boxes are:

Box : Value : Binary

1 2 00010

4 16 10000

so a BitOr would be : 10010.

now when you're trying to see if a box was checked, you do that with a bitand() example, to see if the second box is checked, you would do a BitAnd with the binary equivelant of the value (4 or 100) vs the stored value. that would return a 0, which indicates that the checkbox was not selected. here you can see the bit and:

00100 each position is compared, and only positions with a 1 in both rows would return

10010 a 1, so in this case, each column is populated with a 0.

now if you checkked for either of the values that actually are checked, you'll receive the number that you're checking for back as the result, like if you check for the first box, value 2 or 10

00010 performing the same comparison on these values, where only columns that have a 1 on both rows

10010 are populated with a 1, the returned result would be 00010 or 10, which is 2, and would return true

to a condition check because it's not 0. so you would know that the first box is checked.


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

the binary solution is a good one. so if you convert the values of selected check boxes to binary, then combine them with a BitOr() you'd be able to check on any of the checkboxes with a BitAnd(). To follow your example, say boxes 1 and 4 are checked, the value would be 18 (not 20).

the binary equivelant of the boxes are:

Box : Value : Binary

1 2 00010

4 16 10000

so a BitOr would be : 10010.

now when you're trying to see if a box was checked, you do that with a bitand() example, to see if the second box is checked, you would do a BitAnd with the binary equivelant of the value (4 or 100) vs the stored value. that would return a 0, which indicates that the checkbox was not selected. here you can see the bit and:

00100 each position is compared, and only positions with a 1 in both rows would return

10010 a 1, so in this case, each column is populated with a 0.

now if you checkked for either of the values that actually are checked, you'll receive the number that you're checking for back as the result, like if you check for the first box, value 2 or 10

00010 performing the same comparison on these values, where only columns that have a 1 on both rows

10010 are populated with a 1, the returned result would be 00010 or 10, which is 2, and would return true

to a condition check because it's not 0. so you would know that the first box is checked.

I followed u all the way up to the bitand to retrive the information. I should be just using bitand wrong. (never actually used it) i played with a little but got some odd numbers. was tring bitand(18,100) and other things i really dont know what i am doing with that. could you give a small exaple to check.. Binarys i own me heh

Share this post


Link to post
Share on other sites

I followed u all the way up to the bitand to retrive the information. I should be just using bitand wrong. (never actually used it) i played with a little but got some odd numbers. was tring bitand(18,100) and other things i really dont know what i am doing with that. could you give a small exaple to check.. Binarys i own me heh

well your example there : bitand(18,100) is comparing a decimal number with a binary number... the way to do it would be like:

if BitAnd(18,8) then ...

you can tell by looking at it that it's going to return 0, because the left number is larger than the right. here's a sample implementation for you...

$value = 0
For $x = 1 To 8
    If Not mod($x,2) Then $value = BitOR($value,2^$x);if it's an even number, BitOr() it with current value
Next
    
$checkme = InputBox("input","Enter a number to see if it was included in the BitOr().  $value = " & $value,3)
If BitAND(Int($checkme),$value) Then
    MsgBox(0,"Yes",$checkme & " was included because it is an even number")
Else
    MsgBox(0,"No",$checkme & " was not included because it is either an odd number or higher than 8")
EndIf

the bit and works just like the bit or. the values are compared at each position in the binary equivelant of the value. so with the comparison from your example, 18 to 8, you have 2 values being compared:

10010 and 00100. if you look at each place, and put a 0 in any case where that place in either number = 0, you're going to end up with all 0's... only values that were bitwised together to form the number in the second position will return a value other than 0. does that help at all?

10010

00100

-------

00000


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I'm not sure how much you grasp about the way binary works, so forgive me if I go over info you already know.

Binary is a number system much like any other, it differs in that instead of being 10 based, it is 2 based. Meaning that instead of having 0,1,2,...,8,9 it only has 0's and 1's.

0 and 1 in binary is exactly the same as 0 and 1 in the 10 based number system you have always used. When you get to to numbers higher than 1 you do the same thing in binary that you naturaly do in the 10 based system when you run out of digits, you carry the digit to the left. So 2 in binary is expressed as 10.

Here is an example:

0000 = 0

0001 = 1

0010 = 2

0011 = 3

0100 = 4

0101 = 5

Now, this works well for your project because if we picture each of the place holders as a check box in your other application, it is easy to see that a value of 3 means two of the switches are off and two of them is on. A value of 5 also gives us two off and two on, but it refers to a very different combination of switches.

BitAND and BitOR operations let us do some interesting things. In BitAnd operations you combine two binary numbers based on the values in their comparable place holders. It returns 1 if both bits are 1 and returns 0 otherwise

For example:

0101 = 5

0011 = 3

-----------

0001 = 0

1001 = 9

1010 = 10

-----------

1000 = 8

BitOR does a similar function however it returns 0 if both bits are 0 and returns 1 otherwise.

0101 = 5

0011 = 3

-----------

0111 = 7

1000 = 8

0010 = 2

-----------

1010 = 10

====================================

I find it more intuitive, for your situation, to convert the value in your database into a binary number then to base your IF-Then statements on a stringmid() check of that binary value.

Here's a function I made a while back that I modified to give you some ideas:

$msg = ""

$x = 20; value from your database
$y = MiniBin($x)

For $i = 1 To 8
    If StringMid($y,$i,1) = 1 then
        $msg = $msg & "Swich " & $i & " IS ON" & @CRLF
    Else
        $msg = $msg & "Swich " & $i & " is off" & @CRLF
    EndIf
Next
MsgBox(0,"Info", "Test Data =" & $x & @CRLF & "Binary= " & $y & @CRLF & $msg)


Func MiniBin($var)
; This function converts decimal number (0-255) into a 8 char binary string
    $bin = ""
    If ($var - 128) >= 0 Then
        $var = $var - 128
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf

    If ($var - 64) >= 0 Then
        $var = $var - 64
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    If ($var - 32) >= 0 Then
        $var = $var - 32
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    If ($var - 16) >= 0 Then
        $var = $var - 16
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 8) >= 0 Then
        $var = $var - 8
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 4) >= 0 Then
        $var = $var - 4
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 2) >= 0 Then
        $var = $var - 2
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 1) >= 0 Then
        $var = $var - 1
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    Return $bin
    
EndFunc ;==>MiniBin

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

thanks guys for your help in this, i think i have a great idea on how to accomplish what i need to do.

Share this post


Link to post
Share on other sites

thanks guys for your help in this, i think i have a great idea on how to accomplish what i need to do.

cool, glad to help.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0