vb怎麼讀取和修改tt文字檔案的內容

時間 2021-12-26 07:28:18

1樓:匿名使用者

private type aatype

a as string * 2

b as string * 2

c as string * 2

d as string * 2

end type

dim aa as aatype

dim bb as integer

private sub command1_click()

on error resume next ' resume重新開始; (經打斷後)再繼續

bb = inputbox("輸入記錄號", "插入資料")

if bb = 0 then exit sub

open "d:\aa.txt" for random as #1 len = len(aa)

tt = lof(1) / len(aa)

text5 = tt

for i = tt to bb step -1

get #1, i, aa

put #1, i + 1, aa

next

aa.a = text1.text

aa.b = text2.text

aa.c = text3.text

aa.d = text4.text

put #1, bb, aa

close #1

end sub

private sub command2_click()

on error resume next ' resume重新開始; (經打斷後)再繼續

bb = inputbox("輸入記錄號", "刪除資料")

if bb = 0 then exit sub

open "d:\aa.txt" for random as #1 len = len(aa)

tt = lof(1) / len(aa)

for i = bb to tt

get #1, i + 1, aa

put #1, i, aa

next

close #1

end sub

private sub command3_click()

on error resume next ' resume重新開始; (經打斷後)再繼續

bb = inputbox("輸入記錄號", "讀取資料")

if bb = 0 then exit sub

open "d:\aa.txt" for random as #1 len = len(aa)

tt = lof(1) / len(aa)

get #1, bb, aa

text1 = aa.a

text2 = aa.b

text3 = aa.c

text4 = aa.d

close #1

end sub

private sub command4_click()

on error resume next ' resume重新開始; (經打斷後)再繼續

bb = inputbox("輸入記錄號", "修改資料")

open "d:\aa.txt" for random as #1 len = len(aa)

aa.a = text1.text

aa.b = text2.text

aa.c = text3.text

aa.d = text4.text

put #1, lastrecord + bb, aa

close #1

end sub

private sub command5_click()

open "d:\aa.txt" for random as #1 len = len(aa)

tt = lof(1) / len(aa)

aa.a = text1.text

aa.b = text2.text

aa.c = text3.text

aa.d = text4.text

put #1, tt + 1, aa

close #1

end sub

private sub form_load()

text1 = ""

text2 = ""

text3 = ""

text4 = ""

end sub

我也是仿別人的做的.

2樓:

樓上說的已經很詳細了

vb 怎麼更改txt編碼格式和讀取txt指定字元

3樓:匿名使用者

vb可以通過createobject函式來實現開啟utf-8編碼格式文字檔案,將它顯示於文字框中。並可通過print # 語句將格式化顯示的資料以ansi格式寫入順序檔案中。

createobject函式,建立並返回乙個對 activex 物件的引用。

print # 語句,將格式化顯示的資料寫入順序檔案中。

以下是實現**:

private sub command1_click()

dim ados as object

dim str as string

commondialog1.filename = ""

commondialog1.filter = "文字檔案(*.txt)|*.txt|"

commondialog1.action = 1

str = commondialog1.filename

debug.print str

set ados = createobject("adodb.stream")

with ados

.charset = "utf-8"

.type = 2

.open

.loadfromfile str

text1.text = .readtext

.close

end with

debug.print mid(str, 1, len(str) - 4) & "1.txt"

open mid(str, 1, len(str) - 4) & "1.txt" for output as #1

print #1, text1.text

close #1

end sub

vb如何讀取txt中內容

4樓:匿名使用者

用api函式獲得使用者資料夾,這個我不曉得,我只會用獲取的使用者名稱來做...

下面的**,我並沒有限制使用者桌面上的txt檔案必須為「新建 文字文件.txt」,也就是滿足檔案裡有字串「1234」的txt檔案,就刪除。你可以自己調整一下,這樣就不需要filelistbox控制項了,如果只是針對你自己的電腦,這樣連api函式也不需要用上了,直接自己把資料夾路徑附上去。

在窗體上新增乙個timer控制項,乙個filelistbox控制項,timer1.interval=2000,file1.pattern="*.

txt",file1.visible=false,新增**如下:

