Problem with my Function!!! Please help!

# Thread: Problem with my Function!!! Please help!

1. tr Guest

## Problem with my Function!!! Please help!

Hi.<BR>I have a function that prints out the "level" of a member.<BR>The Problem: If a member has over 20, he should be "Normal" but it prints out Beginner instead. Thats beacuse he has over 10. But i want it to be if he has BETWEEN 10 and 20, he should be Beginner, 21-30: Normal and so on. Hope you understand.<BR><BR>If he has under 10, i prints out Newbie. like it should. But if he has over 10, no matter how much, it prints "Beginner", it shouldn&#039t be that way!<BR><BR>I print it out with Resonse.Write and then " & isHello(rs("Posts")) & "<BR><BR>Hope you understand.<BR><BR>&#039This is the function.<BR>Function isHello(dt)<BR> <BR> if rs("Posts") &#062;= 10 Then<BR> isHello = "Beginner"<BR><BR> elseif rs("Posts") &#062;= 20 Then<BR> isHello = "Normal"<BR><BR> elseif rs("Posts") &#062;= 30 Then<BR> isHello = "Advanced"<BR><BR> elseif rs("Posts") &#062;= 50 Then<BR> isHello = "Expert"<BR> else<BR> isHello = "Newbie"<BR> end if<BR> <BR>End Function<BR><BR>&#039End of function<BR><BR>PLEASE HELP!!!

2. SteveC Guest

## RE: Problem with my Function!!! Please help!

This is hardly a question that needs to be posted in the advanced forum... but since I&#039m here...<BR><BR>Your first statement will evaluate to true, so that&#039s why it&#039s returning beginner. If a statement evaluates to true, then it doesn&#039t keep searching through the rest of the &#039else&#039 contents.<BR><BR>Look at your English statement "if he has BETWEEN 10 and 20, he should be Beginner, 21-30: Normal and so on. Hope you understand"<BR><BR>And you&#039ll find your answer.

3. Senior Member
Join Date
Dec 1969
Posts
183

## RE: Problem with my Function!!! Please help!

try this<BR>Function isHello(dt)<BR><BR>if rs("Posts") &#062;= 10 and rs("Posts")&#060;20 Then<BR>isHello = "Beginner"<BR><BR>.<BR>..<BR>..<BR>End Function<BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Problem with my Function!!! Please help!

The "Between" answers you were given work, but there&#039s a simpler way: <BR><BR>Just make the comparisons in reverse!<BR><BR>But *DO* copy that recordset field value to a temp variable and quit eating up so much CPU time!<BR><BR>Thus:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;isHello="Expert"<BR>&nbsp; &nbsp;&nbsp;&nbsp;ElseIf posts &#062;= 40 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;...Function isHello( )<BR>&nbsp;&nbsp;&nbsp;&nbsp;posts = rs("Posts")<BR>&nbsp;&nbsp;&nbsp;&nbsp;If posts &#062;= 50 Then <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;Else<BR>&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isHello="New bie"<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>End Function<BR><BR>*********************<BR><BR>HOWEV ER...A *much* better and faster way:<BR><BR>ScoreNames = Array("Newbie","Beginner","Normal","Advanced","Adv anced","Expert")<BR><BR>Function isHello( )<BR>&nbsp;&nbsp;&nbsp;&nbsp;posts = CInt( rs("Posts") ) 10<BR>&nbsp;&nbsp;&nbsp;&nbsp;If posts &#062; 5 Then posts = 5<BR>&nbsp;&nbsp;&nbsp;&nbsp;isHello = ScoreName(posts)<BR>End Function<BR><BR>**********<BR><BR>And if you don&#039t know what the operator does in VBScript, go look it up in the docs! <BR><BR>(Yes, "Advanced" is in there twice on purpose: Look at the original code as posted.)<BR><BR>**********<BR><BR>p.s.: Why would the NUMBER of posts made by a person determine they are an "Expert" or not???? I see a *LOT* of posts by the same people, over and over, asking for help. I think *ONE* good post answering a tough question is worth a *LOT* more than 100 questions that could be answered by looking in all the *tons* of online resources that are available!<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Scramble in prior message...

First chunk of example code should have read:<BR><BR>Function isHello( )<BR>&nbsp;&nbsp;&nbsp;&nbsp; posts = rs("Posts")<BR>&nbsp;&nbsp;&nbsp;&nbsp; If posts &#062;= 50 Then <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p; isHello="Expert"<BR>&nbsp;&nbsp;&nbsp;&nbsp; ElseIf posts &#062;= 40 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ...<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; isHello="Newbie"<BR>&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>End Function<BR>

6. ty
Junior Member
Join Date
Dec 1969
Posts
19

## RE: Problem with my Function!!! Please help!

it was just an example with the expert thing, i could have written dumb instead if I wanted :-)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•