Solved

Working with strings

Posted on 2000-02-24
34
301 Views
Last Modified: 2010-05-02
Ok, who know's the answer to this one?
I have a file: file.txt, somewhere in this file is the following:
--------------------------------------

Spool 1
facts go here

spool 2
more facts go here

Spool 3
last of facts go here

--------------------------------------
What I need to do is search through the file until I find spool 1, then replace anything that may be between Spool 1 and Spool 2. So, "Facts go here" would be replacd with "No facts available"
0
Comment
Question by:RandyB30
  • 16
  • 8
  • 7
  • +2
34 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2555603
Something like this perhaps?


Dim SourceFilenr As Integer
Dim DestFilenr As Integer
Dim sRow As String
Dim bAdd As Boolean

bAdd = True
SourceFilenr = FreeFile
Open SourceFilename For Input As #SourceFilenr
DestFilenr = FreeFile
Open DestFilename For Output As #DestFilenr
Do Until EOF(SourceFilenr)
  Line Input #SourceFilenr, sRow
  If bAdd Then Print #DestFilenr, sRow
  If (sRow = "Spool 1") Then
    bAdd = False
    Print #DestFilenr, "No facts available"
  ElseIf (Not bAdd) And (sRow = "Spool 2") Then
    bAdd = True
    Print #DestFilenr, sRow
  End If
Loop
0
 
LVL 4

Expert Comment

by:PBuck
ID: 2555746
I use a richtextbox for something for similiar.  Its very fast and effective (especially since the Richtextbox can handle huge filesizes).

'Load the file into the richtextbox
frmMain.RTextbox.LoadFile File.txt, rtfText

Searchtxt1 = "Spool 1"
Searchtxt2 = "Spool 2"
Searchtxt3 = "Spool 3"

    CompVal1 = frmMain.RTextbox.Find(Searchtxt1, , , rtfWholeWord)
    CompVal2 = frmMain.RTextbox.Find(Searchtxt2, , , rtfWholeWord)
    CompVal3 = frmMain.RTextbox.Find(Searchtxt3, , , rtfWholeWord)
    'These provide the position number of the (S) in Spool

    If (CompVal1 <> -1) and (CompVal2 <> -1) Then  'Found a match of Spool 1 & 2
      frmMain.RTextbox.SelStart = CompVal1 + len(Searchtxt1) 'Start from ending of "Spool 1"
      frmMain.RTextbox.SelLength = CompVal2 - (Compval1 + len(Searchtxt1))
      frmMain.RTextbox.SelText = "No facts available"

'** This is not completed code - I appologize (I got to head out of the office real quick).  But the above will replace everything from Spool 1 to Spool 2 equal to "No facts available"

'** Then just perform the same features for Spool 2 to Spool 3.  You place these in an array and perform a loop.  I wasn't sure if you said that the Spool 1,2 and 3 was always present within the file?
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2555822

1) The code I submitted can handle larger files than a richtextbox

2) The richtextbox can seem to be fast when dealing with smaller files, but when the files get bigger the richtextbox is *really* slow since the data is interpreted as one single big string.

3) You can use the Timer function to time a function with code like

    Dim OldTimer As Single
    OldTimer = Timer
    <do stuff>
    Me.Caption = Timer - Oldtimer

    This way is way more accurate than just looking at the richtextbox, see that it sure looks like it does the task pretty fast, and not knowing how fast it should be using code without controls.
0
 
LVL 4

Expert Comment

by:PBuck
ID: 2555941
You are obsolutely correct about the file size difference.  But your way is assuming the Spool 1 is on a line by itself and that there is *only* one line of data between the Spools.  Through the richtextbox, it will leave no doubt when replacing everything from Spool 1<---->Spool 2<--->Spool 3.  

As for the *really* slow comment, that is totally dependant on machine speed and file size.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2556171
Read my code again, I haven't run it but it will work for more than just one line between the "Spool 1" and "Spool 2" lines.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2556175
And you can also see at the overhead needed for the two solutions.

   Richtextbox solution = 280kb for the dll and 200kb for the ocx
   Pure code solution = no overhead
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2557038
This may not be the solution for you, depending on what exactly you are trying to do.

If you have control over the format of the file, and it is meant purely for i/o and not as a text document per se, you could structure it as an INI file, ie

[Spool1]
Facts = "Facts"

[Spool2]
Facts = "More facts"

[Spool3]
Facts = "Last Facts"

Then use the GetPrivateProfileString and WritePrivateProfileString APIs to read and edit the file (you can still name the file as *.TXT). ie

Call WritePrivateProfileString("Spool1", "Facts", "No facts available", "c:\myfile.txt")

This is a much faster method than using Rich Text Boxes etc.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2558506
If this is a larger question on strings (for larger files), then I'd say try using parsing for tokens. In sample, 'Spool' becomes a token. If the line input goes as above to sRow:

Dim token As String
token = Left$(sRow, 6)

For this simple exercise, you then check your token to the string "Spool ". This can be followed by further line parsing to get the # to first learn to distinguish begin/end, then to best identify segments as the workload increases.

One difference in approach, is for any handling of characters on the line beginning with the seventh (7th) one.

There are several reasons to include char 6 in the parse above.  But mainly, it is due to the need to have something define the verb or noun used. Typically called a delimiter.

For programs needing to parse alternative nouns, verbs, delimiters, etc. fewer characters are read at a time until the token is properly defined.

For Working With Strings, this can be done easy enough with the midString:

NextChar = Mid$(LineToParse, Position, NumberOfCharactersToGet)

The last parameter is usually =1 except for cases which you can control and want to improve on.  For example, if you know that all of your identifiers are 5 or more characters (ie, as long or longer than 'Spool') you can run a programming cheat by gathering in 5 characters on the first parse of the line, then gather characters one at a time for the rest of the line.  Unless you have inside knowledge of other fixed format option for the file you are reading (which could lead to a conversion of the char representing numbers at the end to integer format, if there is a need for that).
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2558991
vbmaster: Your code works, but with your example, I need 2 files. I need something to replace the lines in a single file.

PBuck: Your code seems to only find the first match and not the second 2. I tried to play around with it but I couldn't get it to work. First time using RTB.

SunBow: That sounds lik exactly what I need. In some cases the spools will be grouped together like this "Spools 1,2,3). So it would be great is I could continue 1 character at a time looking for what I need. Problem is, I'm new at this and I have no idea how to parse anything.

Ok, another way, go here to see an example of the document http://home.neo.rr.com/randyb30
How about searching for Spool 1, reading all the text until the first blank line, the replacing it with something else?
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2559052
Of course DestFilename is only a temporary file, and when you're done you just simply use the Kill statement on the old file and then the Name statement to rename the DestFilename to SourceFilename. That is something like

  Kill SourceFilename
  Name DestFilename As SourceFilename

The Name statement will simply move the file if on the same harddrive so you have two choices, you can set DestFilename = SourceFilename & ".bak" for fast renaming OR you could create a temporary file in the Temp directory as the DestFilename (if you want a function to get a temporary filename I'll post it).

Voila. You have code to do the replacement however big the file is.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2559240
Sorry, I suddenly do not know what you want to do between the identifiers. It looks like All IDs begin "Spool " so you may not want anything to do with character input. Especially if the # only runs from 1-4 (ie, <10, only one digit, and you have personal control over which letter goes into which column.

For testing the begin/end, it looks like the 'If (sRow = "Spool 1") Then
' method may be more appropriate for you (and quicker to develop). But LeftString can also cull out the first seven chars of your ID line (ex: sRow), allowing anything else (ie trash) on that separator line to be ignored.

I assume you need two files, the old and new.  Best to hide the application from use during update. To do this with one file on top of itself, random access is better.  For sequential, which this should be, a file can in a sense be rewritten in place, but I think it still requires an internal temp file, even if all read into ram.

A cheat may be available, depending on need.  If you want to say, replace the text for spool 1 with the text for spool 2, ignore the lines assoc. w/spool 1, then move the Spool 2 ID just in front of Spool 3.  The cheats only apply to those with inside knowledge on what all this thing will do.

If you want to do 1 char at a time, you create a kind of a loop from 1 to end-of line.  Make routine GetChar(). I usually refer to the index as 'position', but some call it 'cursor'. Whatever helps.  The routine first checks for begin/end of line. There are many ways to move the character, but I think you'd best start width midString as above, since I think you'll understand it better and do not need alternatives yet.

But I suspect you are better off ignoring such parsing, as being an overkill. Unless you want to progress on analyzing the text between your Spool IDs. If you can control columns, and sequence of the spool IDs,

Origin input, destination output

for each line in source
read line and write line until Spool 1 is found (write it too)
now write "No facts available" (and ignore every other line until the next ID)

Read next line(s) but do not write until you find Spool 2

For each remaining line in source -
Then read & write everything else until eof on the original file.

I hope this is not too confusing, I need to get some food.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2559389
Sunbow: And if it sounded too confusing he can have a look at the code in the first comment, that shows exactly what you described. ;)
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2559880
Vbmaster,
Except for my prior confusion on goal, and my attempts to address cheating, parsing, and tokens; and some measure of hesitance on your code by RandyB30, I cannot disagree with you.

Although I'd personally like to try the likes of code from PBuck and paulstamp, my experience would have had me use an approach like yours. But you did so first.  It may need a minor adjustment, but I tried to clarify the questions I have with more regular words on YOUR approach as well, that's why I (clearly?) copied some of your code as reference for the test on "Spool 1" as opposed to "Spool" which would be a common path for someone wanting tokens.  Having seen the URL, it appears that RandyB30 may have some in-between needs for approaches above.

If it is not clear yet, IMHO, an approach for 'If (sRow = "Spool 1") Then ' etc. s/b attributed to your answer.

My answering will have to take path of parsing, since that remains a question.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2559886
If we can leave the backup pieces and any real-time management to a separate issue, I'd suggest taking the original file and making a copy of it to use as input. This preserves your original. Then run your program. If you like result, then copy it over to production area your own way.  With that much 'assumed', I'll do an example that uses midstring function to show you more on how it can be used to parse. There are other ways. Below is a paste of sample input, some code to follow (Input File: \Flow Capacity.In):
---------------------------------------

4. Flow Capacity Tests:

This series of tests is to be conducted with an available flow of 40 GPM and a differential pressure drop across the valve inlet port to pilot port of 250 - 300 PSID. The cylinder ports are to be connected as designated to a hydraulic load circuit, which includes a relief valve and a flow meter.

