#1
  1. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Sep 2006
    Location
    California
    Posts
    766
    Rep Power
    26

    Assigning a boolean of true or false to VBScript variable...


    Hi,

    Is there a way I can assign a value of true or false to a VBScript variable?

    I have a function where I want to initiate a value of false:

    Would this work?

    Code:
    'Determine if the employee is a manager
    Function IsManager(uniqueID)
    		Dim UID
    		UID = uniqueID
    		'Dim returnValue as boolean
    		Dim returrnValue
    		returnValue = False
    
    		'Execute Query and if Query returns non-empty recordset then set the value of returnValue to True
    		Dim rs3, sqlEmp
    		Set rs3 = Server.CreateObject("ADODB.Recordset")
    		sqlEmp = "SELECT OrgStructure.Manager FROM OrgStructure where OrgStructure.Manager = " & UID
    		rs3.open sqlEmp, Conn
    		If rs3.EOF Then
    		  returnValue = False
    		Else
    		  returnValue = True
    		End If
    		IsManager = returnValue
    
    		rs3.Close
    		Set rs3 = Nothing
    End Function
  2. #2
  3. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2004
    Location
    Netherlands
    Posts
    542
    Rep Power
    238
    Sure. No problem. Did your test show a strange result?
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Nov 2005
    Posts
    409
    Rep Power
    19
    tested and works...only problem i see off-hand is no protection for non numeric numbers feeding the function:

    Code:
    <%
      'Determine if the employee is a manager
    Function IsManager(uniqueID)
    		Dim UID
    		UID = uniqueID
    
                    If isNumeric(UID) Then
                     UID = CINT(UID)                
    		'Dim returnValue as boolean
    		Dim returrnValue
    		returnValue = False
    
    		'Execute Query and if Query returns non-empty recordset then set the value of returnValue to True
    		Dim rs3, sqlEmp
    		Set rs3 = Server.CreateObject("ADODB.Recordset")
    		sqlEmp = "SELECT OrgStructure.Manager FROM OrgStructure where OrgStructure.Manager = " & UID
    		rs3.open sqlEmp, Conn
    		If rs3.EOF Then
    		  returnValue = False
    		Else
    		  returnValue = True
    		End If
    		IsManager = returnValue
    
    		rs3.Close
    		Set rs3 = Nothing
                   End If
    End Function
    
      ' test function
      uniqueID = 23 ' hardcode 
      
       Select Case IsManager(uniqueID)
        Case true
         Response.Write "Is a manager"
        Case Else
         Response.Write "Is NOT a manager"
       End Select  %>
  6. #4
  7. No Profile Picture
    Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Sep 2006
    Location
    California
    Posts
    766
    Rep Power
    26
    I do not get any error pointing to this function...Just wanted to make sure.

    Thanks.

Similar Threads

  1. VBscript - AddDate Function using a variable
    By davidagnew in forum Visual Basic Programming
    Replies: 3
    Last Post: September 8th, 2003, 07:21 AM
  2. ASP - vbscript adddate function + variable
    By davidagnew in forum ASP Development
    Replies: 2
    Last Post: September 4th, 2003, 06:15 AM
  3. Accessing VBScript variable from Javascript
    By Steve Schofield in forum ASP Development
    Replies: 3
    Last Post: July 27th, 2001, 09:57 AM
  4. Replies: 3
    Last Post: October 14th, 2000, 12:50 AM
  5. Replies: 2
    Last Post: October 6th, 2000, 01:40 PM

IMN logo majestic logo threadwatch logo seochat tools logo