The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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 :)

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 :)

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

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

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?

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

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)