If statement won't continue - vb.net

I am trying to do some computations on VB.net. I used if else statement since I'm a bit familiar with it. My code goes like this
Try
Dim a As Integer = msalary.Text
If (a < 9000) Then
Label5.Text = a - 200
ElseIf (9000 < a < 9999.99) Then
Label5.Text = a - 225
ElseIf (10000 < a < 10999.99) Then
Label5.Text = a - 250
ElseIf (11000 <= a < 11999.99) Then
Label5.Text = a - 275
ElseIf (12000 <= a < 12999.99) Then
Label5.Text = a - 300
ElseIf (13000 <= a < 14000) Then
Label5.Text = a - 325
ElseIf (14000 <= a < 15000) Then
Label5.Text = a - 350
ElseIf (15000 <= a < 16000) Then
Label5.Text = a - 375
ElseIf (17000 <= a < 18000) Then
Label5.Text = a - 400
ElseIf (18000 <= a < 19000) Then
Label5.Text = a - 425
ElseIf (19000 <= a < 20000) Then
Label5.Text = a - 450
ElseIf (20000 <= a < 21000) Then
Label5.Text = a - 475
ElseIf (21000 <= a < 22000) Then
Label5.Text = a - 500
ElseIf (22000 <= a < 23000) Then
Label5.Text = a - 525
ElseIf (23000 <= a < 24000) Then
Label5.Text = a - 550
ElseIf (24000 <= a < 25000) Then
Label5.Text = a - 575
ElseIf (25000 <= a < 26000) Then
Label5.Text = a - 600
ElseIf (26000 <= a < 27000) Then
Label5.Text = a - 625
ElseIf (27000 <= a < 28000) Then
Label5.Text = a - 650
ElseIf (28000 <= a < 29000) Then
Label5.Text = a - 675
ElseIf (29000 <= a < 30000) Then
Label5.Text = a - 700
ElseIf (30000 <= a < 31000) Then
Label5.Text = a - 725
ElseIf (31000 <= a < 32000) Then
Label5.Text = a - 750
ElseIf (32000 <= a < 33000) Then
Label5.Text = a - 800
ElseIf (33000 <= a < 34000) Then
Label5.Text = a - 825
ElseIf (34000 <= a < 35000) Then
Label5.Text = a - 850
ElseIf (a >= 35000) Then
Label5.Text = a - 875
ElseIf a = "" Then
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
The farthest the condition was able to go to -225 even if I put 20000 in it. It will only subtract 225 from the 20000. Is there something wrong on what I did or is there a better way to do it?

