Solved

Visual Basic question

Posted on 1997-09-09
3
204 Views
Last Modified: 2013-11-25
How do I get a text box on a form to save as a text document
using, a 3d command button using it as a save button? How do
I code this so that i can reopen the same file without it
being scrambled and unreadable?
0
Comment
Question by:iriqus
3 Comments
 

Expert Comment

by:superjohan
ID: 1434483
Not a clue...
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1434484
iriqus: reject superjohan's ridiculous answer, and then we can deal with this.  Basically, you need to access the text box .text property, and using basic's file i/o, actually write that text to disk as a file.  Usually you need to have a file name and path designated, which you can obtain using the common dialogue control.  Just reject the above answer, and I or someone else who really knows will give you specific answers.
0
 

Accepted Solution

by:
hjack earned 50 total points
ID: 1434485
you have a couple things to consider here.
1. a textbox's text property can hold up to 32,766 characters
2. a string can only hold 255

this should read it in:
Private Function DataConverter( myfile As String)

Dim  InFileNo As Integer, Rec As String

On Error GoTo Dconvert



   
InFileNo = FreeFile
Open myfile For Input As #InFileNo



Do While Not EOF(InFileNo)
    Rec = Input$(255, InFileNo)
    myTexbox.text = myTextbox.text & rec
Loop

Close #InFileNo

Exit Function

Dconvert:
    Select Case Err
        Case Else
            Resume Next
       
    End Select
End Function


some variation of this should work to write...


Private Function DataConverter( myfile As String)

Dim OutFileNo As Integer, Rec As String


On Error GoTo Dconvert
   

OutFileNo = FreeFile
Open strTempFile For Output As #OutFileNo



Do While Not (intoffset > len(mytextbox.text)-255)

    Rec = mid(mytextbox.text,intOffset,255)
    Write #OutFileNo, Rec
 
Loop


Close #OutFileNo
Exit Function

Dconvert:
    Select Case Err
        Case Else
            Resume Next
       
    End Select
End Function


you should also look into these i.o. operators..

get  -- reads data
put --- writes data
print # --- writes data
LOF-- length of current file
EOF-- checks for end of file
Reset-- closes all files..

hope this or some variation could help..

jack

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

22 Experts available now in Live!

Get 1:1 Help Now