View Full Version : خواندن فایل text با vb و ذخیره خروجی در یه text (فوری)
  
yasssalm
پنج شنبه 13 اسفند 1388, 19:06 عصر
سلام به تمام دوستان
من یه فایل exe دارم که ورودی را از vb توی یک فایل text دریافت میکنه و خروجی exe هم فایل text هستش که توسط vb باید خوانده و نمایش داده بشه. من نمی تونم text ورودی و خروجی را با vb ارتباط بدم.ممنون میشم کمکم کنید.
sajjad_india
پنج شنبه 13 اسفند 1388, 19:54 عصر
این واسه خوندن فایل هستش یا لود کردن خط به خط و همه محتویات فایل : 
فقط خودت ویرایش کن 
Sub loodfile()
 Text1.Text = ""
    Dim iFile As Integer
   Dim sCDKeys() As String
   Dim iItem As Integer
   
   'Instead of hardcoding a file number (12 in your case)
   'use Freefile to ask VB which numbers are available
   iFile = FreeFile
   
   'Notice I've changed your path, so I can test the code
   Open "kala.txt" For Input As iFile
   
   'Read the entire file and break it all up into
   'an array in one line of code
   sCDKeys = Split(Input$(LOF(iFile), iFile), vbCrLf)
   
   'Close the file
   Close iFile
   'Now, fill the combo and get outta here
   With List1
          .Clear 'get rid of anything currently loaded
          'Loop thru the array, adding as we go
          For iItem = 0 To UBound(sCDKeys)
                 If Len(sCDKeys(iItem)) > 0 Then 'no blanks allowed
                        .AddItem sCDKeys(iItem)
                 End If
          Next
          
          'Now, select the first item in the combo
          If .ListCount > 0 Then
                 .ListIndex = 0
          End If
          
   End With
End Sub
ذخیره فایل : 
Dim a, str1 As String
str1 = Text1.Text
Open "kala.txt" For Input As #1
k = 0
    Do While Not EOF(1)
    Input #1, a
    
     k = k + 1
    If k = 1 Then
         str1 = str1 & vbNewLine & a
        Else
         str1 = str1 & vbNewLine & a
         End If
    Loop
Close #1
Open "kala.txt" For Output As #1
Print #1, str1
Close #1
MsgBox "˜ÇáÇí ãæÑÏ äÙÑ Èå áíÓÊ ÇÖÇÝå ÔÏ", , "Mobile Service"
Text1.Text = ""
loodfile
Text1.SetFocus
kimprog
جمعه 14 اسفند 1388, 12:49 عصر
از منوي رفرنس در پروجكت  ايتم "Microsoft Scripting Runtime" را انتخاب كنيد ، حالا شما ميتوانيد ازامكانات "File System Object" در برنامه تان استفاده كنيد  از جمله كار با فايلهاي TXT ....
Sub Read_Files()
    Dim fso As New FileSystemObject, txtfile, _
      fil1 As File, ts As TextStream
    fso.CreateTextFile "c:\testfile.txt", True
    MsgBox "Writing file"
    ' Write a line.
    Set fil1 = fso.GetFile("c:\testfile.txt")
    Set ts = fil1.OpenAsTextStream(ForWriting)
    ts.Write "Hello World"
    ts.Close
    ' Read the contents of the file.
    Set ts = fil1.OpenAsTextStream(ForReading)
    s = ts.ReadLine
    MsgBox s
    ts.Close
End Sub
مثال از MSDN بود.
pooya1072
جمعه 14 اسفند 1388, 13:56 عصر
دوست عزيز...سوالت يه كم مبهمه
فايل exe قراره از vb متن بگيره؟
يا من متوجه نميشم يا منظورت اينه كه فايل exe مي خواد از يه فايل exe ديگه كه با vb درستش كردي اطلاعت بگيره.اگه اينطوره كه بگو تا راه حلش رو بهت بگم.
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.