Solved

How do I write text data to a text box instead of a text file?

Posted on 2006-06-13
7
151 Views
Last Modified: 2010-04-30
Hi

I have been outputting data to a txt file which works fine. But rather than a txt file I need to use an open window with a text box. Lines of text are continually entered one at a time.
I use the following to open the file and write the data

Public Function WriteLineToFile(ByVal filename As String, ByVal outputLine As String)
    On Error GoTo fileError
   
    Dim ff As Integer
    ff = FreeFile
    Open filename For Append As #ff
    Print #ff, outputLine
    Close #ff
    Exit Function
   
fileError:
    MsgBox "Error writing to " & filename & vbCrLf & err.Description, vbExclamation, "Error " & err.Number
End Function

and the following under the click button
 WriteLineToFile outputlog, "Logged on user:" & "  " & name & "  " & Date & "  " & Time & "  " & "FFT" & " " & "Image Name:" & "  " & imagename

Here output log is a file, I want to change it to a text box. I have tried but keep getting errors

Experts can you help?
0
Comment
Question by:eneate
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16898082
First of all You have to create a form and add a TextBox to it, then add text to it

textBox1.Text = textBox1.Text & "Logged on user:" & "  " & name & "  " & Date & "  " & Time & "  " & "FFT" & " " & "Image Name:" & "  " & imagename
0
 

Author Comment

by:eneate
ID: 16898312
That works. I have it behind a command button when the button is clicked the text is added to the box. However liek this it only enter the line onnce. Every time the button is clicked I need it to go to the next line and print the same thing again. It is to be used as a image history.
Thanks
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 500 total points
ID: 16898369

you can use this code:

Public Function WriteLineToTextbox(ByVal txtBox As TextBox, ByVal outputLine As String)
   txtBox.Text = txtBox.Text & vbCrLf & outputLine
End Function


usage:

Private Sub Command1_Click()
   WriteLineToTextbox Text1, "This is the first line!"
   WriteLineToTextbox Text1, "this is the second line"
   WriteLineToTextbox Text1, "and this the third"
End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:eneate
ID: 16898500
Thanks that works. Is there a way to make it so that the user can not deleate or edit the text. Read only
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16898521

yes
in code:
text1.locked = true

in properties:

set the option locked from text 1 to true
0
 

Author Comment

by:eneate
ID: 16898531
Thank very much it works very well.
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16898559

thanks for the points, and happy coding!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

896 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

14 Experts available now in Live!

Get 1:1 Help Now