Jump to content
Sign in to follow this  

Need to exit a function (dont know where to put return)

Recommended Posts

For $i = 0 to UBound($data)-1
    $varaction = $data[$i][6]       
        Case $varaction = "new hire"
        Case $varaction = "termination"
            msgbox(0, '', "user is leaving")    
        Case Else
            ; error

Func _CreateNewUser()
; Check first to see if user already exists
$getattribute = _AD_GetObjectAttribute($username, "sAMAccountName")
$doesexist = _AD_ObjectExists($username, "sAMAccountName")
If $doesexist = 1 Then
ElseIf @error = 1 Then
    ; do nothing and continue)
    ; dont know what to do

; Create new user
Global $createnewuser = _AD_CreateUser($ou, $username, $firstname & " " & $lastname)
If $createnewuser = 1 Then
    ; success
ElseIf @error = 1 Then
    ; user already exists
ElseIf @error = 2 Then
    ; OU does not exist
ElseIf @error = 3 Then
    ; common name is missing
ElseIf @error = 4 Then
    ; username is missing
    ; dont know what to do
EndFunc ;==> _CreateNewUser()

I need to exit the function _CreateNewUser() if the user already exists, but continue is the user doesn't exist. the problem is that _CreateNewUser() is a function that is inside a loop at the top. that loop calls a series of functions. I don't want to exit the script completely because the loop still needs to run through the other users in my excel sheet. How would I exit the function and move onto other functions in the loop without exiting the script entirely?

I've searched and seen people use return. But everytime I try and mess around with I get a Scite error saying "Invalid keyword at the start of this line"

Edited by kor

Share this post

Link to post
Share on other sites

nm. :x

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...

Share this post

Link to post
Share on other sites

I figured it out. What I did was create a new function that tests the condition, then assigns a value to a var. Then in the case statement I have a If Then Else to either quit the loop or move on to the other functions. Works great. I'll post the code tomorrow for anyone that stumbles across this thread.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...