Solved

Visual Basic question

Posted on 1997-09-09
3
207 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

786 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