Solved

Combine the output of multiple values

Posted on 2006-05-09
268 Views
Dear Expert;

In c# .NET I need to combine the following values to create a unique inventory control number for a product.  The method must:

Get 2 digit Plant number from Table “PLANTMASTER” WHERE  “currentLocation” = 1
Get 2 digit year from system DATE/Time
Get last ticket number (5 digits) from table and increment by one

Combine these values into value called newTicket and display it in the appropriate text box on a form.

I thought this would be easy enough but I am struggling wth it.

Thanks... Ed&Rosie
0
Question by:edrosie

LVL 19

Accepted Solution

One thing you can do is use hex numbers and bit shifting.  For example, use a long integer as the value you want:

0x0000000000000000

Then, the 2 digit plant number could be like 0xA5

The Year is another two digit hex number like 0x06

Five digit ticket could be stored as a normal int:  0x004A

Now, put these together like this:

0x0000000000000000 | 0x004A to make the value 0x000000000000004A.
Shift it left by 16 bits:
0x000000000000004A << 16 which makes 0x00000000004A0000

Now or it again with the next value which is the one digit reader value:
0x00000000004A0000 | 0x01 and shift by 8 because you only need one byte this time
0x00000000004A0001 << 8 is 0x00000000004A0100

or the next value, the year for 0x00000000004A0100 | 0x06 = 0x00000000004A0106
shift left by 8:
0x000000004A010600

Now do the last one:
0x0000004A010600A5

Now you have all your info stored in one number: 0x0000004A is the ticke number,
0x04A, 0x01, and 0x06 are all available.  You can get to them by using the logical and:

0x0000004A010600A5 & 0x0000FFFF00000000 will give you 0x0000004A00000000

etc.

0

Author Comment

thanks for responding so quickly.

unfortunatly I have to use an existing format in order to coexist with the current system

The existing format is 10 digits numeric

example:  0806112345

Where:

08 = plant number
06 = year
12345 = item number which must incriment by one each time a new ticket is created.

Thanks for your help on this
0

Author Comment

Thank you for responding so quickly
0

Featured Post

Suggested Solutions

INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …