[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1054
  • Last Modified:

Creating online high score table from VB game.

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
Jacamar
Asked:
Jacamar
  • 3
  • 2
2 Solutions
 
TooKoolKrisCommented:
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
 
JacamarAuthor Commented:
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
 
TooKoolKrisCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
petoskey-001Commented:
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
 
petoskey-001Commented:
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
 
TooKoolKrisCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now