New Posts  All Forums:Forum Nav:

VB script question

post #1 of 7
Thread Starter 
In one of my classes I need to make a VB script that reads data from one text file and writes specific data to another text file. The data that is needing to be read is -
(First info is junk, second is last name, third is first name, then middle initial and last the grade)
grades.txt
Code:
ADDAELLIS2             Ellis       Angela    M             A                                                            
ADDAFORREST1           Forrest     Alexandra M             B                                                           
ADDAFOSTER1            Foster      Artina    R             F                                                           
ADDAFREDERICKS1        Fredericks  Amber                   F                                                           
ADDAGARGYA1            Gargya      Archana                 C                                                          
ADDAGARRETT2           Garrett     Alisa     A             D                                                          
ADDAGHAZNAVI1          Ghaznavi    Ahmed                   F                                                           
ADDAGUDGEL1            Gudgel      Ashley    M             A                                                           
ADDAHADLER1            Hadler      Alicia    R             F                                                           


From this code I need to write the First Name, Last Name, Middle Initial, Grade to a different text file. Also the only grades that are kept in that text file are grades with F, the rest are discarded.

Here is what I did tried but didn't work.
Code:
 Dim objShell, objFso, objFsoRead, strRead, aryFields, strConnection
 Dim strLname, strFname, strMname, strGrade
 Dim rst, cnn

 Set objShell = CreateObject("Wscript.Shell")
 Set objFso = CreateObject("Scripting.FileSystemObject")
 Set cnn = CreateObject("ADODB.Connection")
 Set rst = CreateObject("ADODB.Recordset")
 Set objFsoRead = objFso.OpenTextFile("C:\email\grades.txt",1)
 Set objFsoWrite = objFso.OpenTextFile("c:\email\failingstudents.txt",8,true)



  Do While objFsoRead.AtEndOfStream <> True
   strRead = objFsoRead.ReadLine
   
   strLname = mid(strRead,24,11)
   strFName = mid(strRead,36,9)
   strMName = mid(strRead,46,1)
   strGrade = mid(strRead,62,1)

   If strGrade = F then
strOut = trim(StrFname) & "," & strMName & "," & trim(strLname) & "," & strGrade
objfsoWrite.writeline(strOut)
   End if

  Loop

objFsoRead.close
objFsoWrite.close

Any help would be appreciated.
RoG
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 2700K @ 4.6GHz - 1.35v Asus Maximus IV Extreme-Z Sapphire 7970 (3GB) Corsair Dominator GT (8GB-1866@1.5v) 
Hard DriveHard DriveHard DriveHard Drive
Intel 520 180GB Crucial C300 256GB OCZ Vertex 4 128GB 2x Seagate Barricuda 2TB (Raid 1) 
Optical DriveCoolingOSMonitor
Asus 24x DVD/CD Burner Corsair H100 Windows 8 Professional 2 x Samsung 27" LED 2ms (S27B550V) 
KeyboardPowerCaseMouse
Razor Black Widow Ulimate Corsair HX1050 Cooler Master HAF-X (Red) Logitech G700 
Audio
Astro A40's 
  hide details  
Reply
RoG
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 2700K @ 4.6GHz - 1.35v Asus Maximus IV Extreme-Z Sapphire 7970 (3GB) Corsair Dominator GT (8GB-1866@1.5v) 
Hard DriveHard DriveHard DriveHard Drive
Intel 520 180GB Crucial C300 256GB OCZ Vertex 4 128GB 2x Seagate Barricuda 2TB (Raid 1) 
Optical DriveCoolingOSMonitor
Asus 24x DVD/CD Burner Corsair H100 Windows 8 Professional 2 x Samsung 27" LED 2ms (S27B550V) 
KeyboardPowerCaseMouse
Razor Black Widow Ulimate Corsair HX1050 Cooler Master HAF-X (Red) Logitech G700 
Audio
Astro A40's 
  hide details  
Reply
post #2 of 7
Just wondering.. why arent you just using php any mysql? it seems to be much more convenient
Folding Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 940 @ 3.4GHz MSI 785GM-E45 mATX Gigabyte GTX 465 800/1600/3600 OCZ 4GB DDR2 800MHz 
Hard DriveOSMonitorPower
WD Caviar Blue 640GB Windows Vista 64-Bit BenQ G2220HD 1920x1080 Corsair 650TX 
Case
Lian Li K62 Mid ATX Tower 
  hide details  
Reply
Folding Rig
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Phenom II 940 @ 3.4GHz MSI 785GM-E45 mATX Gigabyte GTX 465 800/1600/3600 OCZ 4GB DDR2 800MHz 
Hard DriveOSMonitorPower
WD Caviar Blue 640GB Windows Vista 64-Bit BenQ G2220HD 1920x1080 Corsair 650TX 
Case
Lian Li K62 Mid ATX Tower 
  hide details  
