5 Replies - 1183 Views - Last Post: 09 May 2018 - 09:48 PM Rate Topic: -----

#1 JavaThoughts   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 10-April 18

How to turn string characters into numbered list using FileSystemObjec

Posted 09 May 2018 - 08:20 AM

Greetings,

I am using VB6 and File System Object. Below is a text file I am working on.

Notch Side = 0
MapBody{
@...21.........
...1112........
...111111......
.112111111.....
..1111111......
....1111.......
}



I am trying to get this result below but in my code, once my number list reaches 15, it goes back to 1. How do I make it continue on to 16 and so on?

The result that I want :
1 = @
2 = .
3 = .
4 = .
5 = 2
6 = 1
7 = .
8 = .
9 = .
10 = .
11 = .
12 =.
13 = .
14 = .
15 = .
16 = .
17 = .


I keep getting 1 after the number 15.
I kept getting this :

14 = .
15 = .
1 = .
2 = .


My code :

Dim ts As TextStream
Dim fso As FileSystemObject
Set fso = New FileSystemObject

Dim qInput As String
Dim traceInput As String

   qInput = ts.ReadLine
        If qInput = "MapBody{" Then
            Do While Not ts.AtEndOfStream
            Do
            qInput = ts.ReadLine

                        For i = 1 To Len(qInput)
                            traceInput = CStr(traceInput) & vbCrLf & i & " = " & Mid(qInput, i, 1)
                            
                        Next i
            Loop Until qInput = "}"
                
            Loop
        End If
    Loop

MsgBox traceInput





Please help...Thanks in advance...

Is This A Good Question/Topic? 0
  • +

Replies To: How to turn string characters into numbered list using FileSystemObjec

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14685
  • View blog
  • Posts: 58,688
  • Joined: 12-June 08

Re: How to turn string characters into numbered list using FileSystemObjec

Posted 09 May 2018 - 08:23 AM

Is the line of text 15 characters long, and you want a continuous count across all lines?
12            qInput = ts.ReadLine
13 
14                        For i = 1 To Len(qInput)


Was This Post Helpful? 0
  • +
  • -

#3 JavaThoughts   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 10-April 18

Re: How to turn string characters into numbered list using FileSystemObjec

Posted 09 May 2018 - 09:05 AM

View Postmodi123_1, on 09 May 2018 - 08:23 AM, said:

Is the line of text 15 characters long, and you want a continuous count across all lines?
12            qInput = ts.ReadLine
13 
14                        For i = 1 To Len(qInput)




Errr...sorry not sure about "Is the line of text 15 characters long" but I'm trying to give each character in the string a number. I want a continuous count across all characters. Something like this :

The text file :
Hello
Going

I'm trying to make it into like this:
1 = H
2 = e
3 = l
4 = l
5 = o
6 = G
7 = o
8 = i
9 = n
10 = g

But I keep getting this:
1 = H
2 = e
3 = l
4 = l
5 = o
1 = G
2 = o
3 = i
4 = n
5 = g
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14685
  • View blog
  • Posts: 58,688
  • Joined: 12-June 08

Re: How to turn string characters into numbered list using FileSystemObjec

Posted 09 May 2018 - 09:09 AM

Gotcha.. then think for abit about what happens when loops occur. Loop control variables are reset, things repeat, etc.

So if you are printing out characters in the for loop on line 14.. when it is done the parent 'do while' loop cycles around, right? That means a new start to the for loop and a new count for the loop control variable 'i'.

Perhaps have an independent variable to increment and print instead of 'i'? Something that is not affected by a "reset" of sorts with the while loop.
Was This Post Helpful? 1
  • +
  • -

#5 JavaThoughts   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 16
  • Joined: 10-April 18

Re: How to turn string characters into numbered list using FileSystemObjec

Posted 09 May 2018 - 09:43 PM

Thank you!! I get it now. The i keeps going back to one because of the new count so I can't get 16 after 15 but instead got 1. I really need to think more about what happens when a loop occurs.

"That means a new start to the for loop and a new count for the loop control variable 'i'.

Perhaps have an independent variable to increment and print instead of 'i'? Something that is not affected by a "reset" of sorts with the while loop."

I inserted a tCount inside it and that's it!

For i = 1 To Len(qInput)
tCount = tCount + 1
traceInput = CStr(traceInput) & vbCrLf & tCount & " = " & Mid(qInput, i, 1)
Next i


Once again, thank you.
Was This Post Helpful? 1
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14685
  • View blog
  • Posts: 58,688
  • Joined: 12-June 08

Re: How to turn string characters into numbered list using FileSystemObjec

Posted 09 May 2018 - 09:48 PM

glad to hear you got it. Sometimes it takes stepping back and seeing the larger flow.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1