|
-
Apr 25th, 2000, 11:45 PM
#1
I'm trying to replace a word in .rtf file by multiple values. I wrote a code which calculates how many values needs to be replaced and replaces them.
staffCount = frmProposalLetter.lstSelected.ListCount
For idIndex = 0 To staffCount - 1
strRef = frmProposalLetter.lstSelected.List(idIndex)
rtbCoverLetter = Replace(rtbCoverLetter, "#Reference#", strRef, staffCount, vbTextCompare)
Next
I thought that each time when it goes through the loop a new value is added as many times as the value of staffCount is but instead it saves just the last value.
Can anybody help?
Thank you!
-
Apr 26th, 2000, 12:35 AM
#2
you are going trough the loop of listbox
not trough the file in which you have to replace the values
-
Apr 26th, 2000, 12:46 AM
#3
do you know how to resolve it?
-
Apr 26th, 2000, 01:16 AM
#4
what is this value? rtbCoverLetter
Is it a variable that holds informationt where
"#Reference#" has to replace?
-
Apr 26th, 2000, 01:34 AM
#5
rtbCoverLetter is a RichText Box control in my VB app. User selects some values from a listbox1 to a listbox2 and clicks Preview button. It loads a .rtf file (a template with some text) into another form. Now a word "#Reference#" in .rtf file has to be replaced with values from listbox2. The problem is that it loops through all values and replaces it with the last value. Here is a code:
Private Sub Form_Load()
Dim staffIDs()
Dim staffCount
Dim idIndex
Dim strRef As String
ShowCentered Me
'Load the Template
rtbCoverLetter.LoadFile "e:\VB\Jcon\CoverLetter.rtf"
'Replace words in brackets with variables
rtbCoverLetter = Replace(rtbCoverLetter, "#Date#", strProposalDate)
rtbCoverLetter = Replace(rtbCoverLetter, "#Chron_Number#", strCor_Reference_Number)
staffCount = frmProposalLetter.lstSelected.ListCount
For idIndex = 0 To staffCount - 1
rtbCoverLetter = Replace(rtbCoverLetter, "#Reference#", (frmProposalLetter.lstSelected.List(idIndex)), 1, staffCount, vbTextCompare)
Next
rtbCoverLetter = Replace(rtbCoverLetter, "#Reference#", strRef)
rtbCoverLetter = Replace(rtbCoverLetter, "#Subject#", strTitle)
rtbCoverLetter = Replace(rtbCoverLetter, "#ACOTR#", strACOTR)
End Sub
-
Apr 26th, 2000, 02:15 AM
#6
Try to Figure this out
you where missing Selected Propetry of the list box
and loop througn richtextbox
staffCount = lstSelected.ListCount
For idIndex = 0 To staffCount - 1
If lstSelected.Selected(idIndex) = True Then
For i = 1 To Len(rtbCoverLetter.Text)
rtbCoverLetter.Text = Replace(rtbCoverLetter.Text, "#Reference#", _
(lstSelected.List(idIndex)), 1, staffCount, vbTextCompare)
Next
End If
Next
-
Apr 26th, 2000, 02:35 AM
#7
I don't need Selected Property of the listbox. I need ALL values from the list box.
-
Apr 26th, 2000, 04:02 AM
#8
For idIndex = 0 To staffCount - 1
rtbCoverLetter = Replace(rtbCoverLetter.Text, _"#Reference#", (lstSelected.List(idIndex)), 1, 1, vbTextCompare)
Next
you used staffCount and it was count of your listbox items
replace for 1
and will work
-
Apr 27th, 2000, 09:44 PM
#9
I'm wondering if you tested it. It doesn't work! It does exactly the same thing as before but slower and with much more code. Aslo it works only if one value in the listbox is selected. What if I need all values in the listbox? With your code it doesn't work!
-
Apr 27th, 2000, 09:47 PM
#10
Fanatic Member
Anna,
Did you get my email this morning (japan time) with what I thought was wrong?
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Apr 27th, 2000, 09:51 PM
#11
Paul,
I got your email and send you an email back. The question is how to replace one #Reference# with multiple values from the listbox?
Thank you,
Anna
-
Apr 27th, 2000, 10:47 PM
#12
Of course I tried it and it works fine
'ShowCentered Me
'Load the Template
rtbCoverLetter.LoadFile "C:\Temp.txt"
'Replace words in brackets with variables
'rtbCoverLetter = Replace(rtbCoverLetter, "#Date#", strProposalDate)
'rtbCoverLetter = Replace(rtbCoverLetter, "#Chron_Number#", strCor_Reference_Number)
iPos = 1
staffCount = lstSelected.ListCount
For idIndex = 0 To staffCount - 1
rtbCoverLetter = Replace(rtbCoverLetter.Text, "Helen", _
***This where I changed staffCount for 1***
(lstSelected.List(idIndex)), 1, 1, vbTextCompare)
Next
'rtbCoverLetter = Replace(rtbCoverLetter, "#Reference#", strRef)
'rtbCoverLetter = Replace(rtbCoverLetter, "#Subject#", strTitle)
'rtbCoverLetter = Replace(rtbCoverLetter, "#ACOTR#", strACOTR)
-
Apr 27th, 2000, 11:46 PM
#13
Yes, it works fine if you wrote "Helen" 3 times in your .txt file. That's a straight forward situation. My question was how to replace it if you wrote "Helen" once in your ".txt" file but you have multiple values in the listbox. In real life it's a letter with a list of references and you never know how many references user wants to put there. My code worked fine when I was creating a ".txt" file and writing to a file but when I decided to use an ".rtf" template and Replace function it doesn't work.
-
Apr 28th, 2000, 12:25 AM
#14
i hope this time it will work
the problem is I dont get the whole picture.
are you trying to replase #Reference# with
multiple value from list box?
Hello #Replase# ok
has to look like
Hello one,two,three ok
if the values in list box are
one
two
three
staffCount = lstSelected.ListCount
'****************************************
'****************************************
Dim sValues As String
For idIndex = 0 To staffCount - 1
sValues = sValues & "," & lstSelected.List(idIndex)
Next
sValues = Left(sValues, Len(sValues) - 1)
rtbCoverLetter = Replace(rtbCoverLetter.Text, "#Reference#", _
sValues, 1, 1, vbTextCompare)
'****************************************************************
'****************************************************************
let me know if this what you need
what kind of obezyanka are you
monky or shinpadzi?
-
Apr 28th, 2000, 12:42 AM
#15
Thanks! It finally worked! I changed your code a little bit:
Dim sValues As String
rtbCoverLetter.LoadFile "C:\Temp.txt"
staffCount = lstSelected.ListCount
For idIndex = 0 To staffCount - 1
sValues = sValues & Chr(10) & lstSelected.List(idIndex)
Next
rtbCoverLetter = Replace(rtbCoverLetter.Text, "Helen", _
sValues, 1, 1, vbTextCompare)
*******************************
I'm just obezyanka. I guess, you speak Russian?
-
Apr 28th, 2000, 12:49 AM
#16
of cource
if you have any questions
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|