• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

Create an ordered list in Notepad

Hello,

This is my programming question and hence not sure which program to use to create this one..

I need to create the following in a notepad (txt) file


ip-200-100-50-100        A       200.100.50.100
|
|
|
ip-200-100-50-254        A       200.100.50.254


There is 8 spaces between "ip-200-100-50-100" and "A" and there are 7 spaces between "A" and "200.100.50.100".
what is the easiest way to do  this ?

TIA
SR
0
sunray_2003
Asked:
sunray_2003
  • 5
  • 4
1 Solution
 
sunray_2003Author Commented:
I can think a logic like this .

from 1 to 254
print("ip-200-100-50-i        A       200.100.50.i"
write to  test.txt  file
i = i + 1
next



   
0
 
vinnyd79Commented:
In vb you could do it like this:


Private Sub Command1_Click()
Dim i As Integer, ff As Integer
ff = FreeFile
Open "C:\MyTextFile.txt" For Output As #ff
For i = 1 To 254
    Print #ff, "ip-200-100-50-" & i & Space$(8) & "A" & Space$(7) & "200.100.50." & i
Next i
Close #ff

End Sub
0
 
sunray_2003Author Commented:
Thanks..

I saved it as  test.vbs file.  I have put this file in my desktop..
then i double-clicked on it and it says

line :2
Char: 7
error : Expected end of statement
code :800A0401
source : Microsoft VBscript compilation error..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
vinnyd79Commented:
In vbs try this:


Dim fso, MyFile,i
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
For i = 1 to 254
   MyFile.WriteLine("ip-200-100-50-" & i & Space(8) & "A" & Space(7) & "200.100.50." & i)
Next
MyFile.Close

Set MyFile = Nothing
Set fso = Nothing
0
 
sunray_2003Author Commented:
Wonderful... I love it.. I know this is a silly question .. what is the difference between VB and VBS..
Is VB = Visual Basic and VBS as Visual Basic Scripting ?
0
 
vinnyd79Commented:
Yes. VB needs Visual Basic Installed where VBS needs the windows scripting host.VBS is written is text files where VB needs to be run (or compiled) from Visual Basic.

If you wanted to adjust the columns so they line up for all the numbers you could check the length of i and adjust the spaces accordingly:


Dim fso, MyFile,i
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
For i = 1 to 254
   Select Case Len(i)
      Case 1
        MyFile.WriteLine("ip-200-100-50-" & i & Space(8) & "A" & Space(7) & "200.100.50." & i)
      Case 2
          MyFile.WriteLine("ip-200-100-50-" & i & Space(7) & "A" & Space(7) & "200.100.50." & i)
      Case 3
          MyFile.WriteLine("ip-200-100-50-" & i & Space(6) & "A" & Space(7) & "200.100.50." & i)
   End Select

Next
MyFile.Close

Set MyFile = Nothing
Set fso = Nothing
0
 
sunray_2003Author Commented:
This one works real good for me

****************
Dim fso, MyFile,i
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
For i = 1 to 254
   MyFile.WriteLine("ip-200-100-50-" & i & Space(8) & "A" & Space(7) & "200.100.50." & i)
Next
MyFile.Close

Set MyFile = Nothing
Set fso = Nothing
*****************

What if I need to put a TAB between "ip-200-100-50-"   and "A"  and also between  "A" and "200.100.50."
instead of a the 8 and 7 spaces ?
0
 
vinnyd79Commented:
Instead of the Spaces you can add vbTab

 MyFile.WriteLine("ip-200-100-50-" & i & vbTab & "A" & vbTab & "200.100.50." & i)

However,when the last segment goes into 2 digits or more it will push the rest of the data to the next Tab position. To fix that you can add a space before the first Tab:

MyFile.WriteLine("ip-200-100-50-" & i & " " & vbTab & "A" & vbTab & "200.100.50." & i)
0
 
sunray_2003Author Commented:
I will play around some more but I am in good shape now.. Thanks so much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now