text file in visual basic

reading and writing to text file

Page 1 of 1

12 Replies - 6236 Views - Last Post: 26 August 2010 - 11:21 PM Rate Topic: -----

#1 Guest_sanjana*


Reputation:

text file in visual basic

Posted 23 August 2010 - 04:08 AM

hello

I just joined as a programmer and i need to program in visual basic 6.0. it is actually an easy programming language but since i am new to it, i am encountering some difficulties.
I have a text file and i need to read it and place delimiters between the words until i reach the word JUNE2010.
I know how to open the text file but i just dont know how to continue.The algorithm seems simple though.
1. open text file
2.read text file
3.Place delimiter
4.Stop when reach 'JUNE2010'

I will appreciate any kind of help.
thxx

Is This A Good Question/Topic? 0

Replies To: text file in visual basic

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,224
  • Joined: 23-August 08

Re: text file in visual basic

Posted 23 August 2010 - 04:27 AM

If you have the algorithm, then you just need to write the code! If you're expecting us to do that for you, we will not, as per the rules:

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.

If you have code you need help with, then please post it (in code tags) along with the questions you have and/or the exact errors you're receiving.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_sanjana*


Reputation:

Re: text file in visual basic

Posted 23 August 2010 - 04:34 AM

Private Sub Command1_Click()
Dim x
Dim oneLetter

Set objfso = CreateObject("Scripting.FileSystemObject")

Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long
' Get a free file number
nFileNum = FreeFile

' Open a text file for input. inputbox returns the path to read the file
Open "test2.txt" For Input As nFileNum
'Open "tempF.txt" For Input As 2
Set tempFile = objfso.createtextfile(App.Path & "\tempF.txt")
lLineCount = 1
' Read the contents of the file
Do While Not EOF(nFileNum)
   Line Input #nFileNum, sNextLine
   'do something with it
   'add line numbers to it, in this case!
    sNextLine = Pack(sNextLine)
    sNextLine = Trim(sNextLine) & vbCrLf
   
   'sNextLine = Value(Trim(sNextLine))
   'sNextLine = Replace(sNextLine, " ", "")
 '  sText = sText & sNextLine
   'Print sNextLine
  ' Text1.Text = sNextLine
     For x = 1 To Len(sNextLine)
        oneLetter = Mid(sNextLine, x, 1)
        
        If Asc(oneLetter) = 9 Then
            oneLetter = ","
        ElseIf Asc(oneLetter) = 32 Then
                oneLetter = "##**##"
        ElseIf Asc(oneLetter) = 32 Then
                oneLetter = Replace(oneLetter, " ", "")
                
        End If
        
        DoEvents
        Newstring = Newstring & oneLetter
    Next x

   DoEvents
   
Loop
 tempFile.writeline (Newstring)

    tempFile.Close
    Set tempFile = Nothing
'Text1.Text = sText

' Close the file
Close nFileNum

Unload Me
End Sub


this is the code i have implemented so far
Was This Post Helpful? 0

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,224
  • Joined: 23-August 08

Re: text file in visual basic

Posted 23 August 2010 - 04:36 AM

And again, what are the problems/errors you are receiving???
Was This Post Helpful? 0
  • +
  • -

#5 Guest_sanjana*


Reputation:

Re: text file in visual basic

Posted 23 August 2010 - 04:47 AM

the program stops to respond when i click on the command button.i need to close everything.
this is the problem i am encountering.
Was This Post Helpful? 0

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: text file in visual basic

Posted 23 August 2010 - 04:56 AM

do you try debugging ? to see where is the problem
Was This Post Helpful? 0
  • +
  • -

#7 Guest_sanjana*


Reputation:

Re: text file in visual basic

Posted 23 August 2010 - 05:12 AM

when can i expect a reply? its urgent
Was This Post Helpful? 0

#8 Guest_sanjana*


Reputation:

Re: text file in visual basic

Posted 23 August 2010 - 05:17 AM

i did try debug but since no msgbox appears i cannot do much. as i told you the the program stops to respond.

anyways thx for 5as well
Was This Post Helpful? 0

#9 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: text file in visual basic

Posted 23 August 2010 - 05:55 AM

at what line it stop to respond?
Was This Post Helpful? 0
  • +
  • -

#10 Guest_sanjana*


Reputation:

Re: text file in visual basic

Posted 23 August 2010 - 09:48 PM

the program stops to respond when i click on the command button
Was This Post Helpful? 0

#11 Guest_sanjana*


Reputation:

Re: text file in visual basic

Posted 24 August 2010 - 11:04 PM

As per the policy of dreamincode i did provide the code i worked on but i haven't received any reply yet.
Was This Post Helpful? 0

#12 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: text file in visual basic

Posted 25 August 2010 - 10:12 AM

this might help:

#Pack is not an available function in VB
#Supply full path of the text file you want to open

try this


Dim x As Integer
Dim oneLetter As String
Dim objFSO As Scripting.FileSystemObject
Dim tempfile As Object
Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long


Set objFSO = New Scripting.FileSystemObject
Set tempfile = objFSO.CreateTextFile("C:\TEMP\tempF.txt")

'Assigning Values
nFileNum = FreeFile
lLineCount = 1

' Open a text file for input
        Open "C:\TEMP\temp.txt" For Input As nFileNum

' Read the contents of the file
        Do While Not EOF(nFileNum)
            Line Input #nFileNum, sNextLine
            'sNextLine = Pack(sNextLine) *Pack is not available in VB so _
            you might wanna replace this with an appropriate function
            sNextLine = Trim(sNextLine) & vbCrLf
            
        For x = 1 To Len(sNextLine)
            oneLetter = Mid(sNextLine, x, 1)
            If Asc(oneLetter) = 9 Then
                oneLetter = ","
            ElseIf Asc(oneLetter) = 32 Then
                oneLetter = "##**##"
            ElseIf Asc(oneLetter) = 32 Then
                oneLetter = Replace(oneLetter, " ", "")
            End If
            
        DoEvents
        Newstring = Newstring & oneLetter
        Next x

DoEvents
Loop

tempfile.writeline (Newstring)
tempfile.Close
Set tempfile = Nothing
Set objFSO = Nothing

' Close the file
Close nFileNum


Was This Post Helpful? 0
  • +
  • -

#13 Guest_Guest*


Reputation:

Re: text file in visual basic

Posted 26 August 2010 - 11:21 PM

thanks loads for the solution.
Was This Post Helpful? 0

Page 1 of 1