I am creating a program that calculates the monthly electricity bill based on usage. The codes are not neat and does not look very...concise, but it works. I tried using an array (have not learned that in my course yet) because when I searched around for answers, arrays will usually be the solution to it. However, when I use it in my code, it only calculates for the second statement, like if I have If...Else If, it'll only check for Else If and ignore the initial If.
I have created another project to resemble the problem. As you'll see below, the month is only until May, and I have to get it to October...
Option Strict On Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim marTA, aprTA, mayTA As Single Dim mar, apr, may As Decimal Decimal.TryParse(TextBox1.Text, mar) : Decimal.TryParse(TextBox2.Text, apr) Decimal.TryParse(TextBox3.Text, may) Select Case True Case mar = 0 marTA = 3D + (3D * 0.06) TextBox4.Text = marTA.ToString("C2").Replace("$", "RM ") Case mar >= 1 And mar < 201 marTA = CSng(mar * 0.109) TextBox4.Text = marTA.ToString("C2").Replace("$", "RM ") Case mar >= 201 And mar < 301 marTA = CSng((200 * 0.109) + ((mar - 200) * 0.153)) TextBox4.Text = marTA.ToString("C2").Replace("$", "RM ") Case mar >= 301 And mar < 601 marTA = CSng((200 * 0.109) + (100 * 0.153) + ((mar - 300) * 0.172)) TextBox4.Text = marTA.ToString("C2").Replace("$", "RM ") Case mar >= 601 And mar < 901 marTA = CSng((200 * 0.109) + (100 * 0.153) + (300 * 0.172) + ((mar - 600) * 0.182)) TextBox4.Text = marTA.ToString("C2").Replace("$", "RM ") Case mar >= 901 marTA = CSng((200 * 0.109) + (100 * 0.153) + (300 * 0.172) + (300 * 0.182) + ((mar - 900) * 0.215)) TextBox4.Text = marTA.ToString("C2").Replace("$", "RM ") End Select Select Case True Case apr = 0 aprTA = 3 + (3 * 0.06) TextBox4.Text = aprTA.ToString("C2").Replace("$", "RM ") Case apr >= 1 And apr < 201 aprTA = CSng(apr * 0.109) TextBox4.Text = aprTA.ToString("C2").Replace("$", "RM ") Case apr >= 201 And apr < 301 aprTA = CSng((200 * 0.109) + ((apr - 200) * 0.153)) TextBox4.Text = aprTA.ToString("C2").Replace("$", "RM ") Case apr >= 301 And apr < 601 aprTA = CSng((200 * 0.109) + (100 * 0.153) + ((apr - 300) * 0.172)) TextBox4.Text = aprTA.ToString("C2").Replace("$", "RM ") Case apr >= 601 And apr < 901 aprTA = CSng((200 * 0.109) + (100 * 0.153) + (300 * 0.172) + ((apr - 600) * 0.182)) TextBox4.Text = aprTA.ToString("C2").Replace("$", "RM ") Case apr >= 901 aprTA = CSng((200 * 0.109) + (100 * 0.153) + (300 * 0.172) + (300 * 0.182) + ((apr - 900) * 0.215)) TextBox4.Text = aprTA.ToString("C2").Replace("$", "RM ") End Select Select Case True Case may = 0 mayTA = 3 + (3 * 0.06) TextBox4.Text = mayTA.ToString("C2").Replace("$", "RM ") Case may >= 1 And may < 201 mayTA = CSng(may * 0.109) TextBox4.Text = mayTA.ToString("C2").Replace("$", "RM ") Case may >= 201 And may < 301 mayTA = CSng((200 * 0.109) + ((may - 200) * 0.153)) TextBox4.Text = mayTA.ToString("C2").Replace("$", "RM ") Case may >= 301 And may < 601 mayTA = CSng((200 * 0.109) + (100 * 0.153) + ((may - 300) * 0.172)) TextBox4.Text = mayTA.ToString("C2").Replace("$", "RM ") Case may >= 601 And may < 901 mayTA = CSng((200 * 0.109) + (100 * 0.153) + (300 * 0.172) + ((may - 600) * 0.182)) TextBox4.Text = mayTA.ToString("C2").Replace("$", "RM ") Case may >= 901 mayTA = CSng((200 * 0.109) + (100 * 0.153) + (300 * 0.172) + (300 * 0.182) + ((may - 900) * 0.215)) TextBox4.Text = mayTA.ToString("C2").Replace("$", "RM ") End Select End Sub End Class Design View:
