borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (No forum activity) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Reading modifing text files
Poster Message
ranosb
Level: Protégé

Registered: 10-04-2008
Posts: 5

icon Reading modifing text files

First off I'd like to point out to MODS that registration canno't be completed by inputing the security code, it will say its wrong everytime. U have to leave it blank to register...
NEXT:

Was trying to use Javascript to open windows from links in a text file but found out JS does not read or modify text files.

So I need a project for opening a text file of links, and adding text before and after the links and saving that file or outputting the result into a new text file...

Any helpers out there?
Thanks to all that help!

10-04-2008 at 04:11 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 549
icon Re: Reading modifing text files

You are right!!!

thanks for letting us know...since our ISP upgraded to a new server it seems that this feature is not working anymore, I'll try to fint it as soon as I can!

thanks a lot!

____________________________
AndreaVB

10-04-2008 at 06:20 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 549
icon Re: Reading modifing text files

It seems to be fixed now! maybe this was causing some people not to register to our forum...

thank you for letting us know!

    

____________________________
AndreaVB

10-04-2008 at 06:42 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ranosb
Level: Protégé

Registered: 10-04-2008
Posts: 5
icon Re: Reading modifing text files

Glad I could be of help,
Now would anybody help me with my question posted?

10-04-2008 at 07:31 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 549
icon Re: Reading modifing text files

How is formatted your text file? is it in HTML or a simple list of links one for each line? what text do you want to add after and before the links? should it be a static text for each link? please provide us with as many informations as you can...

with VB6 it is possible to load the entire file in a string then manipulate it and save it back to a text file

An example of reading a file:

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).


An example of writing a file:

Dim sFileText as String
Dim iFileNo as Integer
iFileNo = FreeFile
'open the file for writing
Open "C:Test.txt" For Output As #iFileNo
'please note, if this file already exists it will be overwritten!

'write some example text to the file
Print #iFileNo, "first line of text"
Print #iFileNo, " second line of text"
Print #iFileNo, "" 'blank line
Print #iFileNo, "some more text!"

'close the file (if you dont do this, you wont be able to open it again!)
Close #iFileNo
(note: an alternative to Print # is Write # , which adds commas between items, and also puts the " character around strings).



You can read files in a much faster way too, by simply loading the entire file at once. To do this you need to use binary mode, like so:

Function FileText(ByVal filename As String) As String
Dim handle As Integer

' ensure that the file exists
If Len(Dir$(filename)) = 0 Then
Err.Raise 53 ' File not found
End If

' open in binary mode
handle = FreeFile
Open filename$ For Binary As #handle
' read the string and close the file
FileText = Space$(LOF(handle))
Get #handle, , FileText
Close #handle
End Function


____________________________
AndreaVB

10-04-2008 at 08:43 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ranosb
Level: Protégé

Registered: 10-04-2008
Posts: 5
icon Re: Reading modifing text files

Its a simple links.txt file with links with about 30 links, example;

http://www.andreavb.com
http://www.yahoo.com
http://www.site03.com
http://www.site04.com
http://www.site05.com
http://www.site06.com

I need vb to open the links.txt file, take each line one by one and write the following;

function open1() {
var open1 =
window.open(' http://www.andreavb.com','','scrollbars=yes,height=540,width=785,resizable=yes');
window.open('http://www.yahoo.com','','scrollbars=yes,height=540,width=785,resizable=yes');
window.open('http://www.site03.com','','scrollbars=yes,height=540,width=785,resizable=yes');
window.open('http://www.site04.com','','scrollbars=yes,height=540,width=785,resizable=yes');
window.open('http://www.site05.com','','scrollbars=yes,height=540,width=785,resizable=yes');

Adding the text links one by one 10 at a time then
adding another function, for every 10 links;

}
function open2() {
var open2 =
window.open('http://www.site11.com','','scrollbars=yes,height=540,width=785,resizable=yes');

And when it finishes the last line it adds;
}

And saves all this to a new file



[Edited by ranosb on 10-04-2008 at 09:46 AM GMT]

10-04-2008 at 09:42 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 549
icon Re: Reading modifing text files

Here's your function:


Public Sub ReadAndProcessLinkFile(strSourceFile As String, strOutputFile As String)
    Dim iSource As Integer
    Dim iDest As Integer
    Dim strLink As String
    Dim iLink As Integer
    Dim iFunction As Integer
    
    iSource = FreeFile
    Open strSourceFile For Input As #iSource
    iDest = FreeFile
    Open strOutputFile For Output As #iDest
    'read line from source file
    iLink = 0
    iFunction = 1
    Do While Not EOF(iSource)
    Input #iSource, strLink
    If iLink = 0 Then
        'output function header
        Print #iDest, "function open" & iFunction & "() {"
        Print #iDest, "var open" & iFunction & " ="
    End If
    Print #iDest, "window.open('" & strLink & "','','scrollbars=yes,height=540,width=785,resizable=yes');"
    iLink = iLink + 1
    If iLink >= 10 Then
        'ouput end function
        iFunction = iFunction + 1
        iLink = 0
        Print #iDest, "}"
    End If
    Loop
    If iLink < 10 Then
        Print #iDest, "}"
    End If
    Close #iDest
    Close #iSource
End Sub


and this is how to call it, the first parameter is the source text file containing the link lines and the second is the name of the output file you want to generate (if the file exists it will be overwritten!)


Private Sub Command1_Click()
    ReadAndProcessLinkFile "c:test.txt", "c:outoput.txt"
End Sub


hope it works fine for you!

____________________________
AndreaVB

10-04-2008 at 12:29 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ranosb
Level: Protégé

Registered: 10-04-2008
Posts: 5
icon Re: Reading modifing text files

Thank you!

I have VB 6.0 and when I go to help it tells me "The MSDN collection does not exist"

Where can I get this, seems help should be include with VB!

I know there is a different command for this, whats a better way to write this?

If Counter = 1 Then
    Print #jFileNo, "function open1() {"
  Else
  If Counter = 11 Then
    Print #jFileNo, ""
    Print #jFileNo, "function open2() {"
  Else
  If Counter = 21 Then
    Print #jFileNo, ""
    Print #jFileNo, "function open3() {"
   End If
     End If
       End If

[Edited by ranosb on 10-04-2008 at 07:16 PM GMT]

10-04-2008 at 06:42 PM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 549
icon Re: Reading modifing text files


Select Case Counter
Case 1
     Print #jFileNo, "function open1() {"
Case 11
     Print #jFileNo, ""
     Print #jFileNo, "function open2() {"
Case 12
     Print #jFileNo, ""
     Print #jFileNo, "function open3() {"
End Select


____________________________
AndreaVB

11-04-2008 at 07:08 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
ranosb
Level: Protégé

Registered: 10-04-2008
Posts: 5
icon Re: Reading modifing text files

Thats the ticket!  Thanks Admin...

[Edited by ranosb on 11-04-2008 at 09:53 AM GMT]

11-04-2008 at 09:53 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Reading modifing text files
Next Topic (No forum activity) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder