Results 1 to 8 of 8

Thread: Game related Project

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    24

    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:


  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    24

    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.

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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.
    Doctor Ed

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    24

    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?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2007
    Posts
    24

    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.

  7. #7
    Fanatic Member
    Join Date
    Jun 2006
    Posts
    615

    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.

  8. #8
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Game related Project

    Quote 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.
    Doctor Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width