Solved

use of vbKeyBack

Posted on 2001-08-21
12
1,675 Views
Last Modified: 2008-01-16
I want to be able to use vbKeyBack in a RichTextBox. The idea is as follows:

If I have a text string in the RTB such as 112233, I want to then use vbKeyBack & vbKeyBack so as to delete the last two characters, in this example the rtb would finally read 1122.

I tried the following:
Form1!rtbTemp.text = vbKeyBack & vbKeyback  (etc...)

but what I got was the ASCII value (88 in other words) in the rtb.

What I want is a way to delete a certain number of characters from the rtb

Thanks

Ron Lesser
0
Comment
Question by:rlesser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 6410720
One way may to be to simply use SendKeys:

RichTextBox1.SetFocus
SendKeys "{BACKSPACE}"
SendKeys "{BACKSPACE}"


If you are always removing from the end of the text, you could try:

RichTextBox1.Text = Left$(RichTextBox1.Text, Len(RichTextBox1.Text) - 2)
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6410802
Or.. use the Replace function

Form1!rtbTemp.text = Replace(Form1!rtbTemp.text, "112233", "1122")

Or the.. SelStart, SelLength, SelText properties of the RichTextBox (<--- Great for reducing flicker)

I suppose we need a better context for your question.. <smile>.

0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6410835
to expand on AzraSound's comment, i believe you can also go

SendKeys "{BACKSPACE 2}" to backspace twice...

Correct me if Im wrong!
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 28

Expert Comment

by:AzraSound
ID: 6410845
Yup, youre right.    :-)
0
 

Author Comment

by:rlesser
ID: 6410847
Thanks for your comments. Here is more information about the context (I'm trying to be brief):

I have a multiselect list box that I'm using to supply a set of descriptors. The user selects the descriptors that then are "printed" to the rtb, with a comma after each selected descriptor. For example, I want

"the colors are red, green, yellow" and not
"the colors are red, green, yellow,"

Therefore I want to use my loop to list all of the descriptors, ie red, green, yellow in this example, and then delete the last comma.

Thanks again

Ron Lesser
0
 

Author Comment

by:rlesser
ID: 6410848
Thanks for your comments. Here is more information about the context (I'm trying to be brief):

I have a multiselect list box that I'm using to supply a set of descriptors. The user selects the descriptors that then are "printed" to the rtb, with a comma after each selected descriptor. For example, I want

"the colors are red, green, yellow" and not
"the colors are red, green, yellow,"

Therefore I want to use my loop to list all of the descriptors, ie red, green, yellow in this example, and then delete the last comma.

Thanks again

Ron Lesser
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6410872
Option #1

The first item is written outside of the loop, and then the rest is written, e.g.,

strTemp = lstBox.List(0)
For i = 1 to lstBox.ListCount - 1
   strTemp = strTemp & ", " & lstBox.List(i)
Next



Option #2
Use something like the Left$ operator to chop off that last comma once you have the string completely built.


Option #3 (VB6 only)
Create an array of the items selected, and then use the Join function to biuld your string, e.g.,

Dim vArr As Variant
Redim vArr(0 To lstBox.ListCount - 1)
For i = 0 To lstBox.ListCOunt - 1
   vArr(i) = lstBox.List(i)
Next
strFinal = "the colors are " & Join(varr, ", ")
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6410898
Here's another way

Private Sub Command1_Click()
    Dim x As String
    x = "121212,2121212,212121,"
   
    If InStr(Len(x), x, ",") Then
       'show it
       MsgBox x
       'trim it
       MsgBox Left(x, (Len(x) - 1))
    End If
End Sub
0
 

Author Comment

by:rlesser
ID: 6411005
I like the solution because of its simplicity.  I also thought that {BACKSPACE 2} would be a simple way of doing this.

Thanks!
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6411062
Glad we could help  :-)
0
 

Author Comment

by:rlesser
ID: 6412124
I thought I had this working, but now it's not. I've obviously missed a step somewhere. Here is the whole code snippet. You can see where I put the comma in on the third line and I've commented below where I try to remove the last comma.

Can you help me figure out where I've gone astray?

Thanks

For intLoopIx = 0 To lstTech1.ListCount - 1
    If lstTech1.Selected(intLoopIx) Then
    Form1!rtbTemp.text = lstTech1.List(intLoopIx) & ",  "
   
        Form1!rtbSelection.SetFocus
    strWork = Form1!rtbSelection.text
    Wstart = Form1!rtbSelection.SelStart
    Wlength = Form1!rtbSelection.SelLength
   
    Clipboard.Clear
    Clipboard.SetText Form1!rtbTemp.text
   
    strClip = Clipboard.GetText()
    strWork = Left$(strWork, Wstart) + strClip + _
        Mid$(strWork, Wstart + Wlength + 1)
    Form1!rtbSelection.text = strWork
    Form1!rtbSelection.SelStart = Wstart + Len(strClip)
   
   
    End If
    Next intLoopIx

'get rid of comma

If lstTech1 > "" Then
    Form1!rtbSelection.SetFocus
    Wstart = Form1!rtbSelection.SelStart
    Wlength = Len(strWork)

Form1!rtbSelection.text = Left$(Form1!rtbSelection.text, Len(Form1!rtbSelection.text) - 2)
Form1!rtbSelection.SelStart = Wstart + Wlength
End If
0
 

Author Comment

by:rlesser
ID: 6413151
never mind. I just figured out that I had an extra space in my string: ",   " instead of "  "

:.<   :.>

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month6 days, 19 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question