重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
這個簡單,我以前用VB6就寫過一個類似的程序。 不過這個程序需要提供命令行參數(shù)喲。
成都創(chuàng)新互聯(lián)成立以來不斷整合自身及行業(yè)資源、不斷突破觀念以使企業(yè)策略得到完善和成熟,建立了一套“以技術(shù)為基點,以客戶需求中心、市場為導(dǎo)向”的快速反應(yīng)體系。對公司的主營項目,如中高端企業(yè)網(wǎng)站企劃 / 設(shè)計、行業(yè) / 企業(yè)門戶設(shè)計推廣、行業(yè)門戶平臺運(yùn)營、成都App定制開發(fā)、移動網(wǎng)站建設(shè)、微信網(wǎng)站制作、軟件開發(fā)、綿陽電信機(jī)房機(jī)柜租用等實行標(biāo)準(zhǔn)化操作,讓客戶可以直觀的預(yù)知到從成都創(chuàng)新互聯(lián)可以獲得的服務(wù)效果。
就算用VB.NET編寫,也必須要有接收這個命令行參數(shù)的,不然無法實現(xiàn)顯示文件或文件夾路徑。
下面是注冊表文件的內(nèi)容,你也可以用程序來寫入注冊表。
*表示所有文件,你可以隨便修改。
最后面的%1,表示當(dāng)前文件或文件夾
REGEDIT4
[HKEY_CLASSES_ROOT\*\shell\顯示名稱]
[HKEY_CLASSES_ROOT\*\shell\顯示名稱\command]
@="D:\\綠色軟件\\編程\\VB\\顯示名稱\\顯示名稱.exe %1"
imports System.IO
讀取指定文件
'
'讀取指定文本文件
Public Function readtext(ByVal path As String)
If path = "" Then
readtext = "操作失?。?
Exit Function
End If
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim str As String
str = sr.ReadToEnd.ToString
sr.Close()
fs.Close()
readtext = str
Else
readtext = "操作失?。?
End If
Catch ex As Exception
readtext = "操作失??!"
End Try
End Function
'向指定文件寫入數(shù)據(jù)
Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)
If path = "" Then
writetext = "操作失敗!"
Exit Function
End If
Dim op As FileMode
Select Case opi
Case 1
op = FileMode.Append
Case 2
op = FileMode.Create
Case Else
op = FileMode.Create
End Select
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, op)
Dim sr As New StreamWriter(fs)
sr.WriteLine(msg)
sr.Close()
fs.Close()
writetext = "操作完成!"
Else
writetext = "操作失??!"
End If
Catch ex As Exception
writetext = "操作失敗!"
End Try
End Function
一、二進(jìn)制文件讀寫
1、寫二進(jìn)制數(shù)據(jù)到指定目錄
==將barray字節(jié)數(shù)組中的數(shù)據(jù)創(chuàng)建在strFilename目錄文件下,存儲格式為二進(jìn)制,F(xiàn)alse表示不添加,直接覆蓋創(chuàng)建。
2、從指定路徑下讀取二進(jìn)制數(shù)據(jù)到數(shù)組
==將目錄中的文件讀取到barry字節(jié)數(shù)組中,即讀取二進(jìn)制文件。
二、字符文件的讀寫
1、 將txtFile控件中的字符寫到srtFileName指定目錄,以創(chuàng)建方式。
2、從srtFileName目錄中的文件讀取到txtFile控件
1、新建一個標(biāo)準(zhǔn)的VB EXE工程,只有一個Form,F(xiàn)orm上有兩個按鈕:Command1和Command2。
2、雙擊Command1添加如下代碼
Private Sub Command1_Click()
Dim strFile? ? ?As String
Dim intFile? ? ?As Integer
Dim strData? ? ?As String
strFile = "c:\學(xué)生成績.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
End Sub
3、按F8開始單步調(diào)試代碼,點擊Command1,進(jìn)入單步調(diào)試功能,
4、多次按下F8或直接按下F5運(yùn)行完成,就完成了讀取文本文件內(nèi)容并輸出到立即窗口。