Data Flow Window

Posted on 2000-03-31
Last Modified: 2010-05-02
I need to display data (ASCII text) being read from a serial port in a TextBox or on a Label.  I'm reading the data from the serial port into a string using a timer.  The string contains CR and LF characters.  I don't only want to display one string, but as many strings as possible, depending upon the size of the TextBox/Label. If the TextBox/Label is full I want to remove the oldest line. I want the string to be divided only if it contains a CR/LF character or the TextBox/Label is not wide enough. The code also should be as fast as possible.
Any good ideas?
Question by:OTveit
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
  • 4
  • 3
LVL 14

Accepted Solution

wsh2 earned 50 total points
ID: 2673467
1.  Start a new Standard.exe project
2.  Add a Command Button (Command1)
3.  Add a Textbox (Text1) and set the Text1.Multiline property to True and the Text1.Scrollbars property to 2.
4.  Copy and paste the following code into the Form1 code window.
5.  Press F5 to run. Type anything you like in the textbox.. and then press the command button to write 51 lines.

<----- Code Begin ----->

Option Explicit
Private m_intTextLines As Integer
Private m_intTextLimit As Integer

Private Sub Form_Load()

'  At design time
'  Please SET Text1.MultiLine = True
'  Please SET Text1.ScrollBars = 2
   m_intTextLimit = 50

End Sub

Private Sub Command1_Click()
   Dim intindex As Integer
   For intindex = 1 To 51
      xAdd2Textbox ("Data " & intindex & vbCRLF)
   Next intindex

End Sub

Private Sub xAdd2Textbox(ByVal strInput As String)
   If m_intTextLines < m_intTextLimit _
      m_intTextLines = m_intTextLines + 1
      Text1.Text = Text1.Text & strInput
      Dim strWork As String
      strWork = Right(Text1.Text, Len(Text1.Text) _
         - (InStr(1, Text1.Text, vbCrLf) + 1))
      Text1.Text = strWork & strInput
   End If

End Sub

<----- Code End ----->

The textbox will automatically accomodate the CrLf (new line) and if the text line is longer than the width of the textbox, automatically wrap it over onto 2+ lines.


Expert Comment

ID: 2673678
You the Comm control's event instead of timer to poll for the data arriaval
LVL 14

Expert Comment

ID: 2673829
Good point vbGuru.. <smile>
Technology Partners: 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!


Author Comment

ID: 2683133
I've made some changes and it works. Is there a trick to make the cursor dissapear from the text box? It's also a little bit flickery...
LVL 14

Expert Comment

ID: 2684511
I don't know that you want the Cursor to disappear.. that can be VERY confusing to a user.. and in most cases, users will think that there is something wrong with the computer.

In lieu of that, what I would suggest, is using the Text.MouseIcon property to have the cursor change to a different Icon whenever the user crosses over into Text space.. <smile>.

Author Comment

ID: 2700280
Oh, sorry ... a missunderstanding. I do not want the mouse pointer to dissapear, but I want the cursor "|" blinking in the TextBox to dissapear.
LVL 14

Expert Comment

ID: 2701005
That is known as the caret.. <smile>. Change property Text.Locked = True to make it go away.. <smile>.

Author Comment

ID: 2704461
Ok, Thanks!

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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