对不起“愚蠢”的问题。我无法从列表框中的 txtbox 中获取值。现在它在列表框中给出“07650”,而它应该是 76,50...
我有一个名为 formatdecimal 的函数。如果我保存(保存按钮)文本文件(到 .txt),则该值必须保存为“07650”,否则它必须在列表框中像“76,50”一样给出......
有人能帮我吗?
` 公共函数 FormatDecimal(ByVal perc As Decimal) As String
Return (perc * 100).ToString("00000")
End Function` (Source code for the function)
以下是添加按钮的源代码...
Private Sub btnToevoegen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToevoegen.Click (add button)
Dim line As String = ""
Dim number As Integer
Dim name As String = ""
Dim Birthday As Integer
Dim prompt As String
Dim title As String = "FAILURE"
Dim perc As Decimal
If Not CheckLeegtextvak() Then
MessageBox.Show("Give a value in the textbox", "FAILURE", MessageBoxButtons.OK)
Return
End If (check if the textboxes are empty)
'If defaultvalues are okay then do something.
If Not checkdefaultwaarde() Then
prompt = "Select a value in the combobox."
MessageBox.Show(prompt, title, MessageBoxButtons.OK)
Return
End If (check if defaultvalues are okay (beginning of the file)
CheckLengteNaam() (check the length of the name)
number = CInt(txtNumber.Text)
name = CStr(txtName.Text)
Birthday = CInt(txtBirthday.Text)
perc = CDec(txtPercentage.Text)
line = combobox1.SelectedItem.ToString.PadRight(1) & number.ToString.PadRight(5) & name.ToString.PadLeft(5) & birthday.ToString.PadRight(5) & perc.ToString.PadLeft(5)
lstOutput.Items.Add(行)
FormatDecimal(perc)
End Sub
当我添加记录时,perc 的值必须是 76,50。当我将表单保存到 txtfile 时,该值必须是 07650(这就是函数的用途),但它没有保存正确的值。它节省了“76,50”。
保存并另存为代码...
Private Sub mnuBestandOpslaan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBestandOpslaan.Click (This is the save button)
Dim index As Integer
Dim perc As Decimal
'Zoeken naar opgegeven map om bestand in op te slaan onder dezelfde naam.
If dlgOpen.FileName = "" Then
mnuSavefileAs_Click(sender, e)
Else
FileOpen(1, dlgOpen.FileName, OpenMode.Output)
For index = 0 To lstOutput.Items.Count - 1
PrintLine(1, lstOutput.Items(index))
Next
FileClose(1)
End If
FormatDecimal(perc)
End Sub
Private Sub mnuBestandOpslaanAls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBestandOpslaanAls.Click (This is the save as button)
Dim index As Integer
Dim perc As Decimal
'Search folder to save file.
With dlgSave
.InitialDirectory = "C:\My Documents"
.Filter = "tekstbestanden (*.txt) | *.txt"
.Title = "Save as"
End With
'Save file.
If dlgSave.ShowDialog = DialogResult.OK Then
FileOpen(1, dlgSave.FileName, OpenMode.Output)
For index = 0 To lstOutput.Items.Count - 1
PrintLine(1, lstOutput.Items(index))
Next
FileClose(1)
End If
FormatDecimal(perc)
End Sub
您可以作为数字给出的最大值是 100,如 100%...