Looks like you're missing some AndAlso from your If/ElseIf statements. Normally, you wouldn't be able to go from String to Integer without doing a conversion, so I'm guessing you don't have Option Strict
Try
Dim a As Integer = msalary.Text
If (a < 9000) Then
Label5.Text = a - 200
ElseIf (9000 <= a AndAlso a < 10000) Then
Label5.Text = a - 225
ElseIf (10000 <= a AndAlso a < 11000) Then
Label5.Text = a - 250
ElseIf (11000 <= a AndAlso a < 12000) Then
Label5.Text = a - 275
ElseIf (12000 <= a AndAlso a 13000) Then
Label5.Text = a - 300
ElseIf (13000 <= a AndAlso a < 14000) Then
Label5.Text = a - 325
ElseIf (14000 <= a AndAlso a < 15000) Then
Label5.Text = a - 350
ElseIf (15000 <= a AndAlso a < 16000) Then
Label5.Text = a - 375
ElseIf (17000 <= a AndAlso a < 18000) Then
Label5.Text = a - 400
ElseIf (18000 <= a AndAlso a < 19000) Then
Label5.Text = a - 425
ElseIf (19000 <= a AndAlso a < 20000) Then
Label5.Text = a - 450
ElseIf (20000 <= a AndAlso a < 21000) Then
Label5.Text = a - 475
ElseIf (21000 <= a AndAlso a < 22000) Then
Label5.Text = a - 500
ElseIf (22000 <= a AndAlso a < 23000) Then
Label5.Text = a - 525
ElseIf (23000 <= a AndAlso a < 24000) Then
Label5.Text = a - 550
ElseIf (24000 <= a AndAlso a < 25000) Then
Label5.Text = a - 575
ElseIf (25000 <= a AndAlso a < 26000) Then
Label5.Text = a - 600
ElseIf (26000 <= a AndAlso a < 27000) Then
Label5.Text = a - 625
ElseIf (27000 <= a AndAlso a < 28000) Then
Label5.Text = a - 650
ElseIf (28000 <= a AndAlso a < 29000) Then
Label5.Text = a - 675
ElseIf (29000 <= a AndAlso a < 30000) Then
Label5.Text = a - 700
ElseIf (30000 <= a AndAlso a < 31000) Then
Label5.Text = a - 725
ElseIf (31000 <= a AndAlso a < 32000) Then
Label5.Text = a - 750
ElseIf (32000 <= a AndAlso a < 33000) Then
Label5.Text = a - 800
ElseIf (33000 <= a AndAlso a < 34000) Then
Label5.Text = a - 825
ElseIf (34000 <= a AndAlso a < 35000) Then
Label5.Text = a - 850
ElseIf (a >= 35000) Then
Label5.Text = a - 875
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

I wouldn't use such a giant conditional branch, I'd find a more algorithmic approach.
Example:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim salary As Integer = 34567, subtractor As Integer = 200
Dim r As Range = GetSalaryRange(salary)
For I As Integer = 9000 To r.Lower Step 1000
subtractor += 25
Next
Label5.Text = (salary - subtractor).ToString
End Sub
Function GetSalaryRange(salary As Integer) As Range
If salary < 9000 Then Return New Range() With {.Lower = 0, .Upper = 8999}
Dim remainder As Integer = salary Mod 1000
Return New Range With {.Lower = salary - remainder, .Upper = salary - remainder + 999}
End Function
Public Class Range
Public Lower, Upper As Integer
Public Function Contains(number As Integer) As Boolean
If number >= Lower AndAlso number <= Upper Then Return True Else Return False
End Function
End Class
End Class

Related

If Statement inside Case Statement (VB.Net)

