VB.NET 数字字符串与数字的转换
0赞Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(1234)‘按行增加数据
ListBox1.Items.Add(2345)
ListBox1.Items.Add("刘珊")
ListBox1.Items.Add("女女")
' ListBox1.Items.Clear()’清除所有数据
ListBox1.Items.Add(4)
ListBox1.Items.Add(5)
ListBox1.Items.Add(6)
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedItem'选中listbox1 的数据,并在txt文档框显示
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim A As Integer, B As Integer
If TextBox2.Text.Length > 0 Then '判断是否有输入,如果没输入提示请输入数据
A = CInt(TextBox2.Text) * 6
B = TextBox2.Text * 6
MessageBox.Show(A)
Else
MessageBox.Show("请输入数据")
Exit Sub
End If
MessageBox.Show(B)
TextBox3.Text = 5
End Sub
End Class
文章重点在于表达 字符串与数字格式的转换
CDbl() 将字符串数字转换为Double类型的数字
CInt () 将字符串数字转换为Integer类型的数字
CStr() 将数字转换为数字的字符串