Solved

Need help to compare a value with an IF statement

Posted on 2006-06-21
6
204 Views
Last Modified: 2010-07-27
Hey guys whats up .
This is a bit troubling , but I've been trying to get this to work and for some reason it doesn't work.

My objective is to try to compare a result with an IF statement.
Example

I have 4 textbox...2 of them the user inserts numeric value
the third one gives me the percent
and the fourth one assigns an Alphabet to what the value range falls in

Think of it like grading a student from 90 + = "A" , 80 = B, C = 70
and so on and so forth

This is what I have so far...looks fairly simplistic as well
/////

  Dim SellingPrice As Double
        Dim ListPrice As Double
        Dim Percent As Double

        SellingPrice = txtSellingPrice.Text
        ListPrice = txtListPrice.Text


        'Will divide to calculate percent.
        Try
           
        Percent = SellingPrice / ListPrice
        Catch exMessage As DivideByZeroException
            MsgBox(exMessage.Message)
               End Try

       
        If Percent > 99 Then
            txtDealType.Text = "A"
        ElseIf Percent > 96 And Percent < 99 Then
            txtDealType.Text = "B"
        ElseIf Percent > 93 And Percent < 96 Then
            txtDealType.Text = "C"
        ElseIf Percent < 93 Then
            txtDealType.Text = "D"
        End If

        txtPERC.Text = FormatPercent(Percent, 1)
////////////////////

Ok here is the problem now...when ever I put ANY number to get the percent I always get the Value "D"
Even If I let say put
Sellingprice = 95 and ListPrice 100
this will give me  95%
but I still get a value of "D"...hell I can put both prices at 100 to get a percent of 100 and I still get "D" value


Also I put some breakpoints within the IF, elseif statments and I notice that my Percent value stores it like this (0.95)
That alone tells me that obviously is less than it really should be.....
Therefore I'm thinking is there a way for it not be be a percent, but better yet a whole number...maybe I can avoid that whole error that I'm getting

Thanks for your time guys :)





0
Comment
Question by:masterat03
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 16952860
Don't you just need to multiply percent by 100 and then you could compare to integers like 93?
0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16952909
Why don't you do put decimal points while comparing like this?
 If Percent > 99 Then
            txtDealType.Text = "A"
        ElseIf Percent > 96 And Percent < 99 Then
            txtDealType.Text = "B"
        ElseIf Percent > 93 And Percent < 96 Then
            txtDealType.Text = "C"
        ElseIf Percent < 93 Then
            txtDealType.Text = "D"
        End If

Or multily with 100 while calculating percent
   Percent = SellingPrice / ListPrice * 100
0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16952919
forgot to put decimal points
 If Percent > .99 Then
            txtDealType.Text = "A"
        ElseIf Percent > .96 And Percent < .99 Then
            txtDealType.Text = "B"
        ElseIf Percent > .93 And Percent < .96 Then
            txtDealType.Text = "C"
        ElseIf Percent < .93 Then
            txtDealType.Text = "D"
        End If
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:masterat03
ID: 16952940
you are correct mastoo how silly of me not multiplying it after it gets divided :(

hey I was going to say though my output goes out of range..example
instead of 95.0% it does this

95,000%

Even though before i had the
txtPERC.Text = FormatPercent(Percent, 1)


is there anyway to format it correctly besides the way im doing it now?
0
 
LVL 4

Accepted Solution

by:
indu_mk earned 100 total points
ID: 16952988
Dim SellingPrice As Double
        Dim ListPrice As Double
        Dim Percent As Double

        SellingPrice = txtSellingPrice.Text
        ListPrice = txtListPrice.Text


        'Will divide to calculate percent.
        Try

            Percent = SellingPrice / ListPrice
        Catch exMessage As DivideByZeroException
            MsgBox(exMessage.Message)
        End Try


        If Percent > 0.99 Then
            txtDealType.Text = "A"
        ElseIf Percent > 0.96 And Percent < 0.99 Then
            txtDealType.Text = "B"
        ElseIf Percent > 0.93 And Percent < 0.96 Then
            txtDealType.Text = "C"
        ElseIf Percent < 0.93 Then
            txtDealType.Text = "D"
        End If
        txtPERC.Text = FormatPercent(Percent, 1)
0
 

Author Comment

by:masterat03
ID: 16952990
hey indu mk it works the way you said.
I find it much easier, plus I didnt have to multiply it by 100 because the decimal is already in place
//////

If Percent > 0.99 Then
            txtDealType.Text = "A"

        ElseIf Percent > 0.96 And Percent < 0.99 Then
            txtDealType.Text = "B"
        ElseIf Percent > 0.93 And Percent < 0.96 Then
            txtDealType.Text = "C"

        ElseIf Percent < 0.93 Then
            txtDealType.Text = "D"
        End If

        txtPERC.Text = FormatPercent(Percent, 1)


/////////
This definetly works well


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 32
Close form "before" open 3 39
VB 2005 Tooltips on Form Load Event 15 29
VB 2005 how to get a new line of data each time I try to write to a file. 10 24
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now