Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Fields - Getting to the end of 1

Status
Not open for further replies.

BigMoon

Programmer
Nov 7, 2002
7
GB
I'm periodically reading a log file into a text field and would like to goto the end of the text in the field after each update.. is this possible? If so .. how??
 
Or you could try using the selstart and sellength property of the control, for instance in the got focus event

[tt]me!txtCtl.SelStart=me!txtCtl.SelLength[/tt]

- isn't this a forms question (forum702)?

Roy-Vidar
 
RoyVidar

The method you identified works fine until the text field height is reached, then when the VB moves the focus off to carry on processing, the text field the field 'resets'. I'm not sure if this can be got around?

PS its probably a forms question, but since I was driving it from VB....
 
I dont' understand the question, on my setup it works as it should. Some samples of behaviour and expected behaviour might help, as perhaps the current code would.

Roy-Vidar
 
Roy

You're solution works great if just atached to a button, or as an 'Got Focus' trigger. I am however using it as part of the function below..

basically, read a file and output file it to a text field if file has changed..

Function Run_Rsh_Command(strCommand As String, strDrive As String, strInfo As String, strForm As String) As Variant
On Error GoTo Err_Run_Rsh_Command

Dim strAppName As String, strOutFile As String
Dim lngStartTime As Long, lngEndTime As Long, lngPause As Long
Dim strOutput As Variant, strInput As String
Dim blnTimeout As Boolean, l As Long, x As Long, blnError As Boolean, blnFinished As Boolean
Dim Channel1 As Integer

'Get open input channel
Channel1 = FreeFile

Do
Open strOutFile For Input Shared As #Channel1

strOutput = ""

Do While Not EOF(Channel1)
Input #Channel1, strInput
strOutput = strOutput & strInput & vbCrLf
Loop

Close #Channel1

'If the input has changed, display it
If strOutput <> Forms(strForm).txtRshOutput Then
Forms(strForm).txtRshOutput = strOutput
Forms(strForm).txtRshOutput.Requery
Forms(strForm).txtRshOutput.SetFocus
Forms(strForm).txtRshOutput.SelStart = Forms(strForm).txtRshOutput.SelLength

'Reset Timer
lngStartTime = Timer
lngEndTime = lngStartTime + 180
End If

'Search for Error in output text
x = InStr(1, Forms(strForm).txtRshOutput, "Error")
If x > 0 Then
blnError = True
If Forms(strForm).lblWarning.Visible = False Then
Forms(strForm).lblWarning.Visible = True
End If

End If

'Look for End (Create baseline)...
l = InStr(1, Forms(strForm).txtRshOutput, "Finished")
If l <> 0 Then
blnFinished = True
End If

'Update timeout
lngStartTime = Timer
If lngStartTime >= lngEndTime Then
blnTimeout = True
End If

'Pause
lngPause = Timer
Do
DoEvents
Loop Until Timer > lngPause + 3

Loop Until blnFinished = True Or blnTimeout = True

If blnError Then
l = MsgBox("WARNING: Errors detected in log file..", vbCritical + vbOKOnly, strInfo)
Run_Rsh_Command = 255
Else
If blnTimeout = True Then
l = MsgBox("WARNING: Loop has timed out please check results..", vbCritical + vbOKOnly, strInfo)
Run_Rsh_Command = 255
Else
l = MsgBox("Complete.", vbInformation + vbOKOnly, strInfo)
Run_Rsh_Command = 0
End If
End If

Exit_Run_Rsh_Command:

Forms(strForm).lblInfo.Visible = False

Exit Function

Err_Run_Rsh_Command:
MsgBox "Run_Rsh_Command: " & strInfo & vbCrLf & Err.Description
Resume Exit_Run_Rsh_Command

End Function

I have set the text field to display 50 lines of text, your solution works great until the text output reaches 58 or so lines, then for all future updates the cursor appears to jump to the 58th line and go no further..

Hope this helps

Thanks

BigMoon
 
OK - I did ask for it;-)

I now think I understand the question. But I'm not sure what solution to suggest, it still behaves OK on my setup, on different tests (though a couple of times the sellength property reported wrong length).

Couple of things to try...

I can't see you perform anything on the control, other than the assigning of value, could you try moving the cursor placement to later in the function?

In stead of sellength, perhaps try the len function:

[tt]Forms(strForm)("txtRshOutput").SelStart = len(Forms(strForm)("txtRshOutput"))[/tt]

- in case the same anomalities I run accross might be what's causing the anomalities you experience

Or setfocus to another control prior to setting focus to this control again.

One of the more "dirty" variants, could be to alter the behaviour entering controls, in the start of the routine

[tt]dim lngCtlBeh as long
lngCtlBeh=application.getoption("behavior entering field")
application.setoption "behavior entering field",2
' i e altering to "Go to end of field"

' and in the exit clause, reset
application.setoption "behavior entering field",lngCtlBeh[/tt]

Roy-Vidar
 
Roy

Used the len method, now works perfect.

Thanks again

BigMoon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top