Results 1 to 3 of 3

Thread: Append to string -1

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    I have a big string
    {\rtf1\ansi\ansicpg1252\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fswiss Abadi MT Condensed;}{\f3\fswiss MS Sans Serif;}{\f4\fswiss\fprq2 System;}}
    {\colortbl\red0\green0\blue0;\red128\green64\blue0;\red128\green255\blue0;\red128\green255\blue128;\ red255\green128\blue0;\red255\green128\blue64;\red128\green128\blue0;\red255\green255\blue128;\red64 \green0\blue0;\red255\green255\blue0;\red128\green64\blue64;\red255\green0\blue0;\red255\green128\bl ue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green128\blue0;\red128\green0\blue128;\red128\ green0\blue255;\red255\green0\blue128;\red0\green64\blue0;\red255\green128\blue255;\red64\green0\blu e64;\red128\green0\blue64;\red255\green0\blue255;\red255\green128\blue192;\red192\green192\blue192;\ red0\green0\blue64;\red128\green128\blue192;\red128\green128\blue255;\red0\green128\blue192;\red0\gr een128\blue255;\red0\green0\blue160;\red0\green0\blue128;\red0\green0\blue255;\red0\green64\blue128; \red64\green128\blue128;\red128\green255\blue255;\red0\green64\blue64;\red0\green128\blue64;\red0\gr een255\blue255;\red0\green255\blue64;\red0\green255\blue128;\red128\green128\blue64;\red0\green128\b lue128;\red64\green0\blue128;}

    I Need to chop off the last "}" and add to so I made this
    Code:
    Public Sub Append_rtf(toappend As String)
    
    Dim fulllenght, insertpoint As Integer
    Dim oldrtf, newrtf As String
    '****************************************
    ' - created Oct ,14 2000 by []Private[]
    ' adds formated text to a RTB
    '
    '****************************************
    
    'assign varriables
    oldrtf = Space(Len(header) + Len(toappend))
    oldrtf = header$
    Debug.Print oldrtf
    fulllenght = Len(oldrtf)
    insertpoint = InStrRev(oldrtf, "}") ' assumes that the end of the rtf code is like "\par Test}"
    'MsgBox insertpoint
    'do a midstring here to insert the line
     Mid(oldrtf, insertpoint, Len(toappend) + fulllenght) = toappend
     Debug.Print oldrtf
    End Sub
    and call it like this
    Code:
    Append_rtf "\deflang1033\pard\plain\f2\fs20\cf12 test }"
    but it doesn't work . It only overwrites the last "}" in the target string with the first char in the string to append . Why ?

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi PRIVATE1 !!!

    try this version - documented

    -cu TheOnly

    Public Sub Append_rtf(toappend As String)

    Dim fulllenght, insertpoint As Integer
    Dim oldrtf, newrtf As String
    '****************************************
    ' - created Oct ,14 2000 by []Private[]
    ' adds formated text to a RTB
    '
    '****************************************

    'assign varriables
    'oldrtf = Space(Len(header) + Len(toappend))

    oldrtf = header$
    Debug.Print oldrtf
    fulllenght = Len(oldrtf)
    'get the last "}" and substract -1 = append posstion
    insertpoint = InStrRev(oldrtf, "}") -1
    'MsgBox insertpoint
    'now get all char we need and append the other string
    oldrtf = left(oldrtf,insertpoint) & toappend
    Debug.Print oldrtf
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Thank you . Works great
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

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