CodingVB Script Question

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Mod_Inside (MODINSIDE)  
 To:  ALL
33245.1 

Hi

 

Anyone know how to do this?

 

I have a webpage that has to calculate Degree Days for fuel usage within the home. It has a field called strdegday which is populated from a calculation of min and max temperature divided by 2.

 

so max 19 + min 13 = 32 / 2 = 16

 

We work from a normal of 19 for the degrees round here, so 19-16 leaves me 3 as the degree day.

 

Phew hope that makes sense.

 

But i need to add a factor for Hot Water usage and that's where im stumped.

 

With the field stdegday now populated with the figure 3 I need to do an IF calculation on it.

 

I need to know:

 

if strdegday= 0 to 6 then write 0
or if strdegday=7 to 10 then write 1
11 to 16=2 and 17 and over write 3

 

If only it was as easy as above !

 

It's to build in a hot water factor so if Degreeday was 9 then there would be a plus 1 hot water factor, leaving me finally with a total degree day of 10.

 

Any pointers in the right direction would be really appreciated.

 

Regards

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.2 In reply to 33245.1 
Error. Does not compute. Too much input.

(You've written lots of stuff, but it's not concise enough to make it clear what you're asking.)

Still, I'll give it a go anyway

quote:
I need to know:

if strdegday= 0 to 6 then write 0
or if strdegday=7 to 10 then write 1
11 to 16=2 and 17 and over write 3


Ok, so:
VB code:
Function calcHotWaterFactor(strdegday)
	Dim result
	If strdegday < 10
		Then result = Round(0.0023*strdegday*strdegday + 0.13*strdegday - 0.44,0)
		Else result = Round(0.0023*strdegday*strdegday + 0.13*strdegday - 0.19,0)
	End If
	calcHotWaterFactor = result
End Function


If that doesn't do what you want, you'll need to clarify what you want.
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Peter (BOUGHTONP)     
33245.3 In reply to 33245.2 
Thanks for the reply Pete but it doesnt look like what I want.

If say strdegday is between 0 to 6 then I want it to write the value 0

or strdegday is between 7 to 10 then I want it to write the value 1

or strdegday is between 11 to 16 then I want it to write the value 2

or strdegday is 17 and over then I want it to write the value 3

Apologies if im not explaining it clearly it would only wright write one of those values above as it's result.

Thanks in advance !


<edit>What hope have I got when I cant spell write !</edit>
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.4 In reply to 33245.3 
That function will only write one of those values.

Simply do:
VB code:
document.write(calcHotWaterFactor(strdegday))


And you should get the appropriate 0/1/2/3 value written out.
0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Mod_Inside (MODINSIDE)     
33245.5 In reply to 33245.3 
code:
Function calcHotWaterFactorLikeANormalPerson(ByVal strdegday As Integer) as integer
    Dim result as integer
    Select Case strdegday
        Case 0 To 6
            result = 0
        Case 7 To 10
            result = 1
        Case 11 To 16
            result = 2
        Case Else
            result = 3
    End Select
    
    calcHotWaterFactor = result
End Function


I can't be bothered working out if Peter's version would be more efficient or in some other way advantageous - it's unreadable.

Kenny
The Wisdom of IMDB Messageboards:
One Night At McCool's

There's one thing I don't understand: Why would Randy and Jewel, for some reason, have sex right at the beginning of the movie?

-- Um, like, are you kidding? Randy sees the golden opportunity (like finding plutonium by accident) and takes it.
0/0
 Reply   Quote More 

 From:  bob (BOBFARRELL)  
 To:  ALL
33245.6 

Ahahaha, AHAHAHAHAHAHA. VB indeed. Ever heard of JavaScript? SOOoooooo much better, ZZZZZZZzzzzzzzzzzzzzzzzzzz.

0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Kenny J (WINGNUTKJ)     
33245.7 In reply to 33245.5 

Hmm, anything i'm maybe doing wrong?

 

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/Degday/DegreeDayslist.asp, line 486
Function calcHotWaterFactor(ByVal strdegday As Integer) as integer

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.8 In reply to 33245.7 
Does the integer need to be Integer?
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Peter (BOUGHTONP)     
33245.9 In reply to 33245.8 

Doesnt appear to be?

 

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/Degday/DegreeDayslist.asp, line 486
Function calcHotWaterFactor (ByVal strdegday As Integer) as Integer

0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Peter (BOUGHTONP)     
33245.10 In reply to 33245.8 

When I run your one you created I get this too

 

Technical Information (for support personnel)

 

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/Degday/DegreeDayslist.asp, line 486
Function calcHotWaterFactor(strdegday)

 

Any ideas ?

0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Mod_Inside (MODINSIDE)     
33245.11 In reply to 33245.7 
Oh - ASP VBScript - it doesn't bother with types, everything's a variant, so remove all the "AS Integer" stuff, and the ByVal in front of the parameter.

Kenny
The Wisdom of IMDB Messageboards:
One Night At McCool's

There's one thing I don't understand: Why would Randy and Jewel, for some reason, have sex right at the beginning of the movie?

-- Um, like, are you kidding? Randy sees the golden opportunity (like finding plutonium by accident) and takes it.
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Kenny J (WINGNUTKJ)     
33245.12 In reply to 33245.11 

Thanks Kenny,

 

Heres what I get now

 

Technical Information (for support personnel)

 

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/Degday/DegreeDayslist.asp, line 486
Function calcHotWaterFactorLikeANormalPerson

 

Using this,

 

<% Function calcHotWaterFactorLikeANormalPerson
Dim result
Select Case strdegday
Case 0 To 6
result = 0
Case 7 To 10
result = 1
Case 11 To 16
result = 2
Case Else
result = 3
End Select

calcHotWaterFactor = result
End Function %>

0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Kenny J (WINGNUTKJ)     
33245.13 In reply to 33245.11 
Is there a certain place that the code needs to go within the page? Making an arse of this !
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.14 In reply to 33245.10 
>> Any ideas ?

Other than taking Bob's advice and using JavaScript, no. :(


Here's how it could be done with JS:
JavaScript code:
function calcHotWaterFactor(strdegday)
{
	if (strdegday <= 6) return 0
	else if (strdegday <= 10) return 1
	else if (strdegday <= 16) return 2
	else return 3;
}
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Peter (BOUGHTONP)     
33245.15 In reply to 33245.14 

One stupid to you probably question how do I get it to write the result?

 

Thanks

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.16 In reply to 33245.15 
Both VBScript and JavaScript have access to the DOM, and thus use document.write(value) where value is what you want to write, and can be any variable/function/etc.
0/0
 Reply   Quote More 

 From:  Kenny J (WINGNUTKJ)  
 To:  Mod_Inside (MODINSIDE)     
33245.17 In reply to 33245.12 

Which line is 486? You seem to have lost the parameter - the fuction definition should be:

 

Function calcHotWaterFactorLikeANormalPerson(strdegday)

 

I've got a feeling that in ASP, the function definition needs to be above any calls to it. I've not done ASP in years :S.


Kenny
The Wisdom of IMDB Messageboards:
One Night At McCool's

There's one thing I don't understand: Why would Randy and Jewel, for some reason, have sex right at the beginning of the movie?

-- Um, like, are you kidding? Randy sees the golden opportunity (like finding plutonium by accident) and takes it.
0/0
 Reply   Quote More 

 From:  Mod_Inside (MODINSIDE)  
 To:  Kenny J (WINGNUTKJ)     
33245.18 In reply to 33245.17 

Your right I was calling it first. On moving it up to the page header I get

 

Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/Degday/DegreeDayslist.asp, line 190, column 7
Case 0 To 6
------^

 

186 <%
187 Function calcHotWaterFactorLikeANormalPerson(strdegday)
188 Dim result
189 Select Case strdegday
190 Case 0 To 6
191 result = 0
192 Case 7 To 10
193 result = 1
194 Case 11 To 16
195 result = 2
196 Case Else
197 result = 3
198 End Select
199
200 calcHotWaterFactor = result
201 End Function
202 %>

 

If your too busy it doesn't matter, as I understand folks have work to do !

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.19 In reply to 33245.18 
You could try
code:
Case 0,1,2,3,4,5,6
	result = 0
Case 7,8,9,10
	result = 1
(etc)
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mod_Inside (MODINSIDE)     
33245.20 In reply to 33245.18 
Ah, Google supplied this...

There is no solution for this in vbscript. It works in Visual Basic. It does
NOT work in vbscript.
There IS a workaround:

Select Case true
Case (Number1>=1 and Number1 <=5)
...
End Select
0/0
 Reply   Quote More 

Reply to All  
 

1–20  21–31

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats