Vb6 radomly将字符串添加到我的代码中

Vb6 radomly将字符串添加到我的代码中,vb6,Vb6,text1.text=“梅威瑟vs麦格雷戈:洛杉矶新闻发布会” text返回空间的计数 我的习惯价值观是:“爱” 现在,在每次单击按钮时,我想随机将该自定义字符串添加到空间的每个位置 所以首先点击 text1.text=“梅威瑟vs洛夫·麦格雷戈:洛杉矶新闻发布会” 第二次点击 text1.text=“梅威瑟vs麦格雷戈:;爱洛杉矶新闻发布会” 根据代码的不同,它检测到空间,然后每次单击只添加一次 Code: Dim Count As Integer Dim i As Integer

text1.text=“梅威瑟vs麦格雷戈:洛杉矶新闻发布会” text返回空间的计数

我的习惯价值观是:“爱”

现在,在每次单击按钮时,我想随机将该自定义字符串添加到空间的每个位置

所以首先点击 text1.text=“梅威瑟vs洛夫·麦格雷戈:洛杉矶新闻发布会”

第二次点击 text1.text=“梅威瑟vs麦格雷戈:;爱洛杉矶新闻发布会”

根据代码的不同,它检测到空间,然后每次单击只添加一次

Code:

Dim Count As Integer
    Dim i As Integer
    For i = 1 To Len(Text1.Text)
        If Mid(Text1.Text, i, 1) = " " Then Count = Count + 1
        Text2.Text = Count
    Next

下面是一个小测试项目:

Option Explicit
' 1 form with:
'    2 textbox controls: name=Text1 and name=Text2
'    1 command button  : name=Command1

Private mstrText As String

Private Sub Command1_Click()
  Static intCount As Integer 'declare as static to remember value of intCount on next click
  Dim intLoop As Integer
  Dim intSpace As Integer
  intCount = intCount + 1
  'find correct space
  intLoop = 0
  intSpace = 0
  Do While intLoop < intCount
    intSpace = InStr(intSpace + 1, mstrText, " ")
    intLoop = intLoop + 1
  Loop
  Text1.Text = Left$(mstrText, intSpace) & "love " & Mid$(mstrText, intSpace + 1)
  Caption = CStr(intSpace)
End Sub

Private Sub Form_Load()
  mstrText = "Mayweather vs McGregor: Los Angeles Press Conference"
  Text1.Text = mstrText
End Sub

Private Sub Text1_Change()
  'show number of spaces
  Dim intSpace As Integer
  intSpace = Len(Text1.Text) - Len(Replace(Text1.Text, " ", ""))
  Text2.Text = CStr(intSpace)
End Sub
选项显式
“1表格,附:
'2文本框控件:name=Text1和name=Text2
'1命令按钮:name=Command1
私有mstrText作为字符串
专用子命令1_Click()
Static intCount As Integer'声明为Static,以便在下次单击时记住intCount的值
作为整数的Dim intLoop
整数形式的整数空间
intCount=intCount+1
“找到正确的空间
intLoop=0
intSpace=0
当intLoop

这就是你的意思吗?

这不是一个教程网站。您需要尝试解决自己的问题,并显示与问题不一起工作的代码。请阅读并采取行动