Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VB .net and integrating the third party dll to my code which is related to keycard in Hotel software.

So the key-card is generated for the particular floor the guest check in. for that in their documentation they asked to format it as 32 bit character string.

Ex: If the guest is in 17 the floor then the

Dim FloorSelection as string = "00000000000000010000000001000000"


From left 1 should be added in place of 7 for each floor and 1 should be added to the floor the guest checkin

What I have tried:

so how can i achieve this based on their criteria to add 1 to the particular place based on the guest check in floor
Posted
Updated 12-Jun-18 0:32am

1 solution

It's not easy to tell from just that one example - you really need to go back to the documentation and double check exactly how the string it supposed to relate to the floor and room number, as it seems unlikely that it's what it appears from that.
Best guess:
00000000000000010000000001000000
Is in two parts:
0000000000000001  -  floor number (1)
0000000001000000  -  room on floor (7)
But that restricts the system to only work with 16 rooms per floor, and I've stayed in hotels with far, far more than that!

But the simplest way to do this conversion is to set up an array:
VB
Private toBinaryString As String() = {"0000000000000001", "0000000000000010", "0000000000000100", "0000000000001000", "0000000000010000", "0000000000100000", "0000000001000000", "0000000010000000", "0000000100000000", "0000001000000000", "0000010000000000", "0000100000000000", "0001000000000000", "0010000000000000", "0100000000000000", "1000000000000000"}
and then use the floor number and room number as indexes to get each "half" of the string you need.

But I'd strongly advise you to read the documentation carefully before committing yourself on this!
 
Share this answer
 
v2
Comments
Member 13142345 12-Jun-18 7:34am    
As per hotel structure their base level starts at 7, and then it is up to 20 floors. so after communicating with the support team of the key-card they told to place 1 in place of 7 in 32 bit charcter string and place 1 in place of floor the guest checkin

so i have written

If floor = 8 Then
FlrSelection1 = "00000000000000000000000011000000"
ElseIf floor = 9 Then
FlrSelection1 = "00000000000000000000000101000000"
ElseIf floor = 10 Then
FlrSelection1 = "00000000000000000000001001000000"
ElseIf floor = 11 Then
FlrSelection1 = "00000000000000000000010001000000"
ElseIf floor = 12 Then
FlrSelection1 = "00000000000000000000100001000000"
ElseIf floor = 13 Then
FlrSelection1 = "00000000000000000001000001000000"
ElseIf floor = 14 Then
FlrSelection1 = "00000000000000000010000001000000"
ElseIf floor = 15 Then
FlrSelection1 = "00000000000000000100000001000000"
ElseIf floor = 16 Then
FlrSelection1 = "00000000000000001000000001000000"
ElseIf floor = 17 Then
FlrSelection1 = "00000000000000010000000001000000"

but it is not generic. so i want to write a neat code to add the 1 based on floor number
Dave Kreskowiak 12-Jun-18 8:27am    
If you're doing something like that stack of IF's where each value you're checking for is just one more than the previous value, that should just scream ARRAY to you. The values you're checking for just become index values into the array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900