谢谢!
太感激了!
要认你做老大!
Private Sub CmdApply_Click()
Dim Text1 As String
Dim Text2 As String
Dim Text3 As String
Dim Text4 As String
Dim Text5 As String
Dim Text6 As String
Dim Text8 As String
Dim Text9 As String
Text1 = "<SIP CONFIG MODULE>"
Text2 = "SIP Port :" & TextLocalSIPPort.Text
Text3 = "Stun Address :" & TextSTUNServerAddr.Text
Text4 = "Stun Port :" & TextSTUNServerPort.Text
Text5 = "Stun Effect Time :" & TextSTUNEffectTime.Text
Text6 = "--SIP Line List-- :"
Text8 = "SIP1 Use Stun :" & CheckUseStun.Value
Text9 = "SIP2 Use Stun :" & CheckUseStun1.Value
'text2的替换模块
Dim FileNum As Long
Dim StrLine As String
Dim StrFileContent As String
Dim target As String
'获取用户输入的要查找的字符串
target = "SIP Port :"
FileNum = FreeFile
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target) > 0 Then StrLine = Text2: target = "Slore"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target <> "Slore" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text1
Print #FileNum, Text2
End If
Close #FileNum
'text3的替换模块
Dim StrFileContent1 As String
Dim target1 As String
'获取用户输入的要查找的字符串
target1 = "Stun Address :"
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target) > 0 Then StrLine = Text3: target1 = "Slore1"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target1 <> "Slore1" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text3
End If
Close #FileNum
Unload Stun
End Sub
我想拓展可就是不行,反而把前面的都搞错了!
帮我看看行不?真不想麻烦你,可是我实在是没办法,你谅解下哈
Private Sub CmdApply_Click()
Dim Text1 As String
Dim Text2 As String
Dim Text3 As String
Dim Text4 As String
Dim Text5 As String
Dim Text6 As String
Dim Text8 As String
Dim Text9 As String
Text1 = "<SIP CONFIG MODULE>"
Text2 = "SIP Port :" & TextLocalSIPPort.Text
Text3 = "Stun Address :" & TextSTUNServerAddr.Text
Text4 = "Stun Port :" & TextSTUNServerPort.Text
Text5 = "Stun Effect Time :" & TextSTUNEffectTime.Text
Text6 = "--SIP Line List-- :"
Text8 = "SIP1 Use Stun :" & CheckUseStun.Value
Text9 = "SIP2 Use Stun :" & CheckUseStun1.Value
'text2的替换模块
Dim FileNum As Long
Dim StrLine As String
Dim StrFileContent As String
Dim target As String
'获取用户输入的要查找的字符串
target = "SIP Port :"
FileNum = FreeFile
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target) > 0 Then StrLine = Text2: target = "Slore"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target <> "Slore" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text1
Print #FileNum, Text2
End If
Close #FileNum
'text3的替换模块
Dim target1 As String
'获取用户输入的要查找的字符串
target1 = "Stun Address :"
Open ".\Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If InStr(StrLine, target1) > 0 Then StrLine = Text3: target1 = "Slore1"
StrFileContent = StrFileContent & StrLine & vbCrLf
Loop
Close #FileNum
Open ".\Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent
Close #FileNum
If target1 <> "Slore1" Then '没有找到了匹配字符串
Open ".\config.txt" For Append As #FileNum
Print #FileNum, Text3
End If
Close #FileNum
Unload Stun
End Sub
修改了下最明显的错误,但结果还是一样!
Private Sub CmdApply_Click()
Dim Text1 As String
Dim Text2 As String
Dim Text3 As String
Dim Text4 As String
Dim Text5 As String
Dim Text6 As String
Dim Text8 As String
Dim Text9 As String
Text1 = "<SIP CONFIG MODULE>"
Text2 = "SIP Port :" & TextLocalSIPPort.Text
Text3 = "Stun Address :" & TextSTUNServerAddr.Text
Text4 = "Stun Port :" & TextSTUNServerPort.Text
Text5 = "Stun Effect Time :" & TextSTUNEffectTime.Text
Text6 = "--SIP Line List-- :"
Text8 = "SIP1 Use Stun :" & CheckUseStun.Value
Text9 = "SIP2 Use Stun :" & CheckUseStun1.Value
'Call ADDData("SIP Port :", Text2)
'Call ADDData("Stun Address :", Text3)
'Unload Stun
'End Sub
'Private Sub ADDData(target As String, NewStr As String)
Dim FileNum As Long
Dim StrLine As String
Dim StrFileContent As String
'-----------------------------
'-----------------------------
'-----------------------------
Dim target As String
Dim target1 As String
target = "SIP Port :" '多个目标在这里添加
target1 = "Stun Address :" '因为看你的项目不多,所以直接代码添加本来写成过程的……还有数组什么的……
'-----------------------------
'-----------------------------
'-----------------------------
FileNum = FreeFile
Open "Config.txt" For Input As #FileNum
Do Until EOF(FileNum)
Line Input #FileNum, StrLine
If StrLine <> "" Then
'在这里过滤就可以了……不要全部重新多遍……本来写成Sub了,要和上面对应
'-----------------------------
'-----------------------------
'-----------------------------
If InStr(StrLine, target) > 0 Then StrLine = Text2: target = "Slore"
If InStr(StrLine, target1) > 0 Then StrLine = Text3: target1 = "Slore1"
'-----------------------------
'-----------------------------
'-----------------------------
StrFileContent = StrFileContent & StrLine & vbCrLf '这里的缘故所以每在最后会多一个空行
End If
Loop
Close #FileNum
If StrFileContent <> "" Then '如果不是空文件
'在写如前,我们把最后的换行回车符号去掉
StrFileContent = Left$(StrFileContent, Len(StrFileContent) - 2)
Open "Config.txt" For Output As #FileNum
Print #FileNum, StrFileContent '好像print写入最后是有个空回车
Close #FileNum
End If
Open "config.txt" For Append As #FileNum
If target <> "Slore" Then '没有找到了匹配字符串
Print #FileNum, Text1
Print #FileNum, Text2
End If
If target1 <> "Slore1" Then '没有找到了匹配字符串
Print #FileNum, Text3
End If
Close #FileNum
'End Sub
Unload Stun
End Sub
发现print写是会有一个空行的。你看下这个吧。只有最后的一个空换行
对了open还是写完整路径,不然类似快捷方式等打开会找不到Config.txt