Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Going back to the start of a string


Hi, simple I'm sure but can't see the answer. Currently going through a
string "DO While Not ts_IN.AtEndOfStream" looking for information. This
includes then checking another string (while inside the first) for
matching reference point for further data.

So within the first loop, I have a second loop "Do While Not
ts_IN2.AtEndOfStream". And looping through that string searching for
the reference point.

This works initially, but after awhile don't find anything because it
is not going back to the start of ts_IN2 string each time loops on the
first section.


I can show some code if makes simpler, but basically how do I reset to
the start of the second string each time the first DO loops.

Thanks for any help
Neil


--
StackemEvs
------------------------------------------------------------------------
StackemEvs's Profile: 1402
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=175267

Microsoft Office Help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Going back to the start of a string

I don't use the FileSystemObject too much myself, so I can't answer the
question you asked, but I believe there is probably another way to do what
you want without using it. Can you describe what it is you are doing in a
little more detail and provide example text so we can use it to follow along
with your description?

--
Rick (MVP - Excel)


"StackemEvs" wrote in message
...

Hi, simple I'm sure but can't see the answer. Currently going through a
string "DO While Not ts_IN.AtEndOfStream" looking for information. This
includes then checking another string (while inside the first) for
matching reference point for further data.

So within the first loop, I have a second loop "Do While Not
ts_IN2.AtEndOfStream". And looping through that string searching for
the reference point.

This works initially, but after awhile don't find anything because it
is not going back to the start of ts_IN2 string each time loops on the
first section.


I can show some code if makes simpler, but basically how do I reset to
the start of the second string each time the first DO loops.

Thanks for any help
Neil


--
StackemEvs
------------------------------------------------------------------------
StackemEvs's Profile: 1402
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=175267

Microsoft Office Help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Going back to the start of a string

Post your code and explain precisely what you are wanting to have it do so we
can help.
--
Cheers,
Ryan


"StackemEvs" wrote:


Hi, simple I'm sure but can't see the answer. Currently going through a
string "DO While Not ts_IN.AtEndOfStream" looking for information. This
includes then checking another string (while inside the first) for
matching reference point for further data.

So within the first loop, I have a second loop "Do While Not
ts_IN2.AtEndOfStream". And looping through that string searching for
the reference point.

This works initially, but after awhile don't find anything because it
is not going back to the start of ts_IN2 string each time loops on the
first section.


I can show some code if makes simpler, but basically how do I reset to
the start of the second string each time the first DO loops.

Thanks for any help
Neil


--
StackemEvs
------------------------------------------------------------------------
StackemEvs's Profile: 1402
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=175267

Microsoft Office Help

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Going back to the start of a string


Sorry for not getting this back quicker, been away from my machine.
Trying to describe it better now.

I want to take information from two files and put them together,
outputting the data in one file. They have one common field by which to
correlate the data. All items in file one are numbers, File two has the
MainID code and a description which I want to add to the data in the
first file. The MainID is the only unique number, but is not always
sequential, and misses a lot of numbers (is this making sense?) .

I'm not sure how much of this code is actually relevant, or if what I
haven't put in is, so sorry if too much/too little.

'***General Descriptions etc

Const FSO_ForReading As Integer = 1
Const InputFile2 = TEMPDIR & "FileDesc.tmp"

Dim fso As Object
Dim ts_IN As Object
Dim ts_IN2 As Object
Dim sLine As String
Dim sLine2 As String
Dim lngFileOut As Long
Dim UsrDataRecord As DataRecord
Dim nRow As Long
Dim nRow2 As Long
Dim strcode As String
Dim strDesc As String

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts_IN = fso.OpenTextFile(InputFile, FSO_ForReading, True)
Set ts_IN2 = fso.OpenTextFile(InputFile2, FSO_ForReading, True)
lngFileOut = FreeFile
Open OutputFile For Append As lngFileOut

nRow = 0
Row2 = 0
strcode = ""
strDesc = ""


'***File One, so inputting most data in from this file***
'***Reading one line at a time

Do While Not ts_IN.AtEndOfStream
sLine = ts_IN.ReadLine

With UsrDataRecord
MainID = Left(sLine, 4) 'unique file for matching
item1 = Mid(sLine, 5, 8)
item2 = Mid(sLine, 13, 13)
item3 = Mid(sLine, 26, 7)
item4 = Mid(sLine, 33, 9)

'*** Now looking for description by matching .MainID
Do While .MainID = strcode
If .itemcode = strcode Then
Item5 = strDesc
Exit Do
ElseIf ts_IN2.AtEndOfStream Then
Exit Do
ElseIf .itemcode < strcode Then
Item5 = "Not recorded"
Exit Do
Else
'***So moving onto the next code and description
Do While Not ts_IN2.AtEndOfStream
sLine2 = ts_IN2.ReadLine
strcode = Left(sLine2, 4)
strDesc = Mid(sLine2, 5, 20)
nRow2 = nRow2 + 1
Exit Do
Loop
End If
Loop