Reply
post #3 of 7
Quote:
Originally Posted by maxhudson;12071171 
Just wondering.. why arent you just using php any mysql? it seems to be much more convenient

Uh, what? Why would you suggest he use a server-sided web language to parse a text file?
Intellect v2
(9 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC... 
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5 
Mouse
MIONIX NAOS 7000 
  hide details  
Reply
Intellect v2
(9 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC... 
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5 
Mouse
MIONIX NAOS 7000 
  hide details  
Reply
post #4 of 7
Thread Starter 
I have no say over what the teacher gives me in class, that's why. lol
RoG
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 2700K @ 4.6GHz - 1.35v Asus Maximus IV Extreme-Z Sapphire 7970 (3GB) Corsair Dominator GT (8GB-1866@1.5v) 
Hard DriveHard DriveHard DriveHard Drive
Intel 520 180GB Crucial C300 256GB OCZ Vertex 4 128GB 2x Seagate Barricuda 2TB (Raid 1) 
Optical DriveCoolingOSMonitor
Asus 24x DVD/CD Burner Corsair H100 Windows 8 Professional 2 x Samsung 27" LED 2ms (S27B550V) 
KeyboardPowerCaseMouse
Razor Black Widow Ulimate Corsair HX1050 Cooler Master HAF-X (Red) Logitech G700 
Audio
Astro A40's 
  hide details  
Reply
RoG
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 2700K @ 4.6GHz - 1.35v Asus Maximus IV Extreme-Z Sapphire 7970 (3GB) Corsair Dominator GT (8GB-1866@1.5v) 
Hard DriveHard DriveHard DriveHard Drive
Intel 520 180GB Crucial C300 256GB OCZ Vertex 4 128GB 2x Seagate Barricuda 2TB (Raid 1) 
Optical DriveCoolingOSMonitor
Asus 24x DVD/CD Burner Corsair H100 Windows 8 Professional 2 x Samsung 27" LED 2ms (S27B550V) 
KeyboardPowerCaseMouse
Razor Black Widow Ulimate Corsair HX1050 Cooler Master HAF-X (Red) Logitech G700 
Audio
Astro A40's 
  hide details  
Reply
post #5 of 7
Isn't the grade at char 60 and not 62?
    
CPUMotherboardGraphicsRAM
I7 920 Gigabyte EX58 XFX Radeon 4870 X2 6GB Corsair 
Hard DriveOptical DriveOSMonitor
500GB Maxtor LG DVDRW Vista Ultimate x64 2 x Edge IO 22" 
KeyboardPowerMouseMouse Pad
Razer Arctosa XFX 800w BTC Cheetah Gaming Mouse None 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
I7 920 Gigabyte EX58 XFX Radeon 4870 X2 6GB Corsair 
Hard DriveOptical DriveOSMonitor
500GB Maxtor LG DVDRW Vista Ultimate x64 2 x Edge IO 22" 
KeyboardPowerMouseMouse Pad
Razer Arctosa XFX 800w BTC Cheetah Gaming Mouse None 
  hide details  
Reply
post #6 of 7
Not IDE here so explain what isn't working. Liked post above, grade starts at 60. Also, you don't have to create adodb objects for this. If it is a text file, you can use readline or writeline right after the "CreateObject("Scripting.FileSystemObject")".
post #7 of 7
Thread Starter 
Figured it out either way, thanks
RoG
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 2700K @ 4.6GHz - 1.35v Asus Maximus IV Extreme-Z Sapphire 7970 (3GB) Corsair Dominator GT (8GB-1866@1.5v) 
Hard DriveHard DriveHard DriveHard Drive
Intel 520 180GB Crucial C300 256GB OCZ Vertex 4 128GB 2x Seagate Barricuda 2TB (Raid 1) 
Optical DriveCoolingOSMonitor
Asus 24x DVD/CD Burner Corsair H100 Windows 8 Professional 2 x Samsung 27" LED 2ms (S27B550V) 
KeyboardPowerCaseMouse
Razor Black Widow Ulimate Corsair HX1050 Cooler Master HAF-X (Red) Logitech G700 
Audio
Astro A40's 
  hide details  
Reply
RoG
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 2700K @ 4.6GHz - 1.35v Asus Maximus IV Extreme-Z Sapphire 7970 (3GB) Corsair Dominator GT (8GB-1866@1.5v) 
Hard DriveHard DriveHard DriveHard Drive
Intel 520 180GB Crucial C300 256GB OCZ Vertex 4 128GB 2x Seagate Barricuda 2TB (Raid 1) 
Optical DriveCoolingOSMonitor
Asus 24x DVD/CD Burner Corsair H100 Windows 8 Professional 2 x Samsung 27" LED 2ms (S27B550V) 
KeyboardPowerCaseMouse
Razor Black Widow Ulimate Corsair HX1050 Cooler Master HAF-X (Red) Logitech G700 
Audio
Astro A40's 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming