• 0

VBScript Function Question


Question

I'm working on a homework assignment and I have absolutely no idea where to begin with the creation of this function. Here is my assignment, briefly:

I am to create a shirts.html file that creates a form with a number of pieces textbox input, with three buttons: employee total, show summary and clear form. A link to the entire homework assignment, if needed: http://www.skydreamer.co.uk/school/web-scripting/shirts.html

The first thing to do is create a function to calculate the following:

Number of shirts ; Price Per Piece

1 to 199 ; .50

200 to 399; .55

400 to 599 ; .60

600 or more ; .65

Do I use less than, greater than operators to figure this?? If so, I am not quite sure how to go about it - they seem to only calculate two things then. I was doing quite well on my programming homework, which is surprising but now I am 110% stuck. Any help would be greatly appreciated.

Or maybe this should use the if...then...elseif statements? Thanks again for your time...

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I know this will work with server side asp pages so you might have to play with it a little bit, but here you go for what it is worth

function getPrice()
  if isNumeric(textbox1.value) then
   if textbox1.value >=1 or <= 199 then
     getPrice = 50
   end if
   if textbox1.value >=200 or <= 399 then
     getPrice = 55
   end if
   if textbox1.value >=400 or <= 599 then
     getPrice = 60
   end if
   if textbox1.value >=600  then
     getPrice = 65
   end if
  else
   getPrice = "Invalid amount"
  end if
end function

just remember to add the "." back in when doing calculations

Link to comment
Share on other sites

  • 0

Wow, thanks! I just needed to be pointed in the right direction. I'll try that out and let you know how it goes. :) Thanks again, Viper.

Link to comment
Share on other sites

  • 0
Wow, thanks! I just needed to be pointed in the right direction. I'll try that out and let you know how it goes. :) Thanks again, Viper.

no problem, but I was writing that to fast and found one thing you need to change.. change all of the "or"'s to "and"

or it will always evaluate to the first if statement.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.