4.1 (Spool 1 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. Cylinder port flow must be 21.0 to 27.0 GPM or the valve is rejected. Repeat test for "A" power position.

4.2 (Spool 2 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. A minimum of 35 GPM cylinder port flow must be obtained. Repeat test for "A" power position.

4.3 (Spool 3 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. A minimum of 33 GPM cylinder port flow must be obtained. Repeat test for "A" power position. A minimum of 35 GPM cylinder port flow must be obtained.

4.4 (Spools 3 & 4 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. Cylinder port flow must be 22.5 to 32.0 GPM or the valve is rejected. Repeat test for "A" power position. A minimum of 35 GPM cylinder port flow must be obtained.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2559890
Global InChar As String         'one char misc temp
Global InputFile As Integer     'handle
Global InputLine As String      'one line of input
Global OutputLine As String     'one line of output
Global OutputFile As Integer    'handle
Global Spool1HasNotBeenFound As Boolean
Global Spool2HasBeenFound As Boolean
Global Position As Integer      'Pointer into lineInput
Global Token As String          'Used here only to indicate the SpoolID

Sub Main()
Dim InputFileName As String
Dim OutputFileName As String
Spool1HasNotBeenFound = True
Spool2HasBeenFound = False
InputFileName = "\Flow Capacity.In"
OutputFileName = "\Flow Capacity.Out"
InputFile = FreeFile
Open InputFileName For Input As #InputFile
OutputFile = FreeFile
Open OutputFileName For Output As #OutputFile

Do Until EOF(InputFile)
    GetAnotherLine
    If Spool2HasBeenFound Then      'Wrap it all up
        OutputLine = InputLine
        PutAnotherLine
    Else
    CheckForSpool
        If Spool1HasNotBeenFound Then
            OutputLine = InputLine
            PutAnotherLine
        End If
    End If
           
Loop

Close InputFile
Close OutputFile
End Sub
Sub CheckForSpool()                  'Only checking for 1-2
Position = 1
Do Until Len(InputLine) < Position + 5 + 1 'while room is left for tokens
Token = Mid$(InputLine, Position, 5)
If Token = "Spool" Then
InChar = Mid$(InputLine, Position + 6, 1)
    If InChar = "1" Then
        Spool1HasNotBeenFound = False
        OutputLine = InputLine
        PutAnotherLine
        OutputLine = ""
        PutAnotherLine
        OutputLine = "No facts available"
        PutAnotherLine
        OutputLine = ""
        PutAnotherLine
        Exit Do
    End If
    If InChar = "2" Then
        Spool2HasBeenFound = True
        OutputLine = InputLine
        PutAnotherLine
        Exit Do
    End If
End If
Position = Position + 1
Loop
End Sub
Sub GetAnotherLine()
      Line Input #InputFile, InputLine
End Sub
Sub PutAnotherLine()
      Print #OutputFile, OutputLine
End Sub
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2559894
The above code running under VB5 produced the following output (\Flow Capacity.Out):
----------------------------------------

4. Flow Capacity Tests:

This series of tests is to be conducted with an available flow of 40 GPM and a differential pressure drop across the valve inlet port to pilot port of 250 - 300 PSID. The cylinder ports are to be connected as designated to a hydraulic load circuit, which includes a relief valve and a flow meter.

4.1 (Spool 1 only)

No facts available

4.2 (Spool 2 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. A minimum of 35 GPM cylinder port flow must be obtained. Repeat test for "A" power position.

4.3 (Spool 3 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. A minimum of 33 GPM cylinder port flow must be obtained. Repeat test for "A" power position. A minimum of 35 GPM cylinder port flow must be obtained.

4.4 (Spools 3 & 4 only)

Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. Cylinder port flow must be 22.5 to 32.0 GPM or the valve is rejected. Repeat test for "A" power position. A minimum of 35 GPM cylinder port flow must be obtained.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2559950
Comment on my last approach:
1) It does find a wide variety of 'Spool' numbered types.
2) It allowed the phrase to be seemingly anywhere on the line
3) It allowed for language that includes the same word (Spool) in the body. Although this might be a nice thing, it is usually frowned upon. We tend to like to 'reserve' words in such cases.  If control is exercised on the numbering, and perhaps use of Caps can help clarify the ID from the body parts, you can get away with it (cheat) if you can maintain tight control over content.
4) With time, a cleaner method would wrap the SpoolID, usually with square brackets as in paulstamp example.  Your file/your style: you can move on from above example to using the L/R parentheses to designate your target. First the left one alone gives you positioning before testing for the SpoolID (token). Later on, if you have numerous ID types and lengths, it is a good idea to also use the right paren to identify length of token prior to completion of parsing. In such cases, it is often better, easier to implement, if you call this [] or () as one of your delimiters that can not be allowed in the body, between tour IDs (Spool #).
5) adjustments must be made for any other SpoolID handling, as well as for 10 or more of these.
6) the IF statements are mostly cheats based on foreknowledge that there was little work to do and foreknowledge of what the input looks like, no variety to handle.

With time the code could be revised to better elegance.  The intent was to quickly demonstrate "Working with strings" with a working example using some strings/lines in the files used that may be more familiar to you. Getting a single token type by:

Token = Mid$(InputLine, Position, 5)

Change the 5 to a 1 to get a single character at a time.

If your file is longer, but the line lengths are shorter, you may prefer to use Left$ to check the token piece, while shifting the input line to the left, or, in other words, truncate a char from left, test token, repeat, to move through the line.  In such a case, you would not need to hold your place/position in the string.

You could also shift characters one at a time into a teststring to compare on your tokens.  If they multipy like rabbits, you may also want to utilize the Case stmt to improve clarity.
0
IT, Stop Being Called Into Every Meeting

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!

 
LVL 24

Expert Comment

by:SunBow
ID: 2560009
>>How about searching for Spool 1, reading all the text until the first blank line, the replacing it with something else?

I hope you do not still want this.  It is tricky implement. Mainly, you normally cannot see with eyes what is there clearly. Is line empty, null, not, void, spaced, tabbed, or special non-printing characters?

You could rule that one by using len() command for an example (if you get to be the one making the rules).  When I clipped your webpage example, I did not 'see' some trailing spaces, for example. For my sample it impacted the verification of allowing the token to be at the right-most edge, or end-of-line. There, the space(s) count.  I guess another meaning here, is in for the planning of the rules for the file you manage. Perhaps allowing your code to trim whitespace from the right would be a good file maintenance technique for you.

OK: 'an' answer:  Trim whitespace off the right of the input line, then test the line length. If it is zer0 then you replace it and go to a wind-up/wrap up routine for the remainder.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2560024
If I take the text the original question above as input, and run same program above, it shows a need for tuning (improvement). If I Change the the 2nd ID so that it begins with a CAP it (program) looks (behaves) better, as shown in output below (after ====). Including an increase in ID appearance in the body, including case/number combo.  Still, Beware of Case utilization in your design/implementation. Output:

=======================================

Ok, who know's the answer to this one?
I have a file: file.txt, somewhere in this file is the following:
--------------------------------------

Spool 1

No facts available

Spool 2
more facts go here

Spool 3
last of facts go here

--------------------------------------
What I need to do is search through the file until I find spool 1, then replace anything that may be between Spool 1 and Spool 2. So, "Facts go here" would be replacd with "No facts available"
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2562227
Hey SunBow, how about the InStr and Replace functions? I found this in one of my books.

Dim search As String
Dim InputFile As Integer
Dim OutputFile As Integer
Dim InputLine As String

search = "Spool 1"

InputFile = FreeFile
Open "\stuff.doc" For Input As #InputFile
OutputFile = FreeFile
Open "\stuff2.doc" For Output As #OutputFile
Do Until EOF(InputFile)
Line Input #InputFile, InputLine

If InStr(InputLine, search) = 0 Then
    Print #OutputFile, InputLine
Else
    Print #OutputFile, InputLine
    Line Input #InputFile, InputLine
    InputLine = Replace(InputLine, InputLine, RTExtBox.Text)
        If InputLine <> "" Then
            Print #OutputFile, InputLine
            Line Input #InputFile, InputLine
        Else
        End If
End If

Loop
Close #InputFile
Close #OutputFile

End Sub

I would like to know ho to create the temp file though. And also would this work for a Word 97 file? Thanks.



0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2562469
Here's a function that will return the filename of a new temporary file...

  Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

  Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long

  Function TempDir() As String
   
    Dim tmpDir As String
   
    tmpDir = Space$(500)
    TempDir = sAddDirSep(left$(tmpDir, GetTempPath(Len(tmpDir), tmpDir)))
 
  End Function

  Function TempFile(sPrefix As String) As String

    '--------------------------------------------------------
    ' This procedure will return a random tempory file name
    ' for use in the TEMP directory. sPrefix is the
    ' characters you would like put on the front of the
    ' name. > ~DPM1901.TMP
    '--------------------------------------------------------

    Dim sTempFileName As String
 
    sTempFileName = Space$(500)
    Call GetTempFileName(TempDir, sPrefix, 0, sTempFileName)
    TempFile = Left$(sTempFileName, InStr(sTempFileName, Chr$(0)) - 1)

  End Function


You use it with code like this...

  Dim TempFilename As String

  'Create a new temporary file, the name will start with "~MY"
  TempFilename = TempFile("~MY")

  'Do something here with the temporary file

  'Remove the temporary file
  Kill TempFilename


The last line is very important because the TempFile function will create a temporary file so if you do not remove it you will soon have a lot of files inside your temporary directory. ;)
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2565706
InStr is not tool for parsing in my extended approaches. It is a good quick and dirty  parsing technique, but is less flexible and slower. You may prefer it since it can be more clear in and of itself for simple parsing needs. It does remind me tho', if the input file gets any added complexity, it is usually a good idea to move on to binary for I/O for some side bennies.

