使一个字符在VB6上只出现一次
我正在 VB6 上创建一个简单的计算器。
这是我正在处理的代码:
textScreen.Text = textScreen.Text & "+"
这是我按下一些数字按钮,然后单击 多次加号按钮:
75+++++++
我希望加号仅出现一次,即使我点击 它的按钮很多次:
92+
...当我再次单击一些数字按钮,然后单击 在加号按钮上,我希望加号再次显示:
58+4+
这在某种程度上类似于 Windows 7 上的默认计算器。
I'm creating a simple calculator on VB6.
Here's my code I'm working on:
textScreen.Text = textScreen.Text & "+"
Here's the result when I press some number buttons, followed by clicking on
the plus sign button several times:
75+++++++
I would like the plus sign to appear only once, even if I click on
its button many times:
92+
...and when I click on some number buttons again, followed by clicking
on the plus sign button, I would like the plus sign to show up again:
58+4+
This is somehow similar to the default Calculator on Windows 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,对此有不同的方法。但一般来说,我不会只是连接一些字符串。这样,您稍后必须解析该字符串,而不仅仅是解决所请求的术语。相反,尝试创建一些堆栈,其中包含您的操作/数字;只需在网上查找计算器示例即可。
无论如何,为此,您必须以某种方式存储最后一次操作(例如,我输入了数字还是运算符?)
如果您想将计算器限制为不带括号等的简单操作,您可以使用布尔值这样:
然后,在添加
+
(或任何其他运算符)之前:添加任何数字时(例如):(
不要指望 100% 无错误代码,我想我还没有接触过 VB6大约8年了。)
Well, there are different approaches for this. But in general, I wouldn't just concatenate some string. This way you'll have to parse the string later on, instead of just solving the requested term. Instead try to create some stack with your operations/numbers on it; just look on the web for calculator examples.
Anyway, for this, you'll have to somehow store the last operation (e.g. did I input a digit or an operator?)
If you'd like to limit the calculator to simple operations without brackets etc. you can use a boolean value for this:
Then, before adding the
+
(or any other operator):When adding any digit (e.g.):
(Don't count on 100% error free code, I think I haven't touched VB6 for like 8 years.)
您可能只需检查文本中的最后一个字符是否为“+”:
You mighty just check if the last character in the text was "+" :