private declare function getusername lib "advapi32.dll" alias "getusernamea" (byval lpbuffer as string, nsize as long) as long

dim username as string, userpath as string

private sub form_load()

'獲取當前使用者名稱

dim s as string * 255

call getusername(s, 255)

'提取出使用者名稱來

dim i as integer

for i = 1 to 255

'由於s長度為255,所以其中有一部分字元是無效字元(或者說是用於表徵字元結束)

if asc(mid(s, i, 1)) < 32 then

username = left(s, i - 1)

exit for

end if

next i

'設定使用者資料夾

'並不是所有使用者資料夾都是這樣的路徑,所以這行**沒有普遍性

userpath = "c:\documents and settings\" & username & "\桌面\"

'獲取滿足條件的檔案

file1.path = userpath

file1.refresh

end sub

private sub timer1_timer()

'獲取滿足條件的檔案

file1.refresh

'迴圈for i = 0 to file1.listcount - 1

'判斷檔案是否有符合條件的字串

if checktxt(userpath & file1.list(i)) then

'刪除檔案

kill userpath & file1.list(i)

end if

next i

end sub

private function checktxt(filepath as string) as boolean

dim fnum as integer, s as string, s1 as string

'讀取出檔案裡面的內容

fnum = freefile

open filepath for input as #fnum

do until eof(fnum)

line input #fnum, s1

s = s & s1 & vbcrlf

loop

close #fnum

'判斷檔案是否有符合條件的字串

if instr(s, "1234") > 0 then checktxt = true

end function

5樓:

open "檔案絕對路徑" for input as #1'接下來比如我要把檔案讀入文字框text1input #1, text1.text

close #1

也可以用fso,但是不可能一句命令就行的

6樓:匿名使用者

讀取:dim stringa as stringopen "(此處輸入txt路徑)" for input as #1input #1, stringa

close #1

text1.text = stringa

寫入:open "(此處輸入txt路徑)" for output as #1

input #1, text1.text

close #1

holihand原創,yzhiyu_123的不行,我試過了。

7樓:戈琰

樓上的還是寫漏了一點,我的最全

dim a as string

open "(此處輸入txt路徑+檔名)" for input as #1

input #1, a

close #1

text1.text = a

VB6 0如何讀取並修改XML檔案

宣告窗體全域性變數 dim oldip as string,p1 as long,p2 as long,xmlcontent as string dim newip as string private sub form load 讀取xml文件 dim fn,n as long fn freefil...

vb以二進位制讀取和寫入檔案,怎麼用vb6以二進位制讀寫檔案

為什麼你認為是像0,1這樣的?你用的是位元組陣列,陣列每個元素的值在0 255之間!寫的話用put,而不是write 怎麼用vb6以二進位制讀寫檔案 二進位制檔案並不是在檔案裡顯示1和0,那是兩回事。pirvate sub sub1 c data.exe 到 c data.txt open c da...

VB中怎麼讀取網頁檔案,並且逐行顯示在text中,與網頁

新增乙個command1,webbrowser1,richtextbox1.3個控制項 public function counter optional times as long on error resume next counter timer times 1000dodoevents if ...

C fopen和fgets怎麼用來讀取檔案,舉個例子謝謝

把檔名中的漢字去掉是最簡單的方法。你如果想用c 標準檔案流來讀漢字名檔案似乎不好實現,因為標準c 使用的是ansi字符集,其漢字的編碼方案好像為gb2312,而現在的系統中漢字一般使用unicode字符集,與ansi字符集的中文編碼方案不是同一種,所以無法識別。如果想要讀入含漢字檔名的檔案,最好是將...

怎麼把IC卡資料讀取出來修改,門禁卡IC晶元資料如何修改

不知道你用的是什麼讀寫器,一般情況,隨ic卡讀寫器,應該配送相應的api函式庫,可能是靜態的,也可能是動態的,你在程式設計的時候,將相應的.lib檔案,加入你的工程,再加入相應的標頭檔案 隨機的盤裡應該提供 如此,以可以直接呼叫該庫的函式,進行ic卡的讀寫。這是改ic卡密碼的函式,使用c語言寫的,應...