下面是一个例子,窗体中需要一个按钮控件,一个控件:
程序代码:
Private Sub Command1_Click() Dim i As Integer Dim TmpStr As String Dim str1() As String Dim str2() As String TmpStr = "*1.A:123,*2.B:234,*3.C:345,*4.D:456" '首先将字符串赋值给一个变量 str1 = Split(TmpStr, ",") '将以,为标记分割后的字符串数组赋值给数组变量str1 With MSFlexGrid1 '下面的四个属性也可以在设计时设定 .Rows = 3 .Cols = 5 .FixedCols = 1 .FixedRows = 1 For i = 0 To UBound(str1) str2() = Split(str1(i), ":") '将以:为标记分割后的字符串数组赋值给数组变量str2 .TextMatrix(0, i + 1) = Replace(str2(0), "*", "") '去除*号 .TextMatrix(1, i + 1) = str2(1) Next End With End Sub
===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================