String function questions

NachoMan

Registered User.
Local time
Today, 01:25
Joined
Sep 28, 2003
Messages
56
Friends,
I'm having difficulty accomplishing a few things that I'm sure can be done with some built in string functions.

I have a memo form which I need to perform a "quasi-tab." I already know a way to simulate a tab in a memo field by trapping keycodes and all, but it still does not do exactly what I need.

When the user presses tab inside my memo field, I need:

1.) the cursor to go back to the beginning of the current line,
then,
2) move the cursor ten spaces forward.

The second part has been more problematic than the first. The only way I know how to move the cursor ten spaces is to add spaces like this " " . this creates an empty string that I don't want. Its hard to explain clearly what I need.

Basically I have a transcript form that shows verbatim transcriptions of callers lIke this.

ID: TRANSCRIPT
Joe: Hey, this is Joe.
Mike: Hey, Joe, this is Mike.
Lou: Hey, this is Lou.

After the user types in the name, he/she presses 'tab.' The way I had it before, would just add ten spaces from where tab was pressed. This, however, results in the transcript text being out of alignment like this.

Joe: Hey, this is Joe.
Mike: Hey, Joe, this is Mike.
Lou: Hey, this is Lou.

So, again I need to go back to the start of the line and move forward ten spaces WITHOUT ERASING THE CALLER ID NAMES.

Is this possible or should I just explore the RTF control I keep hearing about? I don't want to have to worry about missing references or anything. If someone has any insight I would appreciate it a great deal. Thanks.
 
Nacho,

An intriguing problem. The TAB key will move you to the next
field. This method just looks at the position in the line of the
":". I just played with this a little.

I put two public variables at the top of your form code:

Public IsNewLine As Boolean
Public intChar As Integer

In the form's OnOpen event I put:

IsNewLine = False
intChar = 0

Then I used the OnChange event of the memo field to put:
Code:
If Right(Test.Text, 1) = Chr(10) Then
   IsNewLine = True
   intChar = 0
Else
   If Right(Test.Text, 1) = ":" And IsNewLine = True Then
      IsNewLine = False
      Test.Text = Test.Text & Space(9 - intChar) & "_"
      Me.Test.SelStart = Len(Me.Test.Text) - 1
   End If
   intChar = intChar + 1
End If

I had to put the "_" after the spaces because for some reason
Access wouldn't let me just append spaces. I wasn't gonna
spend any more time figuring out why.

Anyway, it is a starting point, keep me posted.

Wayne
 
Question

Did you actually get this to work? What exactly did it do for you, because mine did nothing. The only thing I added was a trap fo the Keycode 9 (tab) by setting it to 0, and the rest was the same. Thanks again for the response.
 
Last edited:
Can I ask why this is important? :confused:

Or just ask why, regarding the transcripts?
 
Beginning of line in memo field

What I think I need is a way to move to the beginning of the line in the memo field, then move forward ten spaces without overwriting the previous text in that line. Everything I have tried up to this point merely creates a set number of spaces from where I tabbed. This is not a true tab, because the tab positions are not set a fixed distance from the beginning of the line, and all of my text ends up out of alignment.

First, I imagine that I need to go to the beginning of the current line (HOME).
Is there some string function that allows one to move the cursor forward without actually creating spaces and thereby overwriting the text I've written? Probably not.
 
Nacho,

Yeah, I had my sample working, but didn't want to spend the
time to refine it.

What you really need to do here is make it into two fields.
PersonName and Statement.

Wayne
 
Nacho,

Take a look at the attached db.

This was an interesting task and I think that I really would
prefer to seperate the memo into two fields.

Have a look.

Take care,
Wayne
 

Attachments

This one only Tabs if you are on the last line.
It probably has other ‘indiscretions’ as well.


Code:
Option Explicit
Option Compare Text


Private Sub txtMyText_KeyDown(ByRef intKeyCode As Integer, _
                              ByRef intShift As Integer)
    Dim lngPosition  As Long
    Dim lngNumSpaces As Long
    
    If intKeyCode = 9 Then
        intKeyCode = 0
  
        If Me.txtMyText.SelStart = Len(Me.txtMyText.Text) Then
  
            For lngPosition = Len(Me.txtMyText.Text) To 1 Step -1
            
                If Asc(Mid$(Me.txtMyText.Text, lngPosition, 1)) = 10 Then
                    Exit For
                End If
            
            Next lngPosition
            
            lngNumSpaces = 10 - (Len(Me.txtMyText.Text) - lngPosition)
            
            If lngNumSpaces > 0 Then
                Me.txtMyText = Me.txtMyText.Text & Space(lngNumSpaces)
            End If
            
            Me.txtMyText.SelStart = Len(Me.txtMyText.Text)
            
        End If
        
    End If

End Sub
Hope that gets you closer to your goal.

Regards,
Chris.
 
Ah!…too slow again. And an attachment. :(
 

Attachments

Hey Chris,

I didn't know that one could "trap" a Tab character. That does
make it a lot easier. I like your version better than mine.

I learned a few things from this thread.

see ya,
Wayne
 
Last edited:
Yes Wayne it was an interesting exercise and you are correct about the non-proportional font, it just won’t work without one.

Anyhow, it’s getting near time to go and do a little quality control testing of the amber fluid at the local pup. :D

Regards,
Chris.
 
Chris,

I too am outta here. I used the wrong event in my sample. I
used the OnChange which opened up a whole new world of
problems. Your using the KeyDown was much easier.

Wayne
 
Thanks, well done.

Sorry, I haven't responded sooner. This is great. I really appreciate both of your efforts. This was a problem that I was just resolving myself to dealing with. It wasn't a show-stopper problem, but things work a lot nicer with this solution. I will attempt to resolve the last line limitation. Thanks again for all of your help! :cool:

-Lou
 
Last edited:

Users who are viewing this thread

Back
Top Bottom