Solved

Creating online high score table from VB game.

Posted on 2003-11-28
9
1,035 Views
Last Modified: 2012-06-27
Hello,  I have a simple visual basic game that I have made, and I have posted it on a website.  Is there anyway that I can have that visual basic program interact with a text file that is also saved on the website's server.  I would like the game to beable to generate a high score table.  


Thanks for the help.
0
Comment
Question by:Jacamar
  • 3
  • 2
9 Comments
 
LVL 9

Accepted Solution

by:
TooKoolKris earned 63 total points
ID: 9840050
You can turn the webpage into an ASP page and then use some scripting to open an text file for writing and reading.

Sub OpenTextFileTest
   Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
   f.Write "Hello world!"
   f.Close
End Sub

Function ReadTextFileTest
   Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Dim fso, f, Msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
   f.Write "Hello world!"
   Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
   ReadTextFileTest = f.Read(5)
End Function

Function ReadLineTextFile
   Const ForReading = 1, ForWriting = 2
   Dim fso, MyFile
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
   MyFile.WriteLine "Hello world!"
   MyFile.WriteLine "The quick brown fox"
   MyFile.Close
   Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading)
   ReadLineTextFile = MyFile.ReadLine    ' Returns "Hello world!"
End Function
0
 
LVL 2

Author Comment

by:Jacamar
ID: 9840138
Ok, I don't want to write to a file on the users computer, I want to write to a text file that is on the web server.  I have a file saved as Highscores.txt

I want to interact with that using my VB game.
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9840438
These scripts are for the server side as most processing is done on the server with ASP. You need to do some work of your own if you can't see a vaule in any of those functions for editing and showing text from a text file.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Assisted Solution

by:petoskey-001
petoskey-001 earned 62 total points
ID: 9841517
There are two main ways to do this.

1. Upload and download the Highscores.txt direct from the server using FTP, modift it and put it back when your done.  A simple, insecure and bad way to do things if you have any amount of users on your system, but still doable for small amount of trusted users.  It is the only way possible if your website doesn't allow CGI scripts such as PHP, PERL, Python, etc.  Even then it may not be possible depending on how your web server is setup.  If you want to do that, use the INET control and download the file, modify it and put it back.  Like I said this is not suggested, so I'll concentrate on the other way.

2. Use a CGI script to update and store the high score list.  This is similar to what TooKoolKris is suggesting.  The game would then use HTTP or a database connection to your website database if possible and submit a new high score.  When people view the high score list on your server, the CGI would generate the high score list of the highest top 10 score, or download the generated file.


The CGI would probably accept high score submissions using something like "http://www.mycoolgame.com/cgi-bin/sendmyscore.cgi?playername=Mario&score=12345&verify=ABCDEFG".  

You will want to compute a verification algorithm for your high scores, or it will rather quickly be figured out and people will just enter their own high scores.  The CGI will take verify the score matches the verify code, and if so check if it should be added to the high score list.  You can choose to save all score, or ignore it if it's not in the top 10 and create the Highscores.txt during submission.   I'll let you deal with the database method if you want.  I'm going to assume the CGI generates the HighScores.txt when a new high score is submitted.

I won't get into this how to create the CGI because I don't know what your web server is capable of, or what language your CGI will use.

Here is an example of the Visual Basic end of things.  I use a simple INet Control.  You can add it to your form under the menu Project / Components...   The name is Microsoft Internet Transfer Controls 6.0 (SP4) on my system.  Something like this.

Private Sub Command1_Click()
  Text1.Text = Inet1.OpenURL("http://russell.ryba.net/demos/usamap/?username=Mario&score=123&verify=123", icString)
   'or do into a variable
  strHighscoreList = Inet1.OpenURL("http://russell.ryba.net/demos/usamap/?username=Mario&score=123&verify=123", icString)
End Sub

Then you don't even need to save a temporary file on your game players system.

It's a bit more then you asked for, and a bit less too I guess without the CGI script.  Tell me more about what your server can do and maybe I can help you out with that.
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 10166920
I think CGI is the only way to go, but at this point I don't know if it still matters.  I would like to see the game though.
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 10173307
CGI is going the way of the dinosaur amigo; get with the times :) Besides if this game is in VB there is a good chance the host will be MS as well and ASP.NET blows CGI totally out of the water.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now