我是VB菜鸟,新手,请大虾多多指教!
我希望这样实现:
有一文本text.txt
点CMD按钮就查询text.txt的字符"abc",然后替换成"efg"
存盘退出~
我应该怎么做?
请大家帮忙,Wait online!

解决方案 »

  1.   

    Private Sub Commchange_Click()
       
      If munx = False Then
       If MatchCase = True Then
         findnt = InStr(findnt + 1, Form1.Text1.Text, Text1.Text)
       Else
         findnt = InStr(findnt + 1, Form1.Text1.Text, Text1.Text, 1)
       End If
       If findnt <> 0 Then
         Form1.Text1.SelStart = findnt - 1
         Form1.Text1.SelLength = Len(Text1.Text)
       Else
         MsgBox "没有找到" & Chr$(34) & Text1.Text & Chr$(34)
       End If
      End If    If findnt <> 0 Then
          Form1.Text1.SelText = Text2.Text
        End If
     End Sub
    这是我编的一替换功能....
      

  2.   

    因為這關系到文件操作,我使用以下辦法,在form中畫一個text和command.再首先設置text1屬性
    text1.scrollbars=2
    text1.multiline=true
    之後寫入以下代碼
    Option Explicit
    Private Sub Command1_Click()
    Dim fil As Integer
    Dim inputdata
    fil = FreeFile()
    Text1.Text = Replace(Text1.Text, "abc", "efg")
    Open App.Path + "\text.txt" For Output As #fil
    Print #fil, Text1
    Close #fil
    End SubPrivate Sub Form_Load()
    Text1.Text = ""
    Dim fil As Integer
    Dim inputdata
    fil = FreeFile()
    Open App.Path + "\text.txt" For Input As #filDo While Not EOF(fil)
        Line Input #fil, inputdata
        Text1.Text = Text1.Text + inputdata
    Loop
    Close #filEnd Sub
    快放分吧!