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
  • 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>
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.


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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now