Results 1 to 5 of 5
  1. #1
    Join Date
    May 2003
    Posts
    26

    Unanswered: HELP .. adding 0001 + 1 = 2

    Anyone have any suggestions for how to convert a string ("0001") to represent a "formatted" number 0001 then add 1 so the result = "0002". My result is always 2!

  2. #2
    Join Date
    Aug 2003
    Posts
    29
    This is what I use. Maybe it will work for you

    Note : This only will work when the result is a string. If you assign the result to a numerical field the leading zeroes will be stripped off by Windows.

    1. Create a function called format (see code below)
    2. Number is the number you going to add to.
    3. Plus is the number (an integer) you want to add to Number
    4. Answer is the result.


    Private Function format(Number As Integer, Plus As Integer, Answer)
    a = Number + Plus
    l = Len(a)
    Select Case l
    Case 1
    Answer = "000" & a
    Case 2
    Answer = "00" & a
    Case 3
    ans = "0" & a
    Case Else
    Answer = a
    End Select

    End Function

    '-------------------------------------------------------------
    Private Sub Command0_Click()
    Call format(1, 1, Answer)
    TheAnswer = Answer
    End Sub

  3. #3
    Join Date
    Sep 2003
    Location
    Lancashire, UK
    Posts
    22
    Format the result using the Format function
    Result = Format(expression, "0000")

  4. #4
    Join Date
    Apr 2003
    Posts
    280
    Use the Val Function to convert the string to an integer

    Or

    Set a variable to an integer like

    Dim ValueNumber as Integer
    Dim TotalValueNumber as Intege

    TotalValueNumber = 0

    ValueNumber = txtNumber

    TotalValueNumber = TotalValueNumber + ValueNumber

  5. #5
    Join Date
    Aug 2003
    Location
    SW Ohio
    Posts
    198

    Re: HELP .. adding 0001 + 1 = 2

    Originally posted by ramonas
    Anyone have any suggestions for how to convert a string ("0001") to represent a "formatted" number 0001 then add 1 so the result = "0002". My result is always 2!
    format(cint("0001")+1,"0000"))
    Jim P.

    Supoorting Oracle, MSSQL7, Sybase 8, & Pervasive. Confusion Reigns

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •