PDA

View Full Version : چگونه می توان محتویات یک فایل نوشته با فرمت txt را در یک TextBox فراخوانی کرد؟



mmssoft
پنج شنبه 04 تیر 1388, 17:28 عصر
دوستان من یه سوالی داشتم که خیلی برام مهمه.
می خواستم بدونم چه طوری می شه محتویات یک فایل نوشته با فرمت txt رو در یک TextBox فراخوانی کرد؟

mmssoft
پنج شنبه 04 تیر 1388, 17:33 عصر
دوستان لطفا راهنمایی کنید. بازهم سوالم رو نطرح می کنم : چه طوری می شه محتویات یک فایل نوشته با فرمت txt رو در یک TextBox فراخوانی کرد؟

adinochestva
پنج شنبه 04 تیر 1388, 17:41 عصر
Dim sFileText as String
Dim iFileNo as Integer
iFileNo = FreeFile
'open the file for reading
Open "C:\Test.txt" For Input As #iFileNo
'change this filename to an existing file! (or run the example below first)

'read the file until we reach the end
Do While Not EOF(iFileNo)
Input #iFileNo, sFileText
'show the text (you will probably want to replace this line as appropriate to your program!)
MsgBox sFileText
Loop

'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo
(note: an alternative to Input # is Line Input # , which reads whole lines).

mmssoft
پنج شنبه 04 تیر 1388, 20:17 عصر
با تشکر از شما دوست عزیز ولی سورس شما در TextBox درست کار نمی کنه و فقط متون رو در MsgBox درست نشون میده. لطفا تصحیح کنید.

saeedzx
پنج شنبه 04 تیر 1388, 20:17 عصر
Dim intfnum As String
Dim intctr As String
intfnum = FreeFile
Open "c:\windows\system32\addressbank.txt" For Input As #intfnum
Do While Not EOF(intfnum)
Input #intfnum, intctr
t1.Text = intctr + "\nj.mdb"
Loop
Close #intfnum


اینم کدش سوال داشتی بگو

saeedzx
پنج شنبه 04 تیر 1388, 20:18 عصر
t1.text همون text1.text
و c:\windows\system32\addressbank.txt مسیر txt

saeedzx
پنج شنبه 04 تیر 1388, 20:22 عصر
Dim intfnum As String
Dim intctr As String
intfnum = FreeFile
Open "c:\jadougar.txt" For Input As #intfnum
Do While Not EOF(intfnum)
Input #intfnum, intctr
t1.Text = intctr
Loop
Close #intfnum

mmssoft
پنج شنبه 04 تیر 1388, 20:26 عصر
دوست عزیز آقای saeedzx جواب شما مفید بود ولی باز هم درست کار نمی کنه.
مثلا متن فایل من مثل تصویر زیر هست :

http://upload.iranblog.com/6/1245966204.gif

ولی با کدی که شما گفتین همین متن اینجوری تو TextBox به نمایش در میاد. مشکل چیه؟

http://upload.iranblog.com/6/1246024347.gif

لطفا راهنمایی کنید.

adinochestva
پنج شنبه 04 تیر 1388, 20:50 عصر
به جای MsgBox sFileText بزار که تو tbx بریزه

mmssoft
پنج شنبه 04 تیر 1388, 20:57 عصر
من کد زیر را برای Command وارد کردم ولی با توجه به نوشته فایل Text که در بالا نشان داده شده باز هم درست کا نمی کند. تصویر را ببیند.


Dim sFileText As String
Dim iFileNo As Integer
iFileNo = FreeFile
'open the file for reading
Open "C:\Test.txt" For Input As #iFileNo
'change this filename to an existing file! (or run the example below first)

'read the file until we reach the end
Do While Not EOF(iFileNo)
Input #iFileNo, sFileText
'show the text (you will probably want to replace this line as appropriate to your program!)
Text1.Text = sFileText
Loop

'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo



تصویر نوشته های درون فایل Text :

http://upload.iranblog.com/6/1246026690.gif

تصویر بعد از کلیک کردن رو دکمه :

http://upload.iranblog.com/6/1245977651.gif

لطفا راهنمایی کنید.

milad_spider
پنج شنبه 04 تیر 1388, 21:29 عصر
سلام


Open "C:\Test.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1

اینو برن 100 % جواب میده

xxxxx_xxxxx
پنج شنبه 04 تیر 1388, 21:48 عصر
يك ذره به همون خطي كه داده ها به Text منتقل ميشه نگاه كنيد متوجه ميشيد كه چرا اينطوري ميشه!


Dim sFileText As String
Dim iFileNo As Integer
iFileNo = FreeFile
'open the file for reading
Open "C:\Test.txt" For Input As #iFileNo
'change this filename to an existing file! (or run the example below first)

'read the file until we reach the end
Do While Not EOF(iFileNo)
Input #iFileNo, sFileText
'show the text (you will probably want to replace this line as appropriate to your program!)
Text1.Text = Text1.Text & vbCrLf & sFileText
Loop

'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo
البته اين كار توصيه نميشه (خط به خط خوندن فايل)

saeedzx
پنج شنبه 04 تیر 1388, 21:56 عصر
سلام
می دونم یک کد رو جا گذاشتم
این سورس رو دانلود کن کارت حله پسر


سورس (http://upload.iranblog.com/6/1245970904.rar)