determine number of characters up to a certain point

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slider
    New Member
    • Feb 2007
    • 27

    determine number of characters up to a certain point

    hey all, i have a set of numbers which looks like this

    Code:
    21551878283310414135344613310414135344613310468612568833104686125688331043180057716331044879441661331045148067733104487944166133104
    within this block of numbers are the numbers 33104 repeated where necessary. This is practically like a space or a comma to space out the numbers.

    I need a vb asp code which will determine the number of characters for each block of numbers up to the 33104's.

    so for instance 215518782833104 .
    i need the code to tell me that there are 10 numbers before the first 33104, then continue on and tell me how many numbers are in the second block of numbers before the next 33104

    any help will be great!
  • slider
    New Member
    • Feb 2007
    • 27

    #2
    ok i worked that problem out but now im getting an error message saying

    Type mismatch: 'cint'
    /site/enc.asp, line 227

    just so i dont have to paste all my code.. at the beginning of the code a number is turned into a string so it can be placed next to another number by using the + function.

    and here is my code to convert it back to a number so it can be calculated

    x = cint(newcode)

    ?? this has really stumped me! please neone>?

    Comment

    • jhardman
      Recognized Expert Specialist
      • Jan 2007
      • 3405

      #3
      the value of newcode must be a number between -32768 and 32767. Is it possible you are outside of this range?

      Jared

      Comment

      • slider
        New Member
        • Feb 2007
        • 27

        #4
        yea i am outside the range so i tried using clng and once again im out of the range so i made the numbers within the range and i still get the same error message.. type mismatch.

        to clearly explain what i am doing i am converting a letter into a numeric value and running it through a calculation, placing the value into a cookie or database and then reversing the calculations to end up with the original letter.

        so if i want to convert the letter s the code i am using is
        Code:
        case "s"
        encryption = cStr((6632*jday)^2 + jtime)
        code =code+"33104"+encryption
        this works fine. the 33104 is just an indicator like a space or comma to separate the different letters.

        now to reverse the numbers i am using this code
        Code:
        code = request.cookies("ENC")
        
        dim counter, newcode, oldcounter, newnewcode, x, l
        oldcounter = 1
        for i = 1 to len(code)
        
        counter = counter + 1
        
        curchar=mid(code,i,5)
        select case curchar
        
        CASE "33104"
        
        
        newcode = mid(code, oldcounter, counter-oldcounter)
        response.write "<p></p>"
        response.write newcode
        oldcounter = counter +5
         
        end select
        
        next
        once again this works but it wont let me perform any maths to it. and when converting it to a int or a lng it gives me the mismatch error.

        im so confused! any help will be great

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          This is strange, it should really work. I just tried this to test, and it worked just fine:[code=asp]<%
          dim myStr, myNum, list, x

          myStr = "a"
          response.write myStr & "<br>" & VBNewLine

          myStr = "12345"
          response.write myStr & "<br>" & VBNewLine

          myStr = myStr & 6
          response.write myStr & "<br>" & VBNewLine

          list = split(myStr, "4")

          for each x in list
          myNum = clng(x)
          response.write myNum & "<br>" & VBNewLine

          myNum = myNum + 1
          response.write myNum & "<br>" & VBNewLine

          next
          %>[/code] and this was the output: [code=output]a
          12345
          123456
          123
          124
          56
          57[/code]I'm essentially doing the same thing you are, so I don't see what the problem is. I'm manipulating the number as a string, then splitting it and working with it as a number. I guess I'll think about it for a while, but I haven't a clue.

          Jared

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            are you sure you are not using any non-numeric characters? that is the only time I get a mismatch error. If the number is too big it should give an overflow error.

            Jared

            Comment

            • slider
              New Member
              • Feb 2007
              • 27

              #7
              Originally posted by jhardman
              are you sure you are not using any non-numeric characters? that is the only time I get a mismatch error. If the number is too big it should give an overflow error.

              Jared
              hey! i am only using numbers in the string and i believe that the problem may lie in this line of code here
              Code:
              newcode = mid(code, oldcounter, counter-oldcounter)
              because i tried converting a string to a long out side of my for next loop and it worked. it seems like that when i use the mid code to shorten the string to avoid overflow it just dosnt like it

              it is very strange

              Comment

              • slider
                New Member
                • Feb 2007
                • 27

                #8
                ne one at all? i stil havnt been able to resolve this issue.

                Comment

                • slider
                  New Member
                  • Feb 2007
                  • 27

                  #9
                  ok i have made some progress but still no prize.

                  if i use this code
                  Code:
                  dim counter, newcode, oldcounter, newnewcode, x, l
                  oldcounter = 1
                  for i = 1 to len(code)
                  
                  counter = counter + 1
                  
                  curchar=mid(code,i,5)
                  select case curchar
                  
                  CASE "33104"
                  
                  
                  newcode = mid(code, oldcounter, counter-oldcounter)
                  response.write newcode
                  newcode = clng(newcode)
                  
                  oldcounter = counter +5
                   
                  end select
                  
                  next
                  i get a type mismatch error on the line with newcode = clng(newcode)

                  however, when i use that code outside of the loop, it works. So my theory is that the loop is causing the mismatch error...but why?
                  and the thing is..i need that code in the loop so i can preform calculations on the numbers it retrieves.

                  Comment

                  • jhardman
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3405

                    #10
                    Originally posted by slider
                    Code:
                    newcode = mid(code, oldcounter, counter-oldcounter)
                    ...
                    newcode = clng(newcode)
                    OK, how about this. The problem could be because you used the same variable name for these two different expressions. the first one returns a string, the second of course returns a long. I know that MS says all variables in vbScript are type variant, but it seems to me that usually it works more like "by type" or whatever it's called in VB, once it is used, you have to keep the same type. So try using a different variable name for these two lines.

                    Jared

                    Comment

                    • slider
                      New Member
                      • Feb 2007
                      • 27

                      #11
                      Originally posted by jhardman
                      OK, how about this. The problem could be because you used the same variable name for these two different expressions. the first one returns a string, the second of course returns a long. I know that MS says all variables in vbScript are type variant, but it seems to me that usually it works more like "by type" or whatever it's called in VB, once it is used, you have to keep the same type. So try using a different variable name for these two lines.

                      Jared
                      Hey thanks for your help but nah that dosnt work either. im still fair sure its the for next loop which is causing the error..because when i take the code which converts it back to a string and place it outside the loop.it works but it defeats the purpose :(

                      Comment

                      Working...