Results 1 to 4 of 4

Thread: Simple format question

  1. #1

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384

    Simple format question

    I've got a string wich I want to right justify and the max lenght is 6 Ex: if I got 3 char in the string I would like to get 3 spaces then the 3 chars.

    Ex: aaa -> ___aaa

    thanks
    COBOL sa suce !!!

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    VB Code:
    1. Private Function JustifyText(ByVal strText As String, ByVal intMaxLen As Integer, ByVal strFillChar As String) As String
    2.  
    3. On Error Goto JustifyText_Error
    4. If intMaxLen - Len(strText) > 0 Then
    5.   JustifyText = String(intMaxLen - Len(strText), strFillChar) & strText
    6. Else
    7.   JustifyText = strText
    8. End If
    9. Exit Function
    10.  
    11. JustifyText_Error:
    12. Err.Clear
    13. JustifyText = strText
    14. End Function

    in your example:
    Debug.Print JustifyText("aaa", 6, " ")

  3. #3
    Swatty
    Guest

    warm smell of colitas rising up to the air

    use this first param is the length of the string to return, second one your string and third the values you want to fill up
    VB Code:
    1. Public Function Numb(lengte As Integer, waarde As String, voorzetsel As String) As String
    2.     Dim i As Integer
    3.     Dim temp As String
    4.  
    5.     For i = Len(temp) + 1 To lengte
    6.         temp = voorzetsel & temp
    7.     Next i
    8.     Numb = Right(temp, lengte)
    9. End Function

  4. #4
    Lively Member
    Join Date
    Jun 2002
    Location
    Kuwait
    Posts
    85

    Re: Simple format question

    dim ln as integer
    dim i, j as integer
    dim str as string


    ln=len(yourstring)

    i = 6 - ln

    if i>0 then

    str=""

    for j = 0 to i
    str = stR & " " 'Concatenate space
    next

    yourstring = str & yourstring

    else

    yourstring=yourstring

    end if



    So youstring will be rightjustified. But are you sure that initially yourstring does not contain more than 6 characters.
    Your attitude determines your altitude!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width