求一个读取 .txt 文件内容后小写字母转大写的程序
本帖最后由 free4537 于 2013-02-05 22:28:35 编辑 最好是 .txt 文件拖动到 VB 程序后就可以直接转换, 而不是还需要先选择文件然后等等.
好吧, 我承认我是伸手党... 曾学过 VB, 但当时学得不好而且学过的部分也忘记的差不多了, 手上还没有书. 即使这段时间学一个可视化编程语言的话, 也优先选 C#...
不过现在确实需要这么个小程序, 蛮实用的. 所以求个现成的, 记住了, 到哪无网, 不可使用外接存储设备但有 VB 开发环境的地方去把它写出来.
[解决办法]
Open "C:\1.txt" For Binary As #1
Text1.Text = UCase(Input(LOF(1), #1))
Close #1
[解决办法]
在窗口代码中加入以下代码,然后运行,把文件拖入窗口就可以了
Private Sub Form_Load()
Me.OLEDropMode = 1
End Sub
Private Sub Form_OLEDragDrop(Data As DataObject, _
Effect As Long, _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
If Data.GetFormat(vbCFFiles) = False Then
Effect = vbDropEffectNone
Exit Sub
End If
Effect = vbDropEffectMove
Dim i As Long, _
fd1 As Integer, _
fd2 As Integer, _
strTemp As String, _
strFName As String, _
strFPath As String
For i = 1 To Data.Files.Count
strFName = Dir(Data.Files.Item(i), vbHidden + vbReadOnly + vbSystem)
strFPath = Left(Data.Files.Item(i), Len(Data.Files.Item(i)) - Len(strFName))
Name strFPath & strFName As strFPath & strFName & ".bak"
fd1 = FreeFile
Open strFPath & strFName & ".bak" For Input As #fd1
fd2 = FreeFile
Open strFPath & strFName For Output As #fd2
Do While Not EOF(fd1)
Line Input #fd1, strTemp
Print #fd2, UCase(strTemp)
Loop
Close #fd2
Close #fd1
Kill strFPath & strFName & ".bak"
Next i
MsgBox "转换完成"
End Sub
Private Sub Form_OLEDragOver(Data As DataObject, _
Effect As Long, _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single, _
State As Integer)
If Data.GetFormat(vbCFFiles) = False Then
Effect = vbDropEffectNone
Exit Sub
End If
Effect = vbDropEffectMove
End Sub