Hi I am new in coding at Visual studio.
I'm Using Visual Studio 2012
I Have a Question.
I want to Connect combobox and textbox31 to textbox1
ex. if the combobox is 100 and textbox31 is 1 so the textbox1 will be 100
I End Up With This Code:
Dim c As String
c = ComboBox1.Text
Select Case "c"
Case 100
If TextBox31.Text >= 2.25 Then
TextBox1.Text = 100
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 75
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
End If
Case 75
If TextBox31.Text >= 2.25 Then
TextBox31.Text = 75
ElseIf TextBox1.Text >= 2.5 Then
TextBox1.Text = 75
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
End If
Case 50
If TextBox31.Text >= 2.25 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
End If
Case 25
If TextBox31.Text >= 2.25 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
End If
End Select
but when i iput in combobox and textbox 31 the textbox1 didnt respond or what i want to get.
The logic you're using there is nested a bit more than I'd normally be comfortable with. In this instance you could consider something more like this:
Dim c As Integer
Dim aintValues() As Integer = {0, 25, 50, 75, 100}
If IsNumeric(ComboBox1.Text) And IsNumeric(TextBox31.Text) Then
c = ComboBox1.Text
Else
Exit Sub
End If
If c <= 25 Then
aintValues = {0, 25, 25, 25, 25}
ElseIf c <= 50 Then
aintValues = {0, 25, 50, 50, 50}
ElseIf c <= 75 Then
aintValues = {0, 25, 50, 75, 75}
End If
If TextBox31.Text >= 3.25 Then
TextBox1.Text = aintValues(0)
ElseIf TextBox31.Text >= 3.0 Then
TextBox1.Text = aintValues(1)
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = aintValues(2)
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = aintValues(3)
ElseIf TextBox31.Text >= 2.25 Then
TextBox1.Text = aintValues(4)
ElseIf TextBox31.Text >= 0 Then
TextBox1.Text = 42
Else
' negative
End If
Or you can still use a select case as follows:
Dim c As Integer
Dim aintValues() As Integer = {0, 25, 50, 75, 100}
If IsNumeric(ComboBox1.Text) And IsNumeric(TextBox31.Text) Then
c = ComboBox1.Text
Else
Exit Sub
End If
If c <= 25 Then
aintValues = {0, 25, 25, 25, 25}
ElseIf c <= 50 Then
aintValues = {0, 25, 50, 50, 50}
ElseIf c <= 75 Then
aintValues = {0, 25, 50, 75, 75}
End If
Select Case TextBox31.Text
Case Is >= 3.25
TextBox1.Text = aintValues(0)
Case Is >= 3.0
TextBox1.Text = aintValues(1)
Case Is >= 2.75
TextBox1.Text = aintValues(2)
Case Is >= 2.5
TextBox1.Text = aintValues(3)
Case Is >= 2.25
TextBox1.Text = aintValues(4)
Case Is >= 0
TextBox1.Text = 42
Case Else
' negative
End Select
I don't know what your script is about, but one thing could be your failure:
The first if..then-statement sets the text of TextBox31 instead of TextBox1.
I rather would write:
If TextBox31.Text >= 2.25 Then
TextBox1.Text = 100
There's a couple issues with your code, but one place to start would be to understand that your conditional
Case 100
If TextBox31.Text >= 2.25 Then
TextBox1.Text = 100
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 75
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
End If
is functionally equivalent to
Case 100
If TextBox31.Text >= 2.25 Then
TextBox1.Text = 100
End If
the other conditions will never be tested because if TextBox31.Text is any value greater than or equal to 2.25 then it passes and we're done.
Addressing this problem, you might reverse the order of your conditions, i.e.
Case 100
If TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 75
ElseIf TextBox31.Text >= 2.25 Then
TextBox1.Text = 100
End If
Additionally, it sounds like you'd like to cover the situation in which TextBox31.Text < 2.25 which you could do with an Else
Case 100
If TextBox31.Text >= 3.25 Then
TextBox1.Text = 0
ElseIf TextBox31.Text >= 3 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 75
ElseIf TextBox31.Text >= 2.25 Then
TextBox1.Text = 100
Else
TextBox1.Text = 100000
End If
I Solve Now The Problem
i Use This Code:
Case 100
If TextBox31.Text >= 3 Then
TextBox1.Text = 0
ElseIf TextBox31.Text >= 2.75 Then
TextBox1.Text = 25
ElseIf TextBox31.Text >= 2.5 Then
TextBox1.Text = 50
ElseIf TextBox31.Text >= 2.25 Then
TextBox1.Text = 75
ElseIf TextBox31.Text >= 1 Then
TextBox1.Text = 100
Else
TextBox1.Text = 0
Thanks Mr.sfletche For Not Giving up helping me.
Same With Other who help me thanyo very much
Mr.sfletche if i have other problems regarding this would you help me in fute
thanks alot guys
It's a problem of mathematical Sequences. You must not use if statement here. If so, you'll go insane when to work to revise is happened unfortunately.
'Example Data
Dim c = "50"
Dim Text = "3.12"
Dim value As Double
Double.TryParse(Text, value)
Dim num = Math.Ceiling((3.25 - value) / 0.25)
Console.WriteLine(Math.Min(Integer.parseInt(c), 25 * num))
I assume that all you want to do is the above.

Syntax in VB Weight Calculator

I'm writing a really simple weight calculator code -- user inputs weight and height, I calculate standard weight for that height, and the code compares that weight to ranges of weights based on the standard in an if/elseif block.
The standard weight is returned correctly, but the code ALWAYS returns "Normal Weight", regardless of the height to weight ratio. I'm new to VB, so my hunch is it's a relatively simple syntax issue.
Dim dbHeight, dbWeight, dbStWeight As Double
dbHeight = CDbl(tbxHeight.Text)
dbWeight = CDbl(tbxWeight.Text)
dbStWeight = (dbHeight * 30.48 - 105) / 0.454
lblFeedback.Text = ("Your standard weight is " & dbStWeight)
If (dbStWeight * 0.9 <= dbWeight <= dbStWeight * 1.1) Then
lblResult.Text = ("Normal Weight")
ElseIf (dbStWeight * 1.1 < dbWeight <= dbStWeight * 1.2) Then
lblResult.Text = ("Over Weight")
ElseIf (dbStWeight * 0.8 <= dbWeight < dbStWeight * 0.9) Then
lblResult.Text = ("Under Weight")
ElseIf (dbWeight > dbStWeight * 1.2) Then
lblResult.Text = ("Very overweight")
ElseIf (dbWeight < dbStWeight * 0.8) Then
lblResult.Text = ("Very underweight")
End If
lblFeedback.Refresh()
lblResult.Refresh()
Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
Dim dbHeight, dbWeight, dbStWeight As Double
dbHeight = CDbl(tbxHeight.Text)
dbWeight = CDbl(tbxWeight.Text)
dbStWeight = (dbHeight * 30.48 - 105) / 0.454
StWeight.Text = ("Your standard weight is " & dbStWeight)
If (dbStWeight * 0.9 <= dbWeight) AndAlso (dbWeight <= dbStWeight * 1.1) Then
Result.Text = ("Normal Weight")
ElseIf (dbStWeight * 1.1 <= dbWeight) AndAlso (dbWeight <= dbStWeight * 1.2) Then
Result.Text = ("Overweight")
ElseIf (dbStWeight <= dbWeight) AndAlso (dbWeight < dbStWeight * 0.9) Then
Result.Text = ("Underweight")
ElseIf (dbWeight > dbStWeight * 1.2) Then
Result.Text = ("Very overweight")
ElseIf (dbWeight < dbStWeight * 0.8) Then
Result.Text = ("Very underweight")
End If
End Sub

Need help adding number to dim's in my loop sequence? vb.net

Here's basically what I have:
Public checkprogresstime_p1 As String = ""
Public checkprogresstime_p2 As String = ""
'P1 Progress bar updater
checkprogresstime_p1 = (time_total.Text - time_p1_hour.Value)
If checkprogresstime_p1 >= 60 Then
checkprogresstime_p1 = 60
time_p1_progress.ForeColor = Color.LimeGreen
ElseIf checkprogresstime_p1 <= 0 Then
checkprogresstime_p1 = 1
End If
If time_p1_progress.Value < 60 Then
time_p1_progress.ForeColor = Color.Red
End If
time_p1_progress.Value = checkprogresstime_p1
Here's basically what I need:
Dim cnt As Integer = 1
Do
'P1 Progress bar updater
checkprogresstime_p(cnt) = (time_total.Text - time_p(cnt)_hour.Value)
If checkprogresstime_p(cnt) >= 60 Then
checkprogresstime_p(cnt) = 60
time_p(cnt)_progress.ForeColor = Color.LimeGreen
ElseIf checkprogresstime_p(cnt) <= 0 Then
checkprogresstime_p(cnt) = 1
End If
If time_p(cnt)_progress.Value < 60 Then
time_p(cnt)_progress.ForeColor = Color.Red
End If
time_p(cnt)_progress.Value = checkprogresstime_p(cnt)
Loop While cnt <= 25
I have no idea how to do it... I need it to loop and add +1, 25 times. I basically have it written out 25 times at the moment...
This is the For/Loop with your current request. The cnt variable will increment itself in this type of Loop.
For cnt As Integer = 1 To 25
'P1 Progress bar updater
checkprogresstime_p(cnt) = (time_total.Text - time_p(cnt)_hour.Value)
If checkprogresstime_p(cnt) >= 60 Then
checkprogresstime_p(cnt) = 60
time_p(cnt)_progress.ForeColor = Color.LimeGreen
ElseIf checkprogresstime_p(cnt) <= 0 Then
checkprogresstime_p(cnt) = 1
End If
If time_p(cnt)_progress.Value < 60 Then
time_p(cnt)_progress.ForeColor = Color.Red
End If
time_p(cnt)_progress.Value = checkprogresstime_p(cnt)
Next
I believe what you're wanting to do has more to do with having 25 progress bars on your form where each one is named time_p#_progress where # is the number of the progress bar. That being said, there are two ways to acheive updating your progress bars without having to copy and paste your code 25 times...
1. Use Me.Controls to get a reference to the progress bar
For j = 1 To 25
Dim pbar As ProgressBar = Me.Controls("time_p" & j & "_progress")
Dim ph As NumericUpDown = Me.Controls("time_p" & j & "_hour")
Dim checkprogresstime As Long = (time_total.Text - ph.Value)
If checkprogresstime >= 60 Then
checkprogresstime = 60
pbar.ForeColor = Color.LimeGreen
ElseIf checkprogresstime <= 0 Then
checkprogresstime = 1
End If
If time_p1_progress.Value < 60 Then
pbar.Value = checkprogresstime
End If
pbar.Value = checkprogresstime
Application.DoEvents()
Next
Note: You didn't tell us what type of control time_p1_hour was. I assumed it was a NumericUpDown down control. So, if it's not, you need to replace it the type of control that time_p1_hour is.
2. Dynamically create your controls as a control array
Initizliaze your progress bars in the Form1_Load method (MyBase.Load)
Private pbars(24) As ProgressBar
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = LBound(pbars) To UBound(pbars)
pbars(i) = New ProgressBar()
pbars(i).Parent = Me
pbars(i).Top = i * pbars(i).Height
pbars(i).Left = 0
pbars(i).Visible = True
Next
End Sub
Put your code inside of a loop like so
For cnt = 0 To 24
checkprogresstime_p(cnt) = (time_total.Text - time_hour(cnt).Value)
If checkprogresstime_p(cnt) >= 60 Then
checkprogresstime_p(cnt) = 60
time_p_progress(cnt).ForeColor = Color.LimeGreen
ElseIf checkprogresstime_p(cnt) <= 0 Then
checkprogresstime_p(cnt) = 1
End If
If time_p_progress(cnt).Value < 60 Then
time_p_progress(cnt).ForeColor = Color.Red
End If
time_p_progress(cnt).Value = checkprogresstime_p(cnt)
Next

VB.Net - Lockbits - Greater Than / Less Than functions

The following code works well for what I am doing. However, it is taking longer than I need it to. The problem is that it iterates over each greater than/less than function and that takes time. I've done some research but can't figure out how to slim it all down so that it runs faster.
The pixel RGB values have to run through the following tests-
(1) If one value is greater than 250, the others have to be less than 5
(2) If one value is less than 5, the others have to be greater than 250
(3) If one value equals zero, the others have to be greater than 0
(4) The difference between any 2 values have to be less than 15 (or any other threshold I set)
(5) See if two values equal zero
Also, will doing 'Exit For' after each of these functions help?
' Create new bitmap from filepath in TextBox1
Dim bmp As New Bitmap(TextBox1.Text)
' Lock the bitmap's pixels
Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, _
Drawing.Imaging.ImageLockMode.ReadWrite, _
Imaging.PixelFormat.Format24bppRgb)
' Get the address of the first line
Dim ptr As IntPtr = bmpData.Scan0
' Declare an array to hold the bytes of the bitmap
Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height
Dim rgbValues(bytes - 1) As Byte
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)
' Retrieve RGB values
Dim RedValue As Int32
Dim GreenValue As Int32
Dim BlueValue As Int32
Dim l As Integer = 0
For x = 0 To bmp.Width
For y = 0 To bmp.Height - 1
l = ((bmp.Width * 3 * y) + (x * 3))
RedValue = rgbValues(l)
GreenValue = rgbValues(l + 1)
BlueValue = rgbValues(l + 2)
If RedValue < 5 AndAlso GreenValue < 5 AndAlso BlueValue > 250 Then
ElseIf RedValue < 5 AndAlso GreenValue > 250 AndAlso BlueValue < 5 Then
ElseIf RedValue > 250 AndAlso GreenValue < 5 AndAlso BlueValue < 5 Then
ElseIf RedValue > 250 AndAlso GreenValue > 250 AndAlso BlueValue < 5 Then
ElseIf RedValue > 250 AndAlso GreenValue < 5 AndAlso BlueValue > 250 Then
ElseIf RedValue < 5 AndAlso GreenValue > 250 AndAlso BlueValue > 250 Then
ElseIf RedValue > 0 AndAlso GreenValue > 0 AndAlso BlueValue.Equals(0) Then
ElseIf RedValue > 0 AndAlso GreenValue.Equals(0) AndAlso BlueValue > 0 Then
ElseIf RedValue.Equals(0) AndAlso GreenValue > 0 AndAlso BlueValue > 0 Then
ElseIf (RedValue - GreenValue) < 15 AndAlso (RedValue - BlueValue) < 15 AndAlso _
(GreenValue - RedValue) < 15 AndAlso (GreenValue - BlueValue) < 15 AndAlso _
(BlueValue - RedValue) < 15 AndAlso (BlueValue - GreenValue) < 15 Then
ElseIf RedValue.Equals(GreenValue) Then
ElseIf RedValue.Equals(BlueValue) Then
ElseIf GreenValue.Equals(BlueValue) Then
ElseIf RedValue.Equals(BlueValue) AndAlso RedValue.Equals(GreenValue) _
AndAlso BlueValue.Equals(GreenValue) Then
Else
MsgBox("Image is color.")
Exit Sub
End If
Next
Next
MsgBox("Image is grayscale.")
' Unlock the bitmap
bmp.UnlockBits(bmpData)
Grayscale colors have always this specification ( R=G=B ).
eg. #cccccc = [R:204 G:204 B:204]
If Not R = G And G = B Then
MsgBox("colored")
Exit Sub
End If

VB code not calculating

For some reason when I run this it only ever calculates to 0
Where am I going wrong? :(
The user has 3 input boxes to place values. From there those values should be calculating. It only ever equals a value of 0. I get no errors
Option Strict On
Public Class Form1
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click
Dim dblPacA, dblPacB, dblPacC, dblAnswerA, dblAnswerB, dblAnswerC, dblGrandTotal As Double
Dim dblAnswerA1, dblAnswerB1, dblAnswerC1 As Double
'Packages Retail
Dim dblPACA_FACTOR As Double = 99
Dim dblPACB_FACTOR As Double = 199
Dim dblPACC_FACTOR As Double = 299
'Rate of each range
Dim dblTENNINE_FACTOR As Double = 0.8
Dim dblTWONINE_FACTOR As Double = 0.7
Dim dblFIVENINE_FACTOR As Double = 0.6
Dim dblONETEN_FACTOR As Double = 0.5
Try
'important calculate
dblAnswerA1 = dblPacA * dblPACA_FACTOR
dblAnswerB1 = dblPacB * dblPACB_FACTOR
dblAnswerC1 = dblPacC * dblPACC_FACTOR
dblPacA = CDbl(txtPacA.Text)
dblPacB = CDbl(txtPacB.Text)
dblPacC = CDbl(txtPacC.Text)
dblGrandTotal = dblAnswerA + dblAnswerB + dblAnswerC
lblGrandTotal.Text = "Gran Total:" & (dblGrandTotal.ToString("c"))
'lblAnswer.Text = dblAnswer.ToString
'lblAnswer.Text = "PackageA:" & dblAnswerA _
' & "PackageB:" & dblAnswerB & "PackageC:" _
'& dblAnswerC & "GrandTotal:" & dblGrandTotal
Catch
End Try
If dblPacA >= 0 Then
If dblPacA < 10 Then
dblAnswerA = dblAnswerA1
lblAnswerA.Text = "PackageA:" & dblAnswerA.ToString("c")
ElseIf dblPacA >= 10 And dblPacA < 20 Then
dblAnswerA = dblAnswerA1 * dblTENNINE_FACTOR
lblAnswerA.Text = "PackageA:" & (dblAnswerA.ToString("c"))
ElseIf dblPacA >= 20 And dblPacA < 50 Then
dblAnswerA = dblAnswerA1 * dblTWONINE_FACTOR
lblAnswerA.Text = "PackageA:" & dblAnswerA.ToString("c")
ElseIf dblPacA >= 50 And dblPacA < 100 Then
dblAnswerA = dblAnswerA1 * dblFIVENINE_FACTOR
lblAnswerA.Text = "PackageA:" & dblAnswerA.ToString("c")
ElseIf dblAnswerA >= 100 Then
dblAnswerA = dblAnswerA1 * dblONETEN_FACTOR
lblAnswerA.Text = "PackageA:" & dblAnswerA.ToString("c")
End If
Else
MessageBox.Show("txtPacA must be greater than or equal to 0", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If dblPacB >= 0 Then
If dblPacB >= 10 And dblPacB <= 19 Then
dblAnswerB = dblAnswerB1 * dblTENNINE_FACTOR
lblAnswerB.Text = "PackageB:" & dblAnswerB.ToString("c")
ElseIf dblPacB >= 20 And dblPacB <= 49 Then
dblAnswerB = dblAnswerB1 * dblTWONINE_FACTOR
lblAnswerB.Text = "PackageB:" & dblAnswerB.ToString("c")
ElseIf dblPacB >= 50 And dblPacB <= 99 Then
dblAnswerB = dblAnswerB1 * dblFIVENINE_FACTOR
lblAnswerB.Text = "PackageB:" & dblAnswerB.ToString("c")
Else
dblAnswerB = dblAnswerB * dblONETEN_FACTOR
lblAnswerB.Text = "PackageB:" & dblAnswerB.ToString("c")
End If
Else
MessageBox.Show("txtPacB must be greater than or equal to 0", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
If dblPacC >= 0 Then
If dblPacC >= 10 And dblPacC <= 19 Then
dblAnswerC = dblAnswerC1 * dblTENNINE_FACTOR
lblAnswerC.Text = "PackageC:" & dblAnswerC.ToString("c")
ElseIf dblPacC >= 20 And dblPacA <= 49 Then
dblAnswerC = dblAnswerC1 * dblTWONINE_FACTOR
lblAnswerC.Text = "PackageC:" & dblAnswerC.ToString("c")
ElseIf dblPacC >= 50 And dblPacC <= 99 Then
dblAnswerC = dblAnswerC1 * dblFIVENINE_FACTOR
lblAnswerC.Text = "PackageC:" & dblAnswerC.ToString("c")
Else
dblAnswerC = dblAnswerC1 * dblONETEN_FACTOR
lblAnswerC.Text = "PackageC:" & dblAnswerC.ToString("c")
End If
Else
MessageBox.Show("txtPacC must be greater than or equal to 0", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
End Class
dblAnswerA1 = dblPacA * dblPACA_FACTOR
where is dblPacA 's value set? its not. its 0