(1) it needs a lot of decision handling on its own, treats zero length strings different from null, but can return the position of the string - in a sense doing the search loop for the appropriate line content in one comand.
 
(2) it only allows you to search for one token at a time, in this case you've shown, "Spool 1".  What about the others? For your specific controlled example, the only other thing you need to search on is "Spool 2". And it is said to follow the former. So it would likely work for that specific example, as extension of the approach of the first comment. Where the 1st comment needs the SpoolID the only content of the line, the InStr will allow it anywhere. This, of course, may also work for a 'body' of "What I need to do is search through the file until I find spool 1, then replace anything that may be between Spool 1 and Spool 2." but of course you can see the ramifications there, where the line should have three search hits, requiring more programming workarounds and attention to design/enforcement of a set of rules for the content of the file you are examining.

(3) the parsing approach is different, giving flexibility for multiple 'trigger effects' like tokens. You find your ID, take appropriate action, and continue parsing the same line.  For simple short definitions of these, see the 'case statement'. It is very appropriate to the parsing approach for a small set of items to parse, like '(Spool #)' where # runs from 1-9, and you leave room for a case of 'other'.

(4) If parsing is used, it gets easier to also parse the body (the part between your SpoolID's). You may have algorithm that has to always leave one line of content intact, like "Actuate the spool to the "B" power position, with the load relief set at 2500 PSI. " or "Repeat test for "A" power position. " - as something in common with all; while other lines of body, like "A minimum of 35 GPM " may always need replacement of some nature.

(5) Of course, the replace statement can accomodate you example as given, but breaks down on less-than-proper file content and is cumbersome for handing the longer length strings in the examples I've used.

(6) How you move from searching to replacing is involved. Whether you want to allow 'body' prior to any SpoolID, take action on multiple SpoolIDs in same process, etc.  

(7) I am not sure (familiar) of specific use of your:
"InputLine = Replace(InputLine, InputLine, RTExtBox.Text)"
It looks like you are searching the input for itself, and if it is itself it gets a new value, ie same as saying:
"InputLine = RTExtBox.Text)"
My VB5 does not know this Replace command, but I see that VB6 does include it. Not downward compatible.

(8) For your cases:

> In some cases the spools will be grouped together like this "Spools 1,2,3).
> (Spools 3 & 4 only)

It is (very) more cumbersome to use string search for the different Spool/Spools spelling, and the format of the number(s) that follow.  For these cases, parsing for tokens and delimiters can be more appropriate, flexible, and cheaper (runtime). Where parsing with InStr will process the entire line over and over again, parsing for tokens won't. As soon as 'Spool' is found, you check for the plural, the space, the delimiter, end-of-line, etc. Although InStr is ineffiecient, IMHO, it has side benefit of always showing you the exact text you are looking for, if you write it that way.
0
 
LVL 24

Accepted Solution

by:
SunBow earned 100 total points
ID: 2565734
goshikins, I found a copy of VB6 and with a quick run of your search/find/replace code ... with just a minor change of wrapping "RTExtBox.Text" in double quotes, and it looks to to what is intended. OutputFile:

=======================================

Ok, who know's the answer to this one?
I have a file: file.txt, somewhere in this file is the following:
--------------------------------------

Spool 1
RTExtBox.Text
Spool 2
more facts go here

Spool 3
last of facts go here

--------------------------------------
What I need to do is search through the file until I find spool 1, then replace anything that may be between Spool 1 and Spool 2. So, "Facts go here" would be replacd with "No facts available"
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2565814
>> I would like to know ho to create the temp file though. And also would this work for a Word 97 file? Thanks.

1) For temp file for process above, "Stuff.tmp" is more appropriate. You can put it where you want. You can delete it programmatically quite easily. But mostly, you get option to keep it around while you are debugging.

