vbscript problems

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
Well in my web design class the teacher is using vbscript. its fairly simple, but I am having a huge problem.
I basically have a bunch of text boxes I am using and I need to do conversions across them (miles to kilometeres etc)

Im having trouble the the "if else" statements
What I need to do is be able to convert back and forth between miles and kilometers etc. so if they input km they get miles and visa-versa.

Here it is so far, workes best in ms visual studio since thats is what im forced to use.
any ideas on why when I add the 2nd if statement the program just stops working?

http://www.fidaofamily.com/Chris/9906hw1.htm
(right click, save target as, open in compiler)
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
vbscript does not like the = empty comparison
vbscript also wants different variable names in each area of the IF clause:

If statement should look like

IF ... THEN
ELSEIF ... THEN

END IF
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
the other option is did was

if isnumeric(window.miles.value)=true

could i just use that instead?

also, ill work on the structure of the if-then


oh, and the diff variable names is clutch knowledge to know, thanks...
 

imported_Phil

Diamond Member
Feb 10, 2001
9,837
0
0
Originally posted by: KB
vbscript does not like the = empty comparison
vbscript also wants different variable names in each area of the IF clause:

If statement should look like

IF ... THEN
ELSEIF ... THEN

END IF

Agreed. Not knowing VBS makes it difficult for me, but with a knowledge of C++ I can see where he's going wrong. What you posted is pretty much what I posted in his TFNN thread.
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
Phil i had the if else stuff OK (eventually lol), just got it to work, the only problem was the variable naming part (see above 🙂 )


thanks a lot guys! - will let you know if anything else crops up.
 

imported_Phil

Diamond Member
Feb 10, 2001
9,837
0
0
Originally posted by: NiKeFiDO
Phil i had the if else stuff OK (eventually lol), just got it to work, the only problem was the variable naming part (see above 🙂 )


thanks a lot guys! - will let you know if anything else crops up.

You had it just like this?

'if isnumeric(window.kilometers.value)=true then
elseif window.miles.value=empty then
dim mile, kilometer
kilometer=csng (window.kilometers.value)
mile=kilometer/1.609347
window.miles.value=mile
end if

I really can't see how that would work. The logic behind that if() statement is mind-boggling 😛
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
no not at all like that, i still dont know why you have

'if isnumeric(window.kilometers.value)=true then
elseif window.miles.value=empty then

where did that "elseif" come from?
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
'Pounds and kilogram conversion
if isnumeric(window.pounds.value)=true then
dim pound, kilogram
pound=csng (window.pounds.value)
kilogram=pound*.4536
window.kilograms.value=kilogram

elseif isnumeric(window.kilograms.value)=true then
dim pound1, kilogram1
kilogram1=csng (window.kilograms.value)
pound1=kilogram1 / .4536
window.pounds.value=pound1
end if
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
http://www.fidaofamily.com/Chris/9906hw1.htm <--updated to up to now


last problem I am having (probably simple)
everything works up until the last conversion! the last converstion is fahrenheit to celsius..

here is the code:
'Fahrenheit and celsius conversion
if isnumeric (window.fahrenheit.value)=true then
dim fahr, cels
fahr=csng (window.fahrenheit.value)
cels = (fahr ? 32)/1.8
window.celsius.value=cels

elseif isnumeric(window.celsius.value)=true then
dim fahr1, cels1
cels1=csng (window.celsius.value)
fahr1 = (1.8*cels1) + 32
window.fahrenheit.value=fahr1
end if


see anything wrong with this? seems the same as the others to me, but this part wont work! Again, check out the updated version 🙂


also, my reset button doesnt work. wtf?
 

NiKeFiDO

Diamond Member
May 21, 2004
3,901
1
76
not sure what the diff is, but I got it to work by retyping the whole last statement
if isnumeric (window.faren.value)=true then
dim degFaren, degCels
degFaren=csng(window.faren.value)
degCels=((degFaren-32)/1.8)
window.cels.value=degCels

elseif isnumeric (window.cels.value)=true then
dim degFaren1, degCels1
degCels1=csng(window.cels.value)
degFaren1=((1.8*degCels1)+32)
window.faren.value=degFaren1
end if
 

imported_Phil

Diamond Member
Feb 10, 2001
9,837
0
0
Originally posted by: NiKeFiDO
no not at all like that, i still dont know why you have

'if isnumeric(window.kilometers.value)=true then
elseif window.miles.value=empty then

where did that "elseif" come from?

From your source code, you gigantic halfwit 😛 😉
 

SaturnX

Diamond Member
Jul 16, 2000
3,415
0
76
Originally posted by: NiKeFiDO
not sure what the diff is, but I got it to work by retyping the whole last statement
if isnumeric (window.faren.value)=true then
dim degFaren, degCels
degFaren=csng(window.faren.value)
degCels=((degFaren-32)/1.8)
window.cels.value=degCels

elseif isnumeric (window.cels.value)=true then
dim degFaren1, degCels1
degCels1=csng(window.cels.value)
degFaren1=((1.8*degCels1)+32)
window.faren.value=degFaren1
end if

I'm not sure how VBScript works, as I've never used it, but if it functions the same way as VB does, by doing a dim statement WITHOUT the AS [VariableType] declaration ends up allocating them as Variants. Which given that they're numbers is a huge waste a space, (yes I know this is a simple app and it wouldnt' be relavent, but still good programming practice)

Then again I'm not sure if you can do that...

--Mark
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Sorry for the giant threadcrap I'm about to take but ...

Why are you learning vbscript in a web design class? Does your instructor not understand that there is more than one browser in the world and that standards matter?
 

Rip the Jacker

Diamond Member
Dec 29, 2004
5,415
1
76
/me dies reading the code

<-- Programming Newbie, but like kamper said, why are you learning VBScript in a web design class? I don't think it's ever used.

XHTML --> CSS --> Javascript --> PHP

?