WriteOutput UsrDataRecord, lngFileOut
End With
nRow = nRow + 1

Loop
closeAllFiles

This currently works as long as the next MainID in the second file is a
higher number than the previous one it looked for. If it is lower then
the previous description is being added, and continues to do so until a
higher mainID is used by file1.

I have tried various ways to return the second stream back to its
begining, so will check the lower numbers (they are sequential in it
[although some will be missing]).

Any help will be greatly appreciated, I'm ready to get the beers in,
I've spent a lot of time banging my head on the desk, going round in
circles.

If someone has a simple answer to this, and say what is so blatently
obvious (that I can't see it), then maybe I'll explain what I'm after as
a final program (it can wait for now).

All help and suggestions really are greatly appreciated.
Neil


--
StackemEvs
------------------------------------------------------------------------
StackemEvs's Profile: 1402
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=175267

Microsoft Office Help



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Going back to the start of a string

If desired, send your file to my address below. I will only look if:
1. You send a copy of this message on an inserted sheet
2. You give me the newsgroup and the subject line
3. You send a clear explanation of what you want
4. You send before/after examples and expected results.

Send both
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"StackemEvs" wrote in message
...

Sorry for not getting this back quicker, been away from my machine.
Trying to describe it better now.

I want to take information from two files and put them together,
outputting the data in one file. They have one common field by which to
correlate the data. All items in file one are numbers, File two has the
MainID code and a description which I want to add to the data in the
first file. The MainID is the only unique number, but is not always
sequential, and misses a lot of numbers (is this making sense?) .

I'm not sure how much of this code is actually relevant, or if what I
haven't put in is, so sorry if too much/too little.

'***General Descriptions etc

Const FSO_ForReading As Integer = 1
Const InputFile2 = TEMPDIR & "FileDesc.tmp"

Dim fso As Object
Dim ts_IN As Object
Dim ts_IN2 As Object
Dim sLine As String
Dim sLine2 As String
Dim lngFileOut As Long
Dim UsrDataRecord As DataRecord
Dim nRow As Long
Dim nRow2 As Long
Dim strcode As String
Dim strDesc As String

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts_IN = fso.OpenTextFile(InputFile, FSO_ForReading, True)
Set ts_IN2 = fso.OpenTextFile(InputFile2, FSO_ForReading, True)
lngFileOut = FreeFile
Open OutputFile For Append As lngFileOut

nRow = 0
Row2 = 0
strcode = ""
strDesc = ""


'***File One, so inputting most data in from this file***
'***Reading one line at a time

Do While Not ts_IN.AtEndOfStream
sLine = ts_IN.ReadLine

With UsrDataRecord
MainID = Left(sLine, 4) 'unique file for matching
item1 = Mid(sLine, 5, 8)
item2 = Mid(sLine, 13, 13)
item3 = Mid(sLine, 26, 7)
item4 = Mid(sLine, 33, 9)

'*** Now looking for description by matching .MainID
Do While .MainID = strcode
If .itemcode = strcode Then
Item5 = strDesc
Exit Do
ElseIf ts_IN2.AtEndOfStream Then
Exit Do
ElseIf .itemcode < strcode Then
Item5 = "Not recorded"
Exit Do
Else
'***So moving onto the next code and description
Do While Not ts_IN2.AtEndOfStream
sLine2 = ts_IN2.ReadLine
strcode = Left(sLine2, 4)
strDesc = Mid(sLine2, 5, 20)
nRow2 = nRow2 + 1
Exit Do
Loop
End If
Loop

WriteOutput UsrDataRecord, lngFileOut
End With
nRow = nRow + 1

Loop
closeAllFiles

This currently works as long as the next MainID in the second file is a
higher number than the previous one it looked for. If it is lower then
the previous description is being added, and continues to do so until a
higher mainID is used by file1.

I have tried various ways to return the second stream back to its
begining, so will check the lower numbers (they are sequential in it
[although some will be missing]).

Any help will be greatly appreciated, I'm ready to get the beers in,
I've spent a lot of time banging my head on the desk, going round in
circles.

If someone has a simple answer to this, and say what is so blatently
obvious (that I can't see it), then maybe I'll explain what I'm after as
a final program (it can wait for now).

All help and suggestions really are greatly appreciated.
Neil


--
StackemEvs
------------------------------------------------------------------------
StackemEvs's Profile: 1402
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=175267

Microsoft Office Help


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting text string back into a formula Kevin c Excel Discussion (Misc queries) 1 October 17th 06 09:52 PM
Trim special charcters from start of string John Michl Excel Programming 5 July 24th 06 10:40 PM
IF Cell Contents Start with STRING ConfusedNHouston Excel Worksheet Functions 2 April 17th 06 03:28 PM
check if the text string start with a specific character September21 New Users to Excel 5 September 22nd 05 03:07 PM
Scenariao needing help with. convert range to string and back, Kevin G[_2_] Excel Programming 0 January 28th 04 03:23 PM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"