skip to Main Content

I am using VB .Net to access the eBay API and store all completed orders in a database. This database is then fed into a proprietary shipping system, which can not handle an order number larger than 20 characters. eBay returns an order number like so 230407279314-680141236013 which is too long. The order number is always 12 numbers a hyphen and 12 more numbers. What I need to do, is turn this (the result can be alpha numerical) into a shorter, unique order key to store in my database alongside the true orderId (so that this can be referenced by the shipping software instead of the actual order number). The reason for the 20 character limit is the barcode algorithm used. Is there any way to achieve this in VB .Net 2010? This number can be anything unique, so long as it does not exist already (even a good uniqueid function would work, but I would have to query the database to make sure it isn’t taken)

2

Answers


  1. You could store it as one unique hex number – say you’ve stored the ebay code as two strings: lefstr ‘-‘ rightstring. So in this case leftstring = ‘230407279314’ and rightstring = ‘680141236013’.

    once you’ve put them into a single string and retrieved the integer value from it you should be able to store it as a string in hex: id.toString(“x”)

    the id will be no more than 20 hexadecimal characters long 🙂

    Login or Signup to reply.
  2. You can actually turn that number into a 20 character string. You can split the numbers into six digit numbers. As each of those only need 20 bits to be stored, you can then represent them as a five digit hexadecimal number:

    230407 -> 38407
    279314 -> 44312
    680141 -> A60CD
    236013 -> 399ED
    

    Which would give the 20 character string:

    3840744312A60CD399ED
    

    Do it like this:

    Dim code As String = _
      Int32.Parse(orderNumber.Substring(0, 5)).ToString("x5") + _
      Int32.Parse(orderNumber.Substring(5, 5)).ToString("x5") + _
      Int32.Parse(orderNumber.Substring(11, 5)).ToString("x5") + _
      Int32.Parse(orderNumber.Substring(16, 5)).ToString("x5")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search