Visual Studio 2010 String.Format 异常
Visual Studio 2010 String.Format exception
我正在尝试使用 format.string 将列插入列表框,但它似乎不起作用,"Input string was not in correct format" 它说。我 运行 没有办法解决这个问题,在 google 上找不到任何解决方案。所以我决定在这里问,顺便说一句,这是我的代码
Public Class Form1
Dim stddetails As String = "{0, -20}{1, -20}{2, -20}{3, -20}(4, -20}{5, -20}{6, -20}"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lstoutput.Items.Add(String.Format(stddetails, "Customer ID", "Nama Depan", "Nama Belakang", "Pemesanan", "Tanggal Pemesanan", "Pembayaran", "Total"))
cmbpemesanan.Items.Add("Pilih Cara Pemesanan")
cmbpemesanan.Items.Add("Telepon")
cmbpemesanan.Items.Add("Ditempat")
cmbpemesanan.Items.Add("Pemesanan Online")
cmbpembayaran.Items.Add("Pilih Pembayaran")
cmbpembayaran.Items.Add("Cash")
cmbpembayaran.Items.Add("Master Card")
cmbpembayaran.Items.Add("Visa Card")
cmbpembayaran.Items.Add("Debit Langsung")
lstmerek.Items.Add("Indonesian")
lstmerek.Items.Add("Japanese")
lstmerek.Items.Add("Middle East")
lstmerek.Items.Add("European")
seafood.Checked = False
traditional.Checked = False
drinks.Checked = False
fullpack.Checked = False
rbsatu.Checked = False
rbdua.Checked = False
rbempat.Checked = False
rbdelapan.Checked = False
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Dim ikeluar As DialogResult
ikeluar = MessageBox.Show("Keluar dari menu?", "Food Order Menu", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ikeluar = DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
seafood.Checked = False
traditional.Checked = False
drinks.Checked = False
fullpack.Checked = False
rbsatu.Checked = False
rbdua.Checked = False
rbempat.Checked = False
rbdelapan.Checked = False
txtid.Clear()
txtnamabelakang.Clear()
txtnamadepan.Clear()
cmbpembayaran.Text = "Pilih Pembayaran"
cmbpemesanan.Text = "Pilih Cara Pemesanan"
lstoutput.Items.Clear()
lstmerek.SelectedItems.Clear()
lstoutput.Items.Add(String.Format(stddetails, "Customer ID", "Nama Depan", "Nama Belakang", "Pemesanan", "Tanggal Pemesanan", "Pembayaran", "Total"))
End Sub
Public Function getprices(ByVal brand As String, ByVal items As List(Of String), ByVal quantity As Integer) As Double
Dim prices = {
{"Indonesian", 2.5, 2, 0.95},
{"Japanese", 2.3, 1.5, 2.5},
{"Middle East", 3.5, 5, 4.9},
{"European", 3.8, 2.7, 1.5}
}
Dim sum As Double = 0
For i As Integer = 0 To 4
If (brand = prices(i, 0)) Then
For j As Integer = 0 To items.Count - 1
If (items(j) = "Seafood") Then
sum = sum + prices(i, 1)
ElseIf (items(j) = "Traditional") Then
sum = sum + prices(i, 2)
ElseIf (items(j) = "Drinks") Then
sum = sum + prices(i, 3)
End If
Next
sum = sum * quantity
End If
Next
Return sum
End Function
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim ID, namadepan, namabelakang, pemesanan, tanggal, pembayaran, price As String
ID = txtid.Text
namadepan = txtnamadepan.Text
namabelakang = txtnamabelakang.Text
pemesanan = cmbpemesanan.Text
tanggal = cmbtanggal.Text
pembayaran = cmbpembayaran.Text
Dim items As New List(Of String)
Dim quantity As Integer
If (seafood.Checked = True) Then
items.Add(seafood.Text)
End If
If (traditional.Checked = True) Then
items.Add(traditional.Text)
End If
If (drinks.Checked = True) Then
items.Add(drinks.Text)
End If
If (fullpack.Checked = True) Then
items.Add(fullpack.Text)
End If
If (rbsatu.Checked = True) Then
quantity = 1
ElseIf (rbdua.Checked = True) Then
quantity = 2
ElseIf (rbempat.Checked = True) Then
quantity = 4
ElseIf (rbdelapan.Checked = True) Then
quantity = 8
End If
If lstmerek.Text = "" Then
MessageBox.Show("Anda harus memilih jenis makanan.", "Jenis Makanan", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf (seafood.Checked = False And traditional.Checked = False And drinks.Checked = False) Then
MessageBox.Show("Anda harus memilih kategori.", "Kategori", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf (rbsatu.Checked = False And rbdua.Checked = False And rbempat.Checked = False And rbdelapan.Checked = False) Then
MessageBox.Show("Anda harus memilih jumlah.", "Jumlah Pesanan", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
price = FormatCurrency(getprices(lstmerek.Text, items, quantity))
lstoutput.Items.Add(String.Format(stddetails, ID, namadepan, namabelakang, pemesanan, tanggal, pembayaran, price))
End If
End Sub
Private Sub btntambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntambah.Click
seafood.Checked = False
traditional.Checked = False
drinks.Checked = False
fullpack.Checked = False
rbsatu.Checked = False
rbdua.Checked = False
rbempat.Checked = False
rbdelapan.Checked = False
txtid.Clear()
txtnamabelakang.Clear()
txtnamadepan.Clear()
cmbpembayaran.Text = "Pilih Pembayaran"
cmbpemesanan.Text = "Pilih Cara Pemesanan"
lstoutput.Items.Clear()
lstmerek.SelectedItems.Clear()
End Sub
结束Class
非常感谢任何帮助,谢谢。
第 2 行存在语法错误
您使用了“(”而不是“{”
替换
Dim stddetails As String = "{0, -20}{1, -20}{2, -20}{3, -20}(4, -20}{5, -20}{6, -20}"
和
Dim stddetails As String = "{0, -20}{1, -20}{2, -20}{3, -20}{4, -20}{5, -20}{6, -20}"
我正在尝试使用 format.string 将列插入列表框,但它似乎不起作用,"Input string was not in correct format" 它说。我 运行 没有办法解决这个问题,在 google 上找不到任何解决方案。所以我决定在这里问,顺便说一句,这是我的代码
Public Class Form1
Dim stddetails As String = "{0, -20}{1, -20}{2, -20}{3, -20}(4, -20}{5, -20}{6, -20}"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lstoutput.Items.Add(String.Format(stddetails, "Customer ID", "Nama Depan", "Nama Belakang", "Pemesanan", "Tanggal Pemesanan", "Pembayaran", "Total"))
cmbpemesanan.Items.Add("Pilih Cara Pemesanan")
cmbpemesanan.Items.Add("Telepon")
cmbpemesanan.Items.Add("Ditempat")
cmbpemesanan.Items.Add("Pemesanan Online")
cmbpembayaran.Items.Add("Pilih Pembayaran")
cmbpembayaran.Items.Add("Cash")
cmbpembayaran.Items.Add("Master Card")
cmbpembayaran.Items.Add("Visa Card")
cmbpembayaran.Items.Add("Debit Langsung")
lstmerek.Items.Add("Indonesian")
lstmerek.Items.Add("Japanese")
lstmerek.Items.Add("Middle East")
lstmerek.Items.Add("European")
seafood.Checked = False
traditional.Checked = False
drinks.Checked = False
fullpack.Checked = False
rbsatu.Checked = False
rbdua.Checked = False
rbempat.Checked = False
rbdelapan.Checked = False
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Dim ikeluar As DialogResult
ikeluar = MessageBox.Show("Keluar dari menu?", "Food Order Menu", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ikeluar = DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
seafood.Checked = False
traditional.Checked = False
drinks.Checked = False
fullpack.Checked = False
rbsatu.Checked = False
rbdua.Checked = False
rbempat.Checked = False
rbdelapan.Checked = False
txtid.Clear()
txtnamabelakang.Clear()
txtnamadepan.Clear()
cmbpembayaran.Text = "Pilih Pembayaran"
cmbpemesanan.Text = "Pilih Cara Pemesanan"
lstoutput.Items.Clear()
lstmerek.SelectedItems.Clear()
lstoutput.Items.Add(String.Format(stddetails, "Customer ID", "Nama Depan", "Nama Belakang", "Pemesanan", "Tanggal Pemesanan", "Pembayaran", "Total"))
End Sub
Public Function getprices(ByVal brand As String, ByVal items As List(Of String), ByVal quantity As Integer) As Double
Dim prices = {
{"Indonesian", 2.5, 2, 0.95},
{"Japanese", 2.3, 1.5, 2.5},
{"Middle East", 3.5, 5, 4.9},
{"European", 3.8, 2.7, 1.5}
}
Dim sum As Double = 0
For i As Integer = 0 To 4
If (brand = prices(i, 0)) Then
For j As Integer = 0 To items.Count - 1
If (items(j) = "Seafood") Then
sum = sum + prices(i, 1)
ElseIf (items(j) = "Traditional") Then
sum = sum + prices(i, 2)
ElseIf (items(j) = "Drinks") Then
sum = sum + prices(i, 3)
End If
Next
sum = sum * quantity
End If
Next
Return sum
End Function
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim ID, namadepan, namabelakang, pemesanan, tanggal, pembayaran, price As String
ID = txtid.Text
namadepan = txtnamadepan.Text
namabelakang = txtnamabelakang.Text
pemesanan = cmbpemesanan.Text
tanggal = cmbtanggal.Text
pembayaran = cmbpembayaran.Text
Dim items As New List(Of String)
Dim quantity As Integer
If (seafood.Checked = True) Then
items.Add(seafood.Text)
End If
If (traditional.Checked = True) Then
items.Add(traditional.Text)
End If
If (drinks.Checked = True) Then
items.Add(drinks.Text)
End If
If (fullpack.Checked = True) Then
items.Add(fullpack.Text)
End If
If (rbsatu.Checked = True) Then
quantity = 1
ElseIf (rbdua.Checked = True) Then
quantity = 2
ElseIf (rbempat.Checked = True) Then
quantity = 4
ElseIf (rbdelapan.Checked = True) Then
quantity = 8
End If
If lstmerek.Text = "" Then
MessageBox.Show("Anda harus memilih jenis makanan.", "Jenis Makanan", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf (seafood.Checked = False And traditional.Checked = False And drinks.Checked = False) Then
MessageBox.Show("Anda harus memilih kategori.", "Kategori", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf (rbsatu.Checked = False And rbdua.Checked = False And rbempat.Checked = False And rbdelapan.Checked = False) Then
MessageBox.Show("Anda harus memilih jumlah.", "Jumlah Pesanan", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
price = FormatCurrency(getprices(lstmerek.Text, items, quantity))
lstoutput.Items.Add(String.Format(stddetails, ID, namadepan, namabelakang, pemesanan, tanggal, pembayaran, price))
End If
End Sub
Private Sub btntambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntambah.Click
seafood.Checked = False
traditional.Checked = False
drinks.Checked = False
fullpack.Checked = False
rbsatu.Checked = False
rbdua.Checked = False
rbempat.Checked = False
rbdelapan.Checked = False
txtid.Clear()
txtnamabelakang.Clear()
txtnamadepan.Clear()
cmbpembayaran.Text = "Pilih Pembayaran"
cmbpemesanan.Text = "Pilih Cara Pemesanan"
lstoutput.Items.Clear()
lstmerek.SelectedItems.Clear()
End Sub
结束Class
非常感谢任何帮助,谢谢。
第 2 行存在语法错误
您使用了“(”而不是“{”
替换
Dim stddetails As String = "{0, -20}{1, -20}{2, -20}{3, -20}(4, -20}{5, -20}{6, -20}"
和
Dim stddetails As String = "{0, -20}{1, -20}{2, -20}{3, -20}{4, -20}{5, -20}{6, -20}"