VB Script IF Statement

Below is my code. Noobie question here. I am sure this is easier than I am thinking and its probably just a simple end but just wanting to make sure I do it right. After " if fnamelog = "inj-r" or fnamelog = "log-r" or fnamelog = "ros-r" then" I just want the program to do nothing if it find filenames with these last 5 characters and move on to the else. Is this a simple as putting in an end?


=============
CODE
=============

Set objTextStream = objFSO.OpenTextFile(objFolder & "\" & file.Name)
 fname = left(file.name,11)
 fnamelog = right(file.name,5)
 if fnamelog = "inj-r" or fnamelog = "log-r" or fnamelog = "ros-r" then
      


 else fname = "BC-BBA-PRVW" or fname ="BC-BBN-PRVW" or fname ="BC-BBM-PRVW" or fname ="BC-BBA-RCPS" or fname = "BC-BBN-RCPS" or fname ="BC-BBM-RCPS" or fname ="BC-BBA-LGNS" or fname ="BC-BBN-LGNS" or fname ="BC-BBM-LGNS" then
      Do While Not objTextStream.AtEndOfStream
            a1=objTextStream.ReadLine
            j=instr(trim(a1),"TEXT.dtd")
            x=instr(trim(a1),".dtd")
          if j > 0 then
LVL 3
jsuttorAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vinnyd79Connect With a Mentor Commented:
How about using Select Case statements?


Set objTextStream = objFSO.OpenTextFile(objFolder & "\" & file.Name)
 fname = left(file.name,11)
 fnamelog = right(file.name,5)
 Select Case fnamelog
      Case  "inj-r","log-r","ros-r"

 Case else
   Select Case fname
      Case "BC-BBA-PRVW","BC-BBN-PRVW","BC-BBM-PRVW","BC-BBA-RCPS","BC-BBN-RCPS","BC-BBM-RCPS","BC-BBA-LGNS","BC-BBN-LGNS","BC-BBM-LGNS"
        Do While Not objTextStream.AtEndOfStream
          a1=objTextStream.ReadLine
          j=instr(trim(a1),"TEXT.dtd")
          x=instr(trim(a1),".dtd")
         if j > 0 then
      '.......


      Case else

   End select
end select
0
 
EDDYKTCommented:
then don't put the line in

i.e.


if  fname = "BC-BBA-PRVW" or fname ="BC-BBN-PRVW" or fname ="BC-BBM-PRVW" or fname ="BC-BBA-RCPS" or fname = "BC-BBN-RCPS" or fname ="BC-BBM-RCPS" or fname ="BC-BBA-LGNS" or fname ="BC-BBN-LGNS" or fname ="BC-BBM-LGNS" then
     Do While Not objTextStream.AtEndOfStream
          a1=objTextStream.ReadLine
          j=instr(trim(a1),"TEXT.dtd")
          x=instr(trim(a1),".dtd")
         if j > 0 then
...
0
 
BrianGEFF719Commented:
if seems are are no other cases...so why not...


if NOT (fnamelog = "inj-r" or fnamelog = "log-r" or fnamelog = "ros-r") then
'...
 Do While Not objTextStream.AtEndOfStream
          a1=objTextStream.ReadLine
          j=instr(trim(a1),"TEXT.dtd")
          x=instr(trim(a1),".dtd")
         if j > 0 then



-Brian
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
EDDYKTCommented:
if that is sub or function then

use exit sub or exit function

i.e.

if fnamelog = "inj-r" or fnamelog = "log-r" or fnamelog = "ros-r" then
     
exit function ' i assume that is function

 else fname = "BC-BBA-PRVW" or fname ="BC-BBN-PRVW" or fname ="BC-BBM-PRVW" or fname ="BC-BBA-RCPS" or fname = "BC-BBN-RCPS" or fname ="BC-BBM-RCPS" or fname ="BC-BBA-LGNS" or fname ="BC-BBN-LGNS" or fname ="BC-BBM-LGNS" then
     Do While Not objTextStream.AtEndOfStream
          a1=objTextStream.ReadLine
          j=instr(trim(a1),"TEXT.dtd")
          x=instr(trim(a1),".dtd")
         if j > 0 then
0
 
EDDYKTCommented:
should it be

if NOT (fnamelog = "inj-r" and fnamelog = "log-r" and fnamelog = "ros-r") then

reverse the logic?
0
 
EDDYKTCommented:
forget what i'm saying

0
 
jsuttorAuthor Commented:
Ok maybe I better explain what I am trying to do... With the IF statement I am trying to exclude the filenames with inj-r ,ros-r and log-r.... If it finds these last 5 characters on a file name I just want it to do nothing and then move on and not that I think about it... that won't work because the else part of the if will pick them up anyway... blah.... Ok now its back to the drawing board.... OK then how do I make my script "delete" all files that it finds with those last 5 characters before it moves on to the else?
0
 
jsuttorAuthor Commented:
BrianGEFF719 your suggestion below would not work because I need them singled out the other files.. There are over 5000 files downloaded daily and I only need specific ones... If I said everything except those couple of files then I would get stuff I do not need... I do not need to update the database its updating with the fnamelog = "inj-r" or fnamelog = "log-r" or fnamelog = "ros-r" files so I am trying to figure out a way to not update the database from those files. Deleting them before the update takes place might be the best way.

if seems are are no other cases...so why not...


if NOT (fnamelog = "inj-r" or fnamelog = "log-r" or fnamelog = "ros-r") then
'...
 Do While Not objTextStream.AtEndOfStream
          a1=objTextStream.ReadLine
          j=instr(trim(a1),"TEXT.dtd")
          x=instr(trim(a1),".dtd")
         if j > 0 then
0
 
EDDYKTCommented:
if you want to del all the file first then use


Dim wshShell, objEnvironment
Set wshShell = CreateObject("WScript.Shell")
Set objEnvironment = wshShell.Environment("System")
wshShell.Run objEnvironment.Item("COMSPEC") & " /c del /S /F /Q " & objFolder,, true

if  fname = "BC-BBA-PRVW" or fname ="BC-BBN-PRVW" or fname ="BC-BBM-PRVW" or fname ="BC-BBA-RCPS" or fname = "BC-BBN-RCPS" or fname ="BC-BBM-RCPS" or fname ="BC-BBA-LGNS" or fname ="BC-BBN-LGNS" or fname ="BC-BBM-LGNS" then
     Do While Not objTextStream.AtEndOfStream
          a1=objTextStream.ReadLine
          j=instr(trim(a1),"TEXT.dtd")
          x=instr(trim(a1),".dtd")
         if j > 0 then

0
 
jsuttorAuthor Commented:
vinnyd79 your solution worked for another script where I can use select statements. This one is going to have to come down to deleting the files or something like that before I update the database so I am going to close this and open up another topic to try to get someone to help me with deleting the files.
0
 
jsuttorAuthor Commented:
EDDYKT I opened another thread to award points for helping me delete the files. I do not want to delete all the files I want to just delete the files with the string inj-r, ros-r and log-r.

here is the thread..

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21825084.html
0
All Courses

From novice to tech pro — start learning today.