Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / March 2007

Tip: Looking for answers? Try searching our database.

Get long *.txt into string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Regan - 29 Mar 2007 22:05 GMT
Hi the below function is to get a *.PGN file into a string. When i have a
small string it works good.  But it doesn't seem to work with  a long string.

Private Function GetPGN() As String

Dim strPath As String
Dim strFilter As String
Dim LngInputFile As Long

'Get location of *.PGN file
On Error GoTo ProcErr

strFilter = ahtAddFilterItem(strFilter, "PGN files (*.PGN)", "*.PGN")
strPath = ahtCommonFileOpenSave( _
               Filter:=strFilter, OpenFile:=True, _
               DialogTitle:="Please select an input file...", _
               Flags:=ahtOFN_HIDEREADONLY)

'Put contents of *.PGN into string
LngInputFile = FreeFile
Open strPath For Input As LngInputFile
Line Input #LngInputFile, GetPGN

Debug.Print GetPGN
ProcExit:
   Exit Function

ProcErr:
   MsgBox "Error " & Err.Number & "(" & Err.Description & ")"
   Resume ProcExit

End Function

Result in immediate window with small file =

[Event "Challenge from tfh_962"]
[Site "http://gameknot.com/chess.pl?bd=6944083"]
[Date "2007.03.18"]
[Round "-"]
[White "tfh_962"]
[Black "reganjackson"]
[Result "0-1"]
[WhiteElo "1736"]
[BlackElo "1200"]
[TimeControl "1/259200"]
[Mode "ICS"]
[Termination "normal"]

1. d4 Nf6 2. c4 e6 3. Nc3 Bb4 4. Qc2 O-O 5. a3 Bxc3+
6. bxc3 b6 7. e4 d6 8. Bd3 e5 9. f4 Nbd7 10. fxe5 dxe5
11. Nf3 Re8 12. O-O h6 13. Bb2 Nh5 14. c5 c6 15. cxb6 axb6
16. Nxe5 Nxe5 17. dxe5 Be6 18. Rad1 Qg5 19. c4 Bg4 20. Qf2 Bxd1
21. Qxf7+ Kh8 22. Rxd1 Nf4 23. Bf1 Ref8 24. Qd7 Nh3+ 25. Kh1
0-1

IT also works when there is 2 games

But when i  have a *.pgn with 13 games with annotation all that pops up in
the immediate window is
1 line

[Event "Odyssey 2001"]

Can someone tell me what is wrong please

Cheers

Signature

Regan,
Paeroa
World famous in New Zealand

Dirk Goldgar - 29 Mar 2007 22:22 GMT
> Hi the below function is to get a *.PGN file into a string. When i
> have a small string it works good.  But it doesn't seem to work with
[quoted text clipped - 63 lines]
>
> Cheers

I'm not sure where the problem is, but try this to read in the whole
file at one gulp:

   LngInputFile = FreeFile
   Open strPath For Input As LngInputFile
   GetPGN = Input(LOF(LngInputFile ), LngInputFile )
   Close #LngInputFile

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Regan - 29 Mar 2007 23:09 GMT
Thanks Dirk, that did exacty what i wanted it to do.  Now the fun part, i get
to parse it all and put into tables :),  

Thanks again

>file at one gulp:
>
>    LngInputFile = FreeFile
>    Open strPath For Input As LngInputFile
>    GetPGN = Input(LOF(LngInputFile ), LngInputFile )
>    Close #LngInputFile

Signature

Regan,
Paeroa
World famous in New Zealand

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.