2) Parsers like above work bet on text. Text is really easy to edit a variety of ways.  It can even be edited in Word.any, and 'saved as' a text file.

3) Word97 has a satisfactory tool itself to do a search/replace operation, independent of other tools. It will even strip out the blank lines for you.
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2565927
SunBow. You really have me lost on some of your techniques there. I just do this as a hobby right now. I started back to college for programming, but i haven't got to those classes yet. I want to thank everybody for their help. I have to give points to SunBow though just for the amount of time he's spent trying to help. Even though I think what I have wrote will work, I'd still liketo understand your code so I'm giving my e-mail address so we can speed things up. Again, thanks to everybody.
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2565934
When this guys helps, he really helps!! Even though I didn't understand most of it. :) Thanks SunBow.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2566299
Thanx,
I'll pass on a cut from something I did awhile back and am about to import/rework.  The basic idea/goal, was to place all the stuff I am working on in the same place I launched program from. This is a piece of it. Provided as another example of practical application for using inStr .
=======================================
Global CurrentDrive As String   'the root of the Drive mapping from which the .exe was run

Public Sub GetCurrentDrive()
 Dim workString As String
 Dim SlashPos As Integer

    CurrentDrive = ""
    workString = App.Path                                           'Begin with full path of the .exe
    SlashPos = InStr(3, workString, "\", vbTextCompare)             '3rd col. includes "\\" and "c:" etc.
    CurrentDrive = CurrentDrive & Left(workString, SlashPos)
'    GiveUp
End Sub
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2567559
By the way, forgot my E-Mail address.
mbristow@neo.rr.com
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2567607
By the way, forgot my E-Mail address.
mbristow@neo.rr.com
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2574143
Sorry, I do not have that kind of eMail service available at the moment. Awaiting some new services in neighborhood, like RR (any day?).

btw: my prior VB working files self destructed on reboot. I am trying to move on to VB 6, and it just plain locks up on the prior saved work.  Think backup, but I do not know what broke it on LeapDay.  

I went to M$ to get some patches. Their documents are inconsistent on size, but the service pack for Visual Studio is well over 100 MB. FYI.  They recommend you $pend for their CD version of the SP, but apparently, they forgot to include some of the file(s) required in the distribution, so we still need to download for it all. I prefer CDs, but did not want to order and wait for shipping.  I thought you had VB6 due to a reference above.
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2575260
yes I have VB6 and have downloaded the visual studio service pack. It goes pretty fast with the RR. Maybe 10 mins.
By the way, it shows my question as only 10 pts. I had it set for 100pts. Did it give you 100 or 10 pts? Thanks Again.

:Randy
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2576772
I assume the former, that it means any newbie who wants either the 'answer' or to add comment gets to contribute 10 for their share of it. (here, newbie is one who has yet to make a comment in this thread).

If you downloaded entire sp3 (>100 Mb) under 10 m, good news.  I read that in SanDiego they ran at 300 kb their first year, but after 3 years it got as low as 5, with more subscriptions and no backbone upgrades. Many reports on them not providing any real customer support. But I am on their notify list when they get it in.
0
 
LVL 1

Author Comment

by:RandyB30
ID: 2576987
Well, I think it took alittle longer than 10 mins. i don't know what I was thinking. Anyway, referring back to the question I asked here. I now have a working program (for demonstration purposes only), now what would i have to do to make it read a MS Word 97 .doc file (formatted text)? I'll post more points if you want me to.
0
 
LVL 24

Expert Comment

by:SunBow
ID: 2673970
I think best as a different question with clear purpose. Define what you have, and what you want to do.

Will someone use word to view it, while something else handles changes?

Will Word have 'option' to trigger a change effet?

Define formatted.  Word can display text, pretty much as-is, and even a single font is no longer so ugly.

Will there be things that are linked? Pictures/icons?

Macros?  Word in and of its own has good search/replacement.

Interest in Word only display of content, then could keep content as text, but perhaps import, link, picture, embed it. Perhaps not too dynamically, perhaps you would prefer it 'on demand'.
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…

759 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

19 Experts available now in Live!

Get 1:1 Help Now