LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-05-2006, 04:16 PM   #1
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Rep: Reputation: 31
vbs loop question


Here is my script I have written. There is a comment saying I need to skip one ou. I don't know how to skip one iteration in a for each loop. I usually do stuff in perl, and I would just do "Next" but in VB, it doesn't like that, as it is a key word for the script.

Code:
'Create Excel Sheet to write to
Set objExcel = WScript.CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.ActiveSheet.Name = "Bestway Users"
objExcel.ActiveSheet.Range("A1").Activate

'Set basedn to bestway users ou
Set objDSE = GetObject("LDAP://rootDSE")
strBaseDN = "ou=Users,ou=USF Bestway," & objDSE.Get("defaultNamingContext")

'Get all ou's under bestway
Set objTerminalContainer = GetObject("LDAP://" & strBaseDN)
objTerminalContainer.Filter=Array("OrganizationalUnit")
For Each objTerminal in objTerminalContainer
  strCurrentOU = objTerminal.Name & "," & strBaseDN
  Set objUserContainer = GetObject("LDAP://" & strCurrentOU)
  objUserContainer.Filter = Array("user")
  'Get each User in current bw ou
  For Each objUser in objUserContainer
    '
    'Need to Skip Archive OU
    'If objUserContainer.Name = "OU=Archive" Then
    '  Skip this iteration, what do I put here?
    'End IF
    strUserName = objUser.givenname & " " & objUser.sn 
    objUser.Get("lastLogonTimestamp")
    set objLogon = objUser.Get("lastLogonTimestamp")
    intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart 
    intLogonTime = intLogonTime / (60 * 10000000)
    intLogonTime = intLogonTime / 1440
    intLastLogonTime = intLogonTime + #1/1/1601#
    objExcel.ActiveCell.Value = objUserContainer.Name
    objExcel.ActiveCell.Offset(0,1).value = strUserName
    objExcel.ActiveCell.Offset(0,2).Value = intLastLogonTime
    objExcel.ActiveCell.Offset(1,0).Activate
  Next
Next
Fixed the code tag.

Thanks paul

Last edited by jonlake; 10-05-2006 at 06:03 PM.
 
Old 10-05-2006, 05:04 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Perhaps "Exit For"? (Don't have my windows box handy, sorry.)
 
Old 10-05-2006, 05:25 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I think you're asking if Visual Basic has an equivalent of a "continue" in for/each loops.

No, it doesn't. As 95se noted, it has an equivalent of "break" ("exit for"), but no equivalent for "continue".

It doesn't matter. Just use an "if/else" block:
Code:
For Each objTerminal in  objTerminalContainer
  strCurrentOU = objTerminal.Name & "," & strBaseDN
  Set objUserContainer = GetObject("LDAP://" & strCurrentOU)
  objUserContainer.Filter = Array("user")

  'Get each User in current bw ou
  For Each objUser in objUserContainer
    '
    'Need to Skip Archive OU
    If objUserContainer.Name <> "OU=Archive" Then
      strUserName = objUser.givenname & " " & objUser.sn
      objUser.Get("lastLogonTimestamp")
      set objLogon = objUser.Get("lastLogonTimestamp")
      intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
      intLogonTime = intLogonTime / (60 * 10000000)
      intLogonTime = intLogonTime / 1440
      intLastLogonTime = intLogonTime + #1/1/1601#
      objExcel.ActiveCell.Value = objUserContainer.Name
      objExcel.ActiveCell.Offset(0,1).value = strUserName
      objExcel.ActiveCell.Offset(0,2).Value = intLastLogonTime
      objExcel.ActiveCell.Offset(1,0).Activate
    End IF
  Next
Next
'Hope that helps .. PSM

PS:
You were missing the "[/code]" at the end of your code block. Otherwise, the formatting would have been OK.

Last edited by paulsm4; 10-05-2006 at 05:27 PM.
 
Old 10-05-2006, 06:32 PM   #4
jonlake
Member
 
Registered: Apr 2004
Distribution: Slackware 11.0, Gentoo
Posts: 252

Original Poster
Rep: Reputation: 31
Thank you. I was able to get done what I needed with your suggestion.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting .vbs script to perl ? huxflux Programming 30 03-04-2006 10:18 AM
Using VBS on Linux to get environment variables squinn Linux - General 1 11-22-2005 12:11 AM
bash script - for loop question rignes Programming 3 10-06-2004 12:16 AM
Blocking file ext (exe, vbs, bat, com..) with sendmail PcHammer Linux - Software 2 08-29-2002 07:44 AM
(How) Can I run vbs from linux through samba? Noerr Linux - Software 0 07-01-2002 06:07 PM


All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration