Go Premium for a chance to win a PS4. Enter to Win


Data Flow Window

Posted on 2000-03-31
Medium Priority
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 150 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>
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


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

Hire Technology Freelancers with Gigs

Work with 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

971 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