简体   繁体   English

Vb.net附加文本框的行

[英]Vb.net appending lines of a textbox

        Case 0
            MyValues(0) = InputBox("Geef de wisselkoers (> 0 en < 500) voor de Euro tov Amerikaanse dollars (1 Eur = .... Amerikaanse Dollars")
            Do Until MyValues(0) >= 0 And MyValues(0) <= 500
                MsgBox("De parameters vallen buiten de wisselkoers. Lees de text nog maals in het volgende scherm")
                MyValues(0) = InputBox("Geef de wisselkoers (> 0 en < 500) voor de Euro tov Amerikaanse dollars (1 Eur = .... Amerikaanse Dollars")
            Loop
            Wisselkoersenlistbox.Text = String.Join(Environment.NewLine, MyValues)
        Case 2
            MyValues(1) = InputBox("Geef de wisselkoers (> 0 en < 500) voor de Euro tov Britse Ponden (1 Eur = .... Britse Ponden")
            Do Until MyValues(1) >= 0 And MyValues(1) <= 500
                MsgBox("De parameters vallen buiten de wisselkoers. Lees de text nog maals in het volgende scherm")
                MyValues(1) = InputBox("Geef de wisselkoers (> 0 en < 500) voor de Euro tov Amerikaanse dollars (1 Eur = .... Amerikaanse Dollars")
            Loop
            Wisselkoersenlistbox.Text = String.Join(Environment.NewLine, MyValues)

This works now :- ) Thank you very much!!!!! 现在可以使用了:-)非常感谢!!!! I've clicked a plus but can't give out till I reach 15 :( 我点击了加号,但直到15岁才放弃:(

As mentioned by @the_lotus in comments, you're trying to store date in your text box and manipulate it there. 正如@the_lotus在评论中提到的那样,您试图将日期存储在文本框中并在其中进行操作。 This presents a lot of issues. 这带来了很多问题。 Much easier to store the information in an array, update it as required and then rebuild the textbox contents any time the info changes... 将信息存储在数组中更容易,根据需要进行更新,然后在信息更改时重新构建文本框内容...

' Declare a variable to hold your messages. I've gone with 5 here but it can be any reasonable number (or you can use ReDim to change size later if you don't know from the start)
Dim MyMessages(5) As String {"Default Values go here (if any)", "Line2", "Line3", String.Empty, String.Empty}

' Update them as required in your existing Select Case statement

Case 0
    ' ... Other code ...
    ' Update message at index 0 (Line #1) to be whatever they input
    MyMessages(0) = InputBox("Geef de wisselkoers (> 0 en < 500) voor de Euro tov Amerikaanse dollars (1 Eur = .... Amerikaanse Dollars")
Case 1
    ' ... Other code ...
    ' Update message at index 1 (Line #2) to be "Something"...
    MyMessages(1) = "Something"

' ...etc...


' Finally, update the textbox so all messages are shown one-per-line

MessageBox1.Text = String.Join(Environment.NewLine, MyMessages)

Re: Comments on formatting 回复:关于格式的评论

The correct syntax for what you're trying is this... 您尝试使用的正确语法是……

Wisselkoersenlistbox.Text = String.Join(" amerikaanse Dollar" & Environment.NewLine & "1 Euro = ", MyValues)

Unfortunately, that's not very helpful as it only puts the string between values, not in front of the first one or after the last one. 不幸的是,这不是很有帮助,因为它仅将字符串放在值之间,而不是在第一个值之前或在最后一个值之后。

More useful would be to simply format the variables as they're added to the array... 更有用的是在将变量添加到数组时简单地格式化它们...

Dim format = "1 Euro = {0:0.00} amerikaanse Dollar"
Dim input = Double.Parse(InputBox("..."))
MyMessages(x) = String.Format(format, input)

The format string we're providing shows where to put the number and also that it should always show 2 decimal places (no more/less). 我们提供的格式字符串显示了放置数字的位置,还应始终显示2个小数位(不多/少)。

It's worth noting that working with currencies using Single or Double data types is not recommended - as the numbers get larger, the accuracy decreases (just a side-effect of how floating point arithmetic works ). 值得注意的是,不建议使用单或双数据类型的货币-随着数字的增加,精度会下降(这只是浮点算法工作的副作用)。 It might be fine for displaying info / working out approximations, but you should not use it for anything serious, especially when results are used together and errors can compound. 显示信息/计算近似值可能会很好,但是不要将其用于任何严重的事情,尤其是当结果一起使用且错误可能加重时。

As an example, try doing something like: 例如,尝试执行以下操作:

Dim Total as Double
For i = 1 to 1000000
    Total = Total + 1 / 1000000
Next i

Intuitively, Total should be exactly 1 at the end of this loop. 直观地,在此循环结束时, Total应该恰好为1。 In fact, it will be a little above or below i . 实际上,它会比i

For currencies, use the Decimal data type and specify the appropriate degree of accuracy required. 对于货币,请使用“ Decimal数据类型并指定所需的正确度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM