Create a numbered list with VB6

I am a newbie using VB6 to try to create a basic text file program. Mostly in my work, I create a lot of text files with headers and then with variable data to save me manually by typing a document with each heading every time I created a VB6 program that automatically added headers, I would enter the data and it would be display all this as a text file. I have done most of this, but there is one part that I cannot do.

One part of a text file is a numbered list with a dot after it. EG:

TITLE
01. CHEESE
02. CHOCOLATE
03. BREAD

etc.

The list is different in each file and has a different length, so there can be 4 elements, maybe 20. At the moment I just got a plain text block, and I manaully enter the data every time, as indicated above, with numbers, I would like so that the number, point and space are automatically created in front of the list. So I could just enter a list like

CHEESE
CHOCOLATE
BREAD

and when I generate a text file, the list will be automatically numbered. Is this possible with VB6? I know this sounds like a small detail, but I create hundreds of these files, and the less effort I can do for each, the better.

Private Sub create_Click()
Dim fso
Dim file As String
file = "C:\Textfile.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
    fso.DeleteFile file, True
End If
Const ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("C:\Textfile.txt", ForAppending, True)
With filetxt
.writeline (txtArtist & vbNewLine)
.writeline ("SOURCE" & " (" & Combo1 & " #" & txtsource & ")" & ":")
.writeline (txtequip & vbNewLine)
.writeline (Combo2 & ":")
.writeline (txttransfer & vbNewLine)
.writeline ("GENERATION:")
.writeline (txtgen & vbNewLine)
.writeline ("LENGTH:")
.writeline (txtlength & vbNewLine)
.writeline ("NOTES:")
.writeline (txtnotes & vbNewLine)
.writeline ("TRACKS:")
.writeline (txttracks & vbNewLine)
.writeline ("MD5 FINGERPRINTS:")
.writeline (txtmd5 & vbNewLine)
.writeline ("TRANSFERRED BY:")
.writeline (txttransferby & vbNewLine)
.writeline ("**PLEASE DO NOT ENCODE TO LOSSY FORMATS OR SELL!**")
.Close
End With
Shell "notepad.exe C:\Textfile.txt", vbNormalFocus
End Sub
+3
source share
3 answers

You can:

Text1.Text = TextToNumberedList(Text1.Text)

Function TextToNumberedList(strData As String) As String
    Dim arr()  As String
    Dim i      As Long
    arr = Split(strData, vbCrLf)
    For i = 0 To UBound(arr)
        arr(i) = Format$(i + 1, "00") & ". " & arr(i)
    Next

    TextToNumberedList = Join(arr, vbCrLf)
End Function
+5
source

, , - ( )...

   'Split The Text
   Dim YourArray As String()
   YourArray = Split(Input, vbNewLine)

   Dim Counter As Long
   Dim OutputString As String
   For Counter = 0 To UBound(YourArray)
      OutputString = Counter & ". " & YourArray(Counter)
   Next

, , .

+2

Perhaps I misunderstood your question, but could you just split the contents of the text field into an array and iterate over it using the array index for numbering? The main example .

+1
source

All Articles