📄 v6j05-07.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "数组数据输入"
ClientHeight = 2865
ClientLeft = 60
ClientTop = 345
ClientWidth = 6255
LinkTopic = "Form1"
ScaleHeight = 2865
ScaleWidth = 6255
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "合并"
Height = 495
Left = 3480
TabIndex = 5
Top = 2040
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "分隔"
Height = 495
Left = 1200
TabIndex = 4
Top = 2040
Width = 1215
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1575
Left = 3840
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 360
Width = 1815
End
Begin VB.PictureBox Picture1
BackColor = &H80000009&
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1575
Left = 2280
ScaleHeight = 1515
ScaleWidth = 1275
TabIndex = 1
Top = 360
Width = 1335
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1575
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 360
Width = 2055
End
Begin VB.Label Label3
Caption = "合并"
Height = 375
Left = 3960
TabIndex = 7
Top = 120
Width = 1215
End
Begin VB.Label Label2
Caption = "图形框"
Height = 255
Left = 2400
TabIndex = 6
Top = 120
Width = 1215
End
Begin VB.Label Label1
Caption = "输入数字串"
Height = 375
Left = 240
TabIndex = 2
Top = 120
Width = 1335
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a() As String
'Private Sub Command1_Click()
' Dim temp As String
' Dim i As Integer
' temp = Replace(Text1, ",,", ",") ' 去除出现的连续分隔符
' a = Split(temp, ",") ' 将文本框内内容按逗号为分隔符分离,结果放入a字符数组中
' For i = 0 To UBound(a) ' 在图形框显示分离的各元素
' Picture1.Print a(i)
' Next i
'End Sub
Private Sub Command2_Click() ' 将数组a中各元素合并,以空格为分隔符放入Text2中
Text2 = Join(a, " ")
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim Lenstra As Integer, j As Integer
Dim Stra As String, S As String * 1
S = Chr(KeyAscii)
Select Case S
Case "0" To "9", ",", ".", "-"
' 0~9,逗号,负号,小数点 为有效数字串,可以继续输入
Case Else
' 输入非数字字符,去除非法字符,再输入"
KeyAscii = 0
End Select
End Sub
' 方法一内容按逗号为分隔符逐一分离,结果放入a字符数组中,并在图形框显示
Private Sub Command1_Click()
Dim i%
Stra = Text1
Lenstra = Len(Stra)
j = InStr(Stra, ",")
Do While j > 0 ' 以逗号为分界符
ReDim Preserve a(i)
a(i) = Val(Left(Stra, j - 1)) '分离出的数据项存入数组
Stra = Mid(Stra, j + 1) ' 取其余数字串再分离
i = i + 1
j = InStr(Stra, ",")
Loop
ReDim Preserve a(i)
a(i) = Val(Stra) ' 最后一项
For j = 0 To i ' 打印数组
Picture1.Print a(j)
Next j
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -