Sign in to follow this  
delstar81

VB help requested

Recommended Posts

A friend of mine and I are in the process of making some tools for PnP RPG's, such as a character gen, monster/spell/whatever info viewer, dice roller, etc. Right now, we're running into a problem as to the best way to store information on monsters/spells/whatever. We're currently storing it to a plain text file, but there are several headaches cropping up there. I've tried researching into databases and XML as possible alternatives, but most information I find is too sketchy on details for me to be comfortable with it (database info turns out to be focused on the actual writting of the database, but not on how to access it with code, and XML info focuses on web stuff, which we're not doing, or tends to be a convuluted nightmare) So, to the question, does anyone know of any tutorials that show how to make a simple database and how to access it, or how to work with XML to the extent that I need it, without all the extra crap? Or would we be better off with just a plain text file?

Share this post


Link to post
Share on other sites
No takers? I thought I might find some useful info here. Ah well. Just in case, I'm using VB.NET 2005. Any opinions would be useful.

Share this post


Link to post
Share on other sites
This depends on what kind of data you want to store. You can store stuff about monsters and spells in files. Since you are working on .NET, this should be pretty easy. You can create a class that defines a specific type of monster, and then you can load in the data for a new monster from a file. You can use something like

MonsterType = "dog"
ImageFile = "dog.bmp"
AttackPower = "34"
...


You can easily parse this file and then use it in your game.

Share this post


Link to post
Share on other sites
I am currently working on a project very much like yours. A lot of it depends on how much data you have. For the typical stuff i would suggest XML, it works pretty well and can really store a lot of information and is pretty easy to access.

If you have tons of information, like all of the source books for Rifts then I would suggest going with mySQL.

If you need some help getting started let me know, I should be able to point you in the right direction.

theTroll

Share this post


Link to post
Share on other sites
Hope this helps...didn't test it, but I think it should help you out a bit...

Reading XML file:
Dim objDocument As Object
Dim objNode As Object
Dim objNodeList As Object
Dim strName As String, strHealth As Long, strStrength As Long
Dim objMonster As Monster
Dim objMonsters As New Collection

' Create DOM Document object.
Set objDocument = new ActiveXObject("Microsoft.DomDocument");

' Open the XML file.
objDocument.async = False
objDocument.validateOnParse = False
Call objDocument.Load(strFilename)

' Loop through each element of the root.
If objNode.parseError.errorCode = 0 Then
' Find the children of the "monsters" element.
Set objNode = objDocument.documentElement.selectSingleNode("monsters")
Set objNodeList = objNode.childNodes

' Loop through each single "monster" element and create monsters objects.
For Each objNode In objNodeList
Set objMonster = New Monster

Call objMonster.setName(objNode.selectSingleNode("name").nodeValue)
Call objMonster.setHealth(CLng(objNode.selectSingleNode("health").nodeValue))
Call objMonster.setStrength(CLng(objNode.selectSingleNode("strength").nodeValue))

Call objMonsters.Add(objMonster)
Next
Else
' Handle error here...
End If

' Dereference memory objects.
Set objDocument = Nothing
Set objNode = Nothing
Set objNodeList = Nothing
Set objMonster = Nothing



Writing XML file:
Dim objDocument As Object
Dim objMonsterNode As Object, objCurNode As Object

' Create DOM Document object.
Set objDocument = new ActiveXObject("Microsoft.DomDocument");

' Load filename you provide to function.
objDocument.async = False

Set objMonsterNode = objDocument.createElement("monsters")
Set objDocument.documentElement = objMonsterNode
For Each objMonster in objMonsters
Set objCurNode = objDocument.CreateElement("name")
objCurNode.nodeValue = objMonster.getName()
Call objMonsterNode.appendElement(objCurNode)

Set objCurNode = objDocument.CreateElement("health")
objCurNode.nodeValue = objMonster.getHealth()
Call objMonsterNode.appendElement(objCurNode)

Set objCurNode = objDocument.CreateElement("strength")
objCurNode.nodeValue = objMonster.getStrength()
Call objMonsterNode.appendElement(objCurNode)
Next

Call objDocument.Save(strFilename)

' Dereference memory objects.
Set objDocument = Nothing
Set objCurNode = Nothing
Set objMonsterNode = Nothing

Share this post


Link to post
Share on other sites
Here is an article on XML serialization with VB.Net. This lets you easily define how a class is stored in XML.

Although, depending on how complex the data is, a simple text file may be better. If you want to use databases you need to look for information on ADO.NET and SQL.

Share this post


Link to post
Share on other sites
Thanks for the replies. A couple things, though...

MattMan : Will the code you use to write to the XML file actually create the file and fields, or will I have to do that seperately?

Currently, this is being geared towards DnD 3rd Ed., and we have two monster manuals, a speel book, and several other things, so it'll probably be quite a bit of info. We already have the dice roller and character generator. Right now I'm working on a program to store the monster info into the files, so his wife can start data entry on that.

Ace Pilot : I would like to make a file like that, but have no idea how to parse something like that. Right now we're simply using the MyReader parsing, as referenced by MSDN.

Share this post


Link to post
Share on other sites
You can either enter the information into the XML by hand (something I seem to be fond of doing) or write a simple app to enter the information for you.

I would suggest you make a class that can enter and retrive information from the XML file. This class can be used to make an app to enter the information and it can also be used in your RGP app. It might also be a good idea to create in your RGP app a way to enter more information to the XML file. This will let you have a single program instead of two to keep up with more information.

theTroll

Share this post


Link to post
Share on other sites
thetroll : Read the original post. The problem is that I have no idea where to start doing something like that, and every foray into Google or a book leaves me with more questions and very few answers.

Share this post


Link to post
Share on other sites
delstar81, tell me what kind of information you would like to store, and I will work on an example for you in the next two days.

theTroll

Share this post


Link to post
Share on other sites
Since you are using VB.Net 2005 I would suggest looking into ADO Typed Datasets.
It will give you a database like structure with the ability to serialize to xml.

You also have great filtering and search tools.

Share this post


Link to post
Share on other sites
While ADO will be more of a learning curve then just serialized XML, I'd also strongly reccommend it. By implementing fairly easy SQL commands in VB you can manipulate the data to a much greater extent in a database then is possible in XML. You also get the added benefit of security, relational data, and easy to edit control. Of course this also boils down to the tools you have available. If you already have Access/SQL Server (or any other RDBMS) this is sound advice, otherwise stick with XML.

ADO Tutorial

XML Serialization Tutorial

From what I've read in just the past few minutes VB.net does away with RDO and DAO so in theory is should be a touch easier to implement a wide array of databases. Best of luck with which ever direction you choose.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this