Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem to Convert a Javascript GTIN calculate function to VB.net

Problem to Convert a Javascript GTIN calculate function to VB.net

Scheduled Pinned Locked Moved Visual Basic
helpcsharpjavascriptdatabase
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    star_platinum
    wrote on last edited by
    #1

    Hello, I am not able to convert this function to VB code.... This is the javascript function to get the last digit of a GTIN number:

    factor = 3;
    sum = 0;

    var gNum = '1234564020233'

        for (index = gNum; index > 0; --index) {
            sum = sum + gNum.substring(index - 1, index) \* factor;
            factor = 4 - factor;
        }
        cc = ((1000 - sum) % 10);
    
        result = gNum + cc;
       
        }
    

    I have the problem to deal with the substring function. Anyone can help?

    D D 2 Replies Last reply
    0
    • S star_platinum

      Hello, I am not able to convert this function to VB code.... This is the javascript function to get the last digit of a GTIN number:

      factor = 3;
      sum = 0;

      var gNum = '1234564020233'

          for (index = gNum; index > 0; --index) {
              sum = sum + gNum.substring(index - 1, index) \* factor;
              factor = 4 - factor;
          }
          cc = ((1000 - sum) % 10);
      
          result = gNum + cc;
         
          }
      

      I have the problem to deal with the substring function. Anyone can help?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      OK, JavaScript substring returns the string enclosed by the start and ending values. In your case that would be index - 1, and index. It appears that index starts out with the length of the string in gNum and goes backwards by -1 with each iteration.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • S star_platinum

        Hello, I am not able to convert this function to VB code.... This is the javascript function to get the last digit of a GTIN number:

        factor = 3;
        sum = 0;

        var gNum = '1234564020233'

            for (index = gNum; index > 0; --index) {
                sum = sum + gNum.substring(index - 1, index) \* factor;
                factor = 4 - factor;
            }
            cc = ((1000 - sum) % 10);
        
            result = gNum + cc;
           
            }
        

        I have the problem to deal with the substring function. Anyone can help?

        D Offline
        D Offline
        Dave Doknjas
        wrote on last edited by
        #3

        factor = 3
        sum = 0
        Dim gNum As String = "1234564020233"

        For index = gNum To 1 Step -1
        sum = sum + gNum.Substring(index - 1, index - (index - 1)) * factor
        factor = 4 - factor
        Next index

        cc = ((1000 - sum) Mod 10)
        result = gNum + cc

        David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

        S 1 Reply Last reply
        0
        • D Dave Doknjas

          factor = 3
          sum = 0
          Dim gNum As String = "1234564020233"

          For index = gNum To 1 Step -1
          sum = sum + gNum.Substring(index - 1, index - (index - 1)) * factor
          factor = 4 - factor
          Next index

          cc = ((1000 - sum) Mod 10)
          result = gNum + cc

          David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

          S Offline
          S Offline
          star_platinum
          wrote on last edited by
          #4

          Hi David, I got this error: System.Data.Index' is not accessible in this context because it is 'Private'.

          D 1 Reply Last reply
          0
          • S star_platinum

            Hi David, I got this error: System.Data.Index' is not accessible in this context because it is 'Private'.

            D Offline
            D Offline
            Dave Doknjas
            wrote on last edited by
            #5

            It must be due to 'index' not being declared. Try:

            For index As Integer = gNum To 1 Step -1

            David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups