<body> <form id="form1" runat="server"> <div> <br /> <asp:Label ID="Label1" runat="server" Text="ราคาสินค้า :"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Height="20px" Width="154px"></asp:TextBox> <asp:Label ID="Label4" runat="server" Text="บาท"></asp:Label> <br /> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="ประเภทสินค้า :"></asp:Label> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem>สินค้า A</asp:ListItem> <asp:ListItem>สินค้า B</asp:ListItem> <asp:ListItem>สินค้า C</asp:ListItem> </asp:DropDownList> <asp:Button ID="Button1" runat="server" Height="33px" Text="คำนวณ" Width="97px" /> <br /> <br /> <br /> <asp:Label ID="Label5" runat="server" Text="- - - - - - - - - - - - - - - - - - - - - - - - - -"></asp:Label> <br /> <br /> <asp:Label ID="Label6" runat="server" Text="ราคาสินค้า = "></asp:Label> <br /> <asp:TextBox ID="TextBox2" runat="server" Height="23px" Width="184px"></asp:TextBox> <br /> <br /> <asp:Label ID="Label7" runat="server" Text="ส่วนลด (Dis) ="></asp:Label> <br /> <asp:TextBox ID="TextBox3" runat="server" Height="24px" Width="189px"></asp:TextBox> <br /> <br /> <asp:Label ID="Label8" runat="server" Text="จำนวนเงินที่ต้องชำระ ="></asp:Label> <br /> <asp:TextBox ID="TextBox4" runat="server" Height="22px" Width="234px"></asp:TextBox> <br /> <br /> <br /> </div> </form> </body>
Dim price As Decimal Dim dis As Decimal Dim total As Decimal price = TextBox1.Text dis = 0 Select Case DropDownList1.SelectedIndex Case 0 If price <= 500 Then dis = 0 ElseIf price <= 1000 Then dis = price * 0.3 Else dis = price * 0.5 End If Case 1 If price <= 1000 Then dis = price * 0.5 ElseIf price <= 5000 Then dis = price * 0.1 Else dis = price * 0.2 End If Case 2 If price <= 1500 Then dis = price * 0.15 ElseIf price <= 3000 Then dis = price * 0.25 Else dis = price * 0.5 End If End Select ' / / / / / / / / เเสดงผล / / / / / / / / / total = price - dis TextBox2.Text = ("" & price) TextBox3.Text = ("" & dis) TextBox4.Text = (" " & total)