Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving Long Strings

Posted on 1998-12-11
7
Medium Priority
?
149 Views
Last Modified: 2010-05-03
I've seen similar questions address but I have a specific problem.  I want to store a long string to a file (either ADO DB or text file, I don't care), but this string can contain quotation marks and control characters.  Is there a simple easy way to do this ?
(Let's say the string can be as long as 64000 characters)

-Jason
0
Comment
Question by:jmalcolm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:jmalcolm
ID: 1449553
P.S.  The basis for this question is that I have an rich text control that I want to save to a file.

0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1449554
Here is an easy sub routine you can use to setup the string for saving in either a text file or a DB.  Just send the string to the routine, and it will return a string ready to be saved in a DB or text file.

Public Function Apostrophe(sFieldString As String) As String

              If InStr(sFieldString, "'") Then
                     Dim iLen As Integer
                     Dim ii As Integer
                     Dim apostr As Integer
                     iLen = Len(sFieldString)
                     ii = 1

                            Do While ii <= iLen
                                    If Mid(sFieldString, ii, 1) = "'" Then
                                    apostr = ii
                                   sFieldString = Left(sFieldString, apostr) & "'" & _
                                   Right(sFieldString, iLen - apostr)
                                    iLen = Len(sFieldString)
                                    ii = ii + 1
                                    End If
                                    ii = ii + 1
                            Loop

              End If

       strClean = sFieldString

End Function

0
 

Author Comment

by:jmalcolm
ID: 1449555
Well, what I'm actually looking for is the specifics on how to save a large string, not just convert the Quotation marks.  Here's my dilemma..I have huge chunk of text from an rich text control.  If I try to save it using the "#write" command, carriage returns, quotation marks, etc. can cause problems when I try to #input it back in.  If I try saving it as a binary file, I can #put string easy enough, but to read it back in, must I get it 1 byte at a time? If I try to read in longs then I'll have to bit shift them to get the respective bytes and this is too slow.  I'm just looking for an easy (and acceptably fast)way to save and retrieve these big strings.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:lankford
ID: 1449556
This may be a little too obvious, but try simply binding the control to a data control.

Create a table in Access that contains a column that is set to store binary data.

Hook this up to your rtf control and *bang*, you information gets stored in the database file whenever the user makes any changes to it.

You can spice this idea up a little bit to actually store and retrieve the information on command whenever you want. You get the idea.

Lankford

ps - I've already done this with a project I am working on it is works great.
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 200 total points
ID: 1449557
Use the Put statement as follows:

Dim intFile As Integer
intFile = FreeFile

'Clear out previous data
Open strFile For Output As #intFile
Close #intFile

'...

'Write big string
intFile = FreeFile
Open strFile For Binary As #intFile

'Note the two commas!
Put #intFile,,strYourBigString

Close #intFile
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1449558
PS - Please note that the Put statement will copy the exact contents of your string to the file, including any special characters and it won't add other characters (unlike, e.g., Print)
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1449559
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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 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…
Suggested Courses

722 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