|
-
May 1st, 2008, 12:56 PM
#1
Thread Starter
Junior Member
Game related Project
So I play a browser based game and I thought about using VB to help me.
I am alas not very experienced in vb so please don't be too technical in your ideas
My first problem is to load records from a text file into a list box : I did manage to do that but each record in the text file is in a line while in the list box, it isn't.
Also I get some squares in occasional places. How to solve this ?
Here's my code:
Code:
Private Type OneKingdom
KingdomID As Integer
Name As String * 30
Planet As String * 25
Land As String * 6
Networth As String * 10
Honor As String * 4
End Type
Dim Filename As String
Dim NumberOfRecords As Integer
Private Sub cmdDisplayFile_Click()
Dim Index As Integer
Dim DataToDisplay As String 'details of one KD
Dim Name As String * 30
Dim Planet As String * 25
Dim Land As String * 6
Dim Networth As String * 10
Dim Honor As String * 4
Dim Kingdom As OneKingdom
Filename = txtFilename.Text
lstdisp.Clear
Open Filename For Random As #1 Len = Len(Kingdom)
For Index = 1 To NumberOfRecords 'loop through KDs in file
Get #1, , Kingdom
Name = Kingdom.Name
Planet = Kingdom.Planet
Land = Kingdom.Land
Networth = Kingdom.Networth
Honor = Kingdom.Honor
DataToDisplay = Kingdom.Name & " " & Planet & " " & Land & " " & Networth & " " & Honor & " " & Stuff & " "
lstdisp.AddItem DataToDisplay
Next Index
Close #1
End Sub
Private Sub cmdSelectFile_Click()
Dim Kingdom As OneKingdom 'one record
CommonDialog1.Showopen 'display the Open (file) dialog box
txtFilename.Text = CommonDialog1.Filename 'display selected file name
Filename = txtFilename.Text
Open Filename For Random As #1 Len = Len(Kingdom) 'open file
NumberOfRecords = LOF(1) / Len(Kingdom) 'calculate number of kindgoms in it
lblrecords.Caption = NumberOfRecords
Close #1
End Sub
here is what happens:
-
May 1st, 2008, 01:22 PM
#2
Re: Game related Project
The squares are carriage returns.
Try this
Code:
Dim sData As String
Dim sFilename As String
sFilename = "c:\yourfile.txt"
Open sFilename For Input As #1
While Not EOF(1)
Line Input #1, sData
List1.AddItem sData
Wend
-
May 1st, 2008, 01:44 PM
#3
Thread Starter
Junior Member
Re: Game related Project
Wow thanks for the quick reply and solution! Is there a way to keep the data in each other like if they were in columns ?

Ok my next problem is, I wanna take specific data from the list, like filter it in a way. Well more like taking specific data to elsewhere where I can work with it. So how can I do that ?
Last edited by dvlkn; May 1st, 2008 at 01:54 PM.
-
May 1st, 2008, 03:42 PM
#4
Re: Game related Project
It appears tro me that we (and perhaps you) really don't know how this file was created in the first place. Was it a random (direct) access file, a sequential text file, or just plain vanilla binary? Hack's code shows that lines were actually used to build it, followed by vbCrLF at each line's end, and that's why Line Input started to make some sense of things. I am, therefore, surmising that this was built as a sequential text file. But, your code in the OP opened it as a random access file, and that's what produced the squares, bad alignments, and other gibberish in the list box.
Therefore, before you can extract meaningful output from this file, please look at the code you used to build it originally. That code positioned the variables as strings stored on disk. Then when you write code to read it back out, you will be able to format it correctly for screen display of the information from within.
-
May 2nd, 2008, 12:57 AM
#5
Thread Starter
Junior Member
Re: Game related Project
Well the text file has exactly the same alignment as seen from the listbox in the last screenshot. It is just a copy/paste of a web table to notepad whose values I am gonna work with.
But I see that Hack's method is no good for me since I need to define each data as strings to work with it. So I am back to square 1: any ideas?
-
May 2nd, 2008, 05:59 AM
#6
Thread Starter
Junior Member
Re: Game related Project
Here is what I am trying to do:
Compare the data found in the first text file to the next.
Calculate the difference between the two (the numbers in them of course) for each record.
Output the results in another listbox or, clear the current one and display the results in it.
I will post screenshots as soon as I can, imagehost is down.
-
May 2nd, 2008, 07:38 AM
#7
Fanatic Member
Re: Game related Project
You are aware you can post images and files directly on here correct?
ALOT of people wont view anything that wasn't uploaded here. Just letting you know.
If ive helped, RATE my post.
If your thread is solved, and you got your answer, mark this thread Resolved.
There is no other forum like VBFORUMS.
-
May 2nd, 2008, 09:01 AM
#8
Re: Game related Project
 Originally Posted by dvlkn
... It is just a copy/paste of a web table to notepad whose values I am gonna work with. ...But I see that Hack's method is no good for me since I need to define each data as strings to work with it. So I am back to square 1: any ideas?
So, you really do not have any idea how the file was built in the first place. Notepad just saved some data as a sequential text file. Therefore, you are driving a car blindfolded on a crowded expressway.
Good Luck.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|