【发布时间】:2014-11-29 12:46:15
【问题描述】:
我需要图像中此表单的代码帮助(数量就是数量!)。当我按“计算”以在 Textbox4 中以折扣价 (Textbox3) 获得一件的价格 (Textbox2) 时,同时导致 Textbox4 的金额 (Textbox1) 乘以价格 (Textbox2) 和折扣 (Textbox3 )。
像这样:
Textbox4 = Textbox3 (discount of) Textbox2
和Textbox5 = Textbox1 * Textbox2 (with discount) Textbox3
我有第一个的代码:
Private Sub TextBox1_AfterUpdate()
With TextBox3
.Text = format(Val(Replace(.Text, "%", vbNullString)) / 100, "#.0# %")
End With
End Sub
Private Sub CommandButton1_Click()
TextBox4.Text = Val(Replace(TextBox3.Text, "%", vbNullString)) / 100 * Val(TextBox2.Text)
End Sub
【问题讨论】:
-
您能否澄清一下,您在输入数量之前是否为 TextBox2 和 3 设置了值?为什么必须发生 afterUpdate 事件?如果您输入三个顶部框,然后单击计算。另外,您是否在实际的 Textbox3 中添加了“%”?
-
我在 TextBoxes 中输入数据并按计算,“afterUpdate”是我的错,应该是“Private Sub TextBox3_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)”
-
但是如果你看到我在textbox2价格和折扣和textbox3输入时也有问题?!我没有得到你需要的东西。比如一个1000的30%是700但是我得到了300,要怎么反转呢?
-
1000的30%其实就是300。折扣是你拿走多少,价格是原价——折扣。
-
好的,我的英语有点差,但是你能帮我写代码而不是数学吗?