Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-21-2005, 09:44 AM   #1 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default help with vbscript code

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

office politics is offline  
Old 03-21-2005, 10:13 AM   #2 (permalink)
 
Monster Techie

Join Date: Jul 2003

Posts: 1,179

Emily is on a distinguished road

Send a message via AIM to Emily
Default

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.
__________________
<a href=\"http://www.upstark.com\">www.upstark.com</a>
Emily is offline  
Old 03-21-2005, 10:33 AM   #3 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default

i modeled after an example at http://www.w3schools.com/vbscript/tr...=vbdemo_elseif

Code:
function greeting()
i=hour(time)
If i = 10 then
	document.write("Just started...!")
elseif i = 11 then
	document.write("Hungry!")
elseif i = 12 then
	document.write("Ah, lunch-time!")
elseif i = 16 then
	document.write("Time to go home!")
else
	document.write("Unknown")
end if
end function

office politics is offline  
Old 03-21-2005, 10:49 PM   #4 (permalink)
 
Monster Techie

Join Date: Jul 2003

Posts: 1,179

Emily is on a distinguished road

Send a message via AIM to Emily
Default Re: help with vbscript code

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
END IF 
The end if in capitals is the one I added that you were missing.
__________________
<a href=\"http://www.upstark.com\">www.upstark.com</a>
Emily is offline  
Old 03-22-2005, 10:02 AM   #5 (permalink)
 
Super Techie

Join Date: Aug 2003

Posts: 348

mack is on a distinguished road

Default

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
__________________

Windows 7 Professional
AMD x2 4400+
ASUS A8N-32 SE Deluxe
FSP Group 500 watt PSU
4GB PC3200 Dual-Channel
EVGA 8800 GT
150GB Raptor 10K HDD
250GB Western Digital HDD
Jobs
Electrician
C# Programmer+Web Programmer
Gamer
mack is offline  
Old 03-22-2005, 10:04 AM   #6 (permalink)
 
Super Techie

Join Date: Aug 2003

Posts: 348

mack is on a distinguished road

Default

If you want to see some good examples of the use of Visual Basic, visit http://sidrahq.com and click "Downloads" and download the source code.
__________________

Windows 7 Professional
AMD x2 4400+
ASUS A8N-32 SE Deluxe
FSP Group 500 watt PSU
4GB PC3200 Dual-Channel
EVGA 8800 GT
150GB Raptor 10K HDD
250GB Western Digital HDD
Jobs
Electrician
C# Programmer+Web Programmer
Gamer
mack is offline  
 
Closed Thread

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On