用VB怎么编写修改文件的程序? 5
用VB怎么编写修改文件的程序?比如点击按钮一实现功能:把C盘下的1.txt改为1.jpg然后重启电脑~点击按钮二实现功能:把C盘下的1.jpg改为1.txt然后重启电脑~...
用VB怎么编写修改文件的程序?
比如 点击 按钮一 实现功能:把C盘下的1.txt 改为 1.jpg 然后重启电脑~
点击 按钮二 实现功能:把C盘下的1.jpg改为 1.txt 然后重启电脑~
点击 按钮三 实现功能:退出程序~!
O(∩_∩)O谢谢~! 刚接触VB。不懂,请高手指点~! 展开
比如 点击 按钮一 实现功能:把C盘下的1.txt 改为 1.jpg 然后重启电脑~
点击 按钮二 实现功能:把C盘下的1.jpg改为 1.txt 然后重启电脑~
点击 按钮三 实现功能:退出程序~!
O(∩_∩)O谢谢~! 刚接触VB。不懂,请高手指点~! 展开
4个回答
展开全部
Private Sub Command1_Click() '名为Command1的单击事件
Name "C:\1.txt" As "C:\1.jpg" '改变原路径文件 C:\1.txt 为 C:\1.jpg
Shell "shutdown -r -t 0" '运行“shutdown.exe ”的“shutdown -r -t 0”命令, -t 0 是参数,0秒后重启的意思 ,-r 为重启的参数 (-s 是关机)
End Sub '事件结束
Private Sub Command2_Click() '同上,名称不同而已
Name "C:\1.jpg" As "C:\1.txt"
Shell "shutdown -r -t 0"
End Sub '事件结束
Private Sub Command3_Click() '还是单击事件
End '结束程序
End Sub
仔细看 应该能看出 qw623577789 有点问题…… 控件名称是不能重复的,所以也就不可能出现两个 Command1_Click
应该是问题太简单, 他疏忽了
初学这样就可以了…… 简单易懂
Name "C:\1.txt" As "C:\1.jpg" '改变原路径文件 C:\1.txt 为 C:\1.jpg
Shell "shutdown -r -t 0" '运行“shutdown.exe ”的“shutdown -r -t 0”命令, -t 0 是参数,0秒后重启的意思 ,-r 为重启的参数 (-s 是关机)
End Sub '事件结束
Private Sub Command2_Click() '同上,名称不同而已
Name "C:\1.jpg" As "C:\1.txt"
Shell "shutdown -r -t 0"
End Sub '事件结束
Private Sub Command3_Click() '还是单击事件
End '结束程序
End Sub
仔细看 应该能看出 qw623577789 有点问题…… 控件名称是不能重复的,所以也就不可能出现两个 Command1_Click
应该是问题太简单, 他疏忽了
初学这样就可以了…… 简单易懂
展开全部
先加3个command ,在复制下面代码
Private Sub Command1_Click()
Call Kill("c:\1.txt")
Open "c:\1.jpg" For Output As #1
Close #1
Shell "shutdown -r -t 0"
End Sub
Private Sub Command2_Click()
Call Kill("c:\1.jpg")
Open "c:\1.txt" For Output As #2
Close #2
Shell "shutdown -r -t 0"
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Command1_Click()
Call Kill("c:\1.txt")
Open "c:\1.jpg" For Output As #1
Close #1
Shell "shutdown -r -t 0"
End Sub
Private Sub Command2_Click()
Call Kill("c:\1.jpg")
Open "c:\1.txt" For Output As #2
Close #2
Shell "shutdown -r -t 0"
End Sub
Private Sub Command3_Click()
End
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Name "c:\1.txt" As "d:\1.jpg"
Shell "shutdown -r -f"
End Sub
Private Sub Command2_Click()
Name "c:\1.jpg" As "d:\1.txt"
Shell "shutdown -r -f"
End Sub
Private Sub Command1_Click()
End
End Sub
Name "c:\1.txt" As "d:\1.jpg"
Shell "shutdown -r -f"
End Sub
Private Sub Command2_Click()
Name "c:\1.jpg" As "d:\1.txt"
Shell "shutdown -r -f"
End Sub
Private Sub Command1_Click()
End
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
声明:
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal lSize As Long, ByVal lpFilename As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As Any, ByVal lpKeyName As Any, ByVal lpString As String, ByVal lplFilename As String) As Long
Public Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFilename As String) As Long
写INI:
WritePrivateProfileString "Main", "Active", "-1", "INI文件保存地址"
效果: (可以替换原有值)
[Main]
Active=-1
'=============================================================
读INI:
ReadIniFile(UpdateIniPath, "Main", "Active", "0")
效果:
-1
在所有代码后加函数:
Public Function ReadIniFile(ByVal strIniFile As String, ByVal strSection As String, ByVal strKey As String, Optional ByVal strKeyDefault As String = vbNullString) As String
Dim strBuffer As String
strBuffer = Space$(gintMAX_SIZE)
If GetPrivateProfileString(strSection, strKey, strKeyDefault, strBuffer, gintMAX_SIZE, strIniFile) Then
ReadIniFile = StringFromBuffer(strBuffer)
End If
End Function
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal lSize As Long, ByVal lpFilename As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As Any, ByVal lpKeyName As Any, ByVal lpString As String, ByVal lplFilename As String) As Long
Public Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFilename As String) As Long
写INI:
WritePrivateProfileString "Main", "Active", "-1", "INI文件保存地址"
效果: (可以替换原有值)
[Main]
Active=-1
'=============================================================
读INI:
ReadIniFile(UpdateIniPath, "Main", "Active", "0")
效果:
-1
在所有代码后加函数:
Public Function ReadIniFile(ByVal strIniFile As String, ByVal strSection As String, ByVal strKey As String, Optional ByVal strKeyDefault As String = vbNullString) As String
Dim strBuffer As String
strBuffer = Space$(gintMAX_SIZE)
If GetPrivateProfileString(strSection, strKey, strKeyDefault, strBuffer, gintMAX_SIZE, strIniFile) Then
ReadIniFile = StringFromBuffer(strBuffer)
End If
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询