Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

People Who can use VB file handling QU

Thread Tools
 
Search this Thread
 
Old 11 March 2002, 01:02 PM
  #1  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

Basically im doing Vb as part of my Uni thingy, I need to import a txt file called player.txt and read from the file players postitions!

ive no idea how to file handle using VB at all! thyve given us no help can anyone help or shed light? my MSN's pug_106_gti@hotmail.com all help appreciated

Si

http://www.cs.ncl.ac.uk/modules/2001-02/csc124/assign2.html
Old 11 March 2002, 01:13 PM
  #2  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

do you need to do anything except read the whole file in one go?

for reading the file, assuming it's
line1data1, line1data2, line1data3, line1data4,...
line2data1, line2data2, line2data3, line2data4,...

dim sFields() as string
dim sLineIn as string
dim x as long
dim fNum as integer

fnum=freefile 'get next available file handle
open "filename" for input as fnum

do
line input #fnum,sLineIn 'read an entire line
sfields=split(slinein,",") 'separate fiel input line into comma separated fields
'and place in array sFields
for x=0 to ubound(sfields)
debug.print sfields(x)
next x
loop until eof(fnum)
close fnum

I should have a look at your link first I s'pose
Old 11 March 2002, 01:17 PM
  #3  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

having read through your thing, I reckon you need to specify a type definition or a record layout. This way you can open the file for random access and read a record straight into a layout.


As with all things, what you learn at college will be of no use when you get out



Old 11 March 2002, 01:23 PM
  #4  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

Let me know where you get stuck.

This function will read an entire text file in one go
Just specify...
dim sFile as string
sFile = FileText("c:\autoexec.bat")

Function FileText(ByVal filename As String) As String
Dim handle As Integer
If Len(Dir$(filename)) = 0 Then
Err.Raise 53 ' File not found
End If
handle = FreeFile
Open filename$ For Binary As #handle
FileText = Space$(LOF(handle))
Get #handle, , FileText
Close #handle
End Function

This function will return a true state if the passed filename exists...
Function FileExists(FileName As String) As Boolean
On Error GoTo ErrorHandler
' get the attributes and ensure that it isn't a directory
FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
' if an error occurs, this function returns False
End Function

I use these functions in most of my apps.

Fosters

Old 11 March 2002, 05:58 PM
  #5  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

Bascailly am stuck now! at the moment ive got a black form with labels laid out in the positions
gk
dl dc dc1 dr

ml mc mc1 mr
fc fc1

Like than then on the left i was thinking having list boxes?? so they can drop down then select player
so
gk
dl
dr etc all down each with a list then the corresponding label has there name! now where do i start!!

Si
Old 11 March 2002, 05:59 PM
  #6  
super_si
Scooby Regular
Thread Starter
 
super_si's Avatar
 
Join Date: Feb 2002
Location: Lurkin Somewhere
Posts: 7,951
Likes: 0
Received 0 Likes on 0 Posts
Post

ment to say thanks for so far
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Frizzle-Dee
Essex Subaru Owners Club
13
01 December 2015 09:37 AM
PetrolHeadKid
Driving Dynamics
10
05 October 2015 05:19 PM
Ganz1983
Subaru
5
02 October 2015 09:22 AM
Nick_Cat
Computer & Technology Related
2
26 September 2015 08:00 AM
Littleted
Computer & Technology Related
0
25 September 2015 08:44 AM



Quick Reply: People Who can use VB file handling QU



All times are GMT +1. The time now is 03:54 AM.