help with vbscript code

Status
Not open for further replies.

office politics

It's all just 1s and 0s
Messages
6,555
Location
in the lab
i got this code to check if a user set only one of three values. With this code as is i get Line:18 Col:0 Expected 'End' Syntax Error:. I think its telling me to change my first else to a end if. when i change all my else's to end if's then i get the following error Line:18 Col:4 Expected 'Function' Syntax Error:.

Code:
i=0

if SEND_TO = NC then
i=i+1
end if

if UW_USERID = NC then
i=i+1
end if

if GOTO_AUTH = NC then
i=i+1
end if

if i = 0 then GETTRUEFALSE = FALSE
else
if i < 2 then GETTRUEFALSE = TRUE
else
if i = 3 then GETTRUEFALSE = FALSE
end if
 
I don't know vbscript but my guess would be that you need another End If at the end of your code, since you have one if/else statement nested within another one, but only one end if.
 
In that example there's only one if/elseif statement, but in your code you have nested statements. I indented the statements so you can see where you need the extra end if.
Code:
i=0

if SEND_TO = NC then
    i=i+1
end if

if UW_USERID = NC then
     i=i+1
end if

if GOTO_AUTH = NC then
     i=i+1
end if

if i = 0 then GETTRUEFALSE = FALSE
else
     if i < 2 then GETTRUEFALSE = TRUE
     else
          if i = 3 then GETTRUEFALSE = FALSE
     end if
[b]END IF[/b]
The end if in capitals is the one I added that you were missing.
 
Because it's wrong.

Wrong:

Code:
if i = 0 then 
 GETTRUEFALSE = FALSE
else
if i < 2 then GETTRUEFALSE = TRUE
else
if i = 3 then GETTRUEFALSE = FALSE
end if

Right (faster)

Code:
Select Case i
  Case 0: GetTrueFalse = False
  Case < 2: GetTrueFalse = True
  Case 3:  GetTrueFalse = False
End Select

Should work if you have i as in integer (Dim as integer) if you're using VB6 but if you're not youll need to convert it to an integer by doing:

int(i)

So change:
Code:
Select Case int(i)

Hope it helps ;)
 
Status
Not open for further replies.
Back
Top Bottom