View Full Version : سوال: عمل replace در ابزار richtextbox
  
as987498749874
جمعه 02 خرداد 1393, 18:30 عصر
سلام دوستان 
من به یه مشکل اساسی خوردم
یه rtf درست کردم که می خوام بعد لود یه عمل replace توش انجام بشه،در صورتی که در خصوصیاتش اصلا نداره و وقتی از دستور replace استفاده میکنم یا استایل متن میره یا جایگزنی خراب در میاد
باید چه کنم؟؟؟/
مرسی
vbhamed
شنبه 03 خرداد 1393, 12:57 عصر
سلام
از تابع زیر برای تغییر استفاده کنید
Public Function FindReplaceRTB(rtb As RichTextBox, strFindString As String, strReplaceString As String) As Long
    Dim lFoundPos          As Long           'Position of first character
    'of match
    Dim lFindLength        As Long         'Length of string to find
    Dim bTryAgain          As Boolean
    Dim lOriginalSelStart  As Long
    Dim lOriginalSelLength As Long
    Dim iMatchCount        As Long
    With rtb
        'Save the insertion points current location and length
        lOriginalSelStart = .SelStart
        lOriginalSelLength = .SelLength
        'Cache the length of the string to find
        lFindLength = Len(strFindString)
        'Attempt to find the first match
        lFoundPos = .Find(strFindString, 0, , rtfNoHighlight)
        'If the First Item in the RTB is found then allow a second
        'Match to be attempted
        bTryAgain = IIf(lFoundPos = -1, False, True)
        Do While lFoundPos > 0 Or bTryAgain
            'When the last character is found exit
            If lFoundPos = Len(.Text) Then Exit Do
            'Reset the Try Again
            bTryAgain = False
            'Track Matches
            iMatchCount = iMatchCount + 1
            rtb.SelStart = lFoundPos
            'The SelLength property is set to 0 as
            'soon as you change SelStart
            .SelLength = lFindLength
            .SelText = strReplaceString
            'Attempt to find the next match
            lFoundPos = .Find(strFindString, lFoundPos + lFindLength, , rtfNoHighlight)
        Loop
        'Restore the insertion point to its original
        'location and length
        .SelStart = lOriginalSelStart
        .SelLength = lOriginalSelLength
    End With
    'Return the number of matches
    FindReplaceRTB = iMatchCount
End Function
روش استفاده :
    FindReplaceRTB RichTextBox1, "عبارت قبلي", "عبارت جديد"
R2du-soft
شنبه 03 خرداد 1393, 22:08 عصر
استاد یک سوال،وقتی از تابع استفاده میکنم از :
Public Function FindReplaceRTB(rtb As RichTextBox, strFindString As String, strReplaceString As String) As Long
ارور میگیره و برنامه اجرا نمیده!؟
vbhamed
یک شنبه 04 خرداد 1393, 10:11 صبح
سلام
دوست عزیز، خود شما به این سوال میتونی جواب بدی ؟
حداقل پیام خطا رو بزارید یا خود برنامه رو
R2du-soft
یک شنبه 04 خرداد 1393, 15:16 عصر
مشکل از اشتباه خودم بود :افسرده: ممنون مشکل حل شد :لبخند:
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.