Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 5th, 2004, 03:48 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default If A OR B OR C Then...

I wanted to know if anyone knows of any syntax that will allow me to do the following flow control...

If strVariable <> "value" Or <> "secondvalue" Or <> "etc" Then
   <Statement>
End If

I thought I had seen something like this before, but it doesn't seem to work.

Thanks,


mmcdonal
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com
Reply With Quote
  #2 (permalink)  
Old November 9th, 2004, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi mmcdonal,

You were missing the strVariable for each condition.
Code:
If strVariable <> "value" Or strVariable <> "secondvalue" Or strVariable <> "etc" Then
   <Statement>
End If
Else you can try using SELECT CASE. Check VBScript documention on that.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #3 (permalink)  
Old November 9th, 2004, 08:52 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Excellent, that was exactly what I needed! Thanks so much for the reply.

mmcdonal
Reply With Quote
  #4 (permalink)  
Old November 17th, 2004, 11:02 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Actually, that is not working in VBSCript. Here is a script you can run on your computer that will return all the usernames by showing all the folders immediately under Documents and Settings and the date the folder was created:

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder("C:\Documents and Settings\")
Sub ShowSubFolders(Folder)
    For Each SubFolder In Folder.SubFolders
        NewArray = Split(SubFolder.Path, "\")
        strLogin = NewArray(2)
        DateArray = Split(SubFolder.DateCreated, " ")
        strCreate = CDate(DateArray(0))
        WScript.Echo strLogin
        WScript.Echo strCreate
        End If
    Next
End Sub

   When I add the IF THEN statement on the WScript.Echo lines, this works and doesn't report the administrator folder...

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder("C:\Documents and Settings\")
Sub ShowSubFolders(Folder)
    For Each SubFolder In Folder.SubFolders
        NewArray = Split(SubFolder.Path, "\")
        strLogin = NewArray(2)
        DateArray = Split(SubFolder.DateCreated, " ")
        strCreate = CDate(DateArray(0))
        If strLogin <> "administrator" Then
        WScript.Echo strLogin
        WScript.Echo strCreate
        End If
    Next
End Sub

   ... but when I use the following code, it not only does NOT get rid of the administrator and All Users folders, it reports both of them, even though the administrator folder is not reported in the second instance of the script...

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder("C:\Documents and Settings\")
Sub ShowSubFolders(Folder)
    For Each SubFolder In Folder.SubFolders
        NewArray = Split(SubFolder.Path, "\")
        strLogin = NewArray(2)
        DateArray = Split(SubFolder.DateCreated, " ")
        strCreate = CDate(DateArray(0))
        If strLogin <> "administrator" Or strLogin <> "All Users" Then
        WScript.Echo strLogin
        WScript.Echo strCreate
        End If
    Next
End Sub

   I think this is a limitation of VBScript. This works in VB.NET, but it is not working here.

   Does anyone else have any suggestions?

Thanks,


mmcdonal
Reply With Quote
  #5 (permalink)  
Old November 22nd, 2004, 07:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
If strLogin <> "administrator" AND strLogin <> "All Users" Then
How about using this? It is as simple as ENGLISH, it should not be "Administrator" AND should not be "All Users". When you say it should not be "Administrator" OR should not be "All Users", doesn't that sound odd?

Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #6 (permalink)  
Old November 23rd, 2004, 08:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Thanks, that's just what I needed. So much for two semesters of sentential calculus =]



mmcdonal
Reply With Quote









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.