Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › vbscript question - reorganizing data in text file
New Posts  All Forums:Forum Nav:

vbscript question - reorganizing data in text file

post #1 of 3
Thread Starter 
First of all I am not a programmer and It has been years since I've taken a class so please be gentle with me.

I have a application which creates a dpi file (just a text file with file names) which is used to combine multiple pdf documents into one. The problem is during the creation of the dpi file it reads from the top down and so I need to reorganize the lines in the dpi file prior to creating the pdf doc. Now the program that creates the pdf doc by reading the dpi file has an option to run scripts prior to creating the final pdf, but I have no idea how to write that script.

so...

I need to write a vbscript that will rearrange the lines in that dpi file if a certain condition is met. For example I will always search the first line of the file for the word "CAT" if that condition is true I then need the script to move the lines in the file around so they are in a certain order (move line 7 to 1, 8 to 2, etc.) Of course if cat is not found I need it to continue on just as it would normally.

Think this is way too complicated to try and tacke, or do any of you have some old scripts lying around that might accomplish this?

Thanks!
The Litter Box
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8400 (804A077) EVGA 780i 8800GTS 512 (G92) 4GB (2x2) Gskill Pc2-8000 
Hard DriveOptical DriveOSMonitor
Seagate 160GBx2 Raid 0 DL DVD Vista Ultimate 64 LG 19" Flatron 
KeyboardPowerCaseMouse
G15 ANTEC NEOHE550W CoolerMaster CM690 MX518 
Mouse Pad
XTrac 
  hide details  
Reply
The Litter Box
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8400 (804A077) EVGA 780i 8800GTS 512 (G92) 4GB (2x2) Gskill Pc2-8000 
Hard DriveOptical DriveOSMonitor
Seagate 160GBx2 Raid 0 DL DVD Vista Ultimate 64 LG 19" Flatron 
KeyboardPowerCaseMouse
G15 ANTEC NEOHE550W CoolerMaster CM690 MX518 
Mouse Pad
XTrac 
  hide details  
Reply
post #2 of 3
I'm not too in tune with VB script, but I can tell you from my C# experience that what you're looking for is called a "bubble sort". It sorts the array (you'll have to create this array and insert each line of your file to an element in the array) and "bubbles up" the results until they're in order. Good luck!
R'lyeh
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 (4.03GHz) Gigabyte EP45-UD3P EVGA GTX285 4GB (2x2) Corsair Dominator (5-5-5-15, 2.1v) 
Hard DriveOptical DriveOSMonitor
300GB WD VelociRaptor, 320GB WD Caviar 7200 Lite-On 20X DVD+R Ubuntu 10.04 x64 / Vista Home Premium x64 Samsung 226BW 
KeyboardPowerCaseMouse
Generic P/S2 Corsair HX750W Lian-Li V2000 Logitech G3 
  hide details  
Reply
R'lyeh
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q9550 (4.03GHz) Gigabyte EP45-UD3P EVGA GTX285 4GB (2x2) Corsair Dominator (5-5-5-15, 2.1v) 
Hard DriveOptical DriveOSMonitor
300GB WD VelociRaptor, 320GB WD Caviar 7200 Lite-On 20X DVD+R Ubuntu 10.04 x64 / Vista Home Premium x64 Samsung 226BW 
KeyboardPowerCaseMouse
Generic P/S2 Corsair HX750W Lian-Li V2000 Logitech G3 
  hide details  
Reply
post #3 of 3
Liked afzsom said, you can use methods like "quick sort" or ""bubble sort" to sort it. They are foundation for all languages. What development platform (offica products or .net IDE etcs) do you execute the vbscript? There are many ways to do this, here is one to take advantage of "arraylist" object. Synatx may be different depending on the development tool

' Code here. Vars may be different

Dim myFilesList(x) ' use redim if you know the number of files.

'Assign file to array.
mtFilesList(0)="D120.dpi"
mtFilesList(1)="D12d.dpi"
mtFilesList(2)="D12f.dpi"
...

'Or if all files are in a directory, use dir to loop around to list all files

dim Strss
dim iNum
iNum=0
Strss=Dir("*.dbi")

Do while Strss <> ""
myFilesList(iNum)=Strss
Strs=Dir()
loop

dim cFileName
cFileName=0

Set NewFilesList = CreateObject("System.Collections.ArrayList" )
For cFileName = 0 To UBound(MyFilesList)
NewFilesList.Add MyFilesList(cFileName)
Next
NewFileList.Sort

' Code to do something on NewFilesList
''
' Once it completes, release resource
Set myFilesList = Nothing
Set NewFilesList = Nothing
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › vbscript question - reorganizing data in text file