Array Placement
Array Placement
Array Placement
Array Placement
Array Placement
Array Placement Array Placement Array Placement Array Placement Array Placement Array Placement Array Placement Array Placement
Array Placement Array Placement
Array Placement
Go Back  Xtreme Visual Basic Talk > > > Array Placement


Reply
 
Thread Tools Display Modes
  #1  
Old 12-29-2014, 08:01 AM
Oversat's Avatar
Oversat Oversat is offline
Newcomer
 
Join Date: Jul 2008
Location: El Paso, TX
Posts: 15
Default Array Placement


I am using a host of fairly large arrays as a kind of ad-hoc database for looking up items with loops. It takes up a ridiculous amount of space if I have them in the form_Load event. Is there somewhere else I can put these static arrays to make my code neat and clean? I'd definitely like it if they had a home they could call their own
Reply With Quote
  #2  
Old 12-29-2014, 09:03 AM
Gruff's Avatar
GruffArray Placement Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Some more detail of what you are looking up would be helpful. Perhaps you should be using a true database?
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 12-29-2014, 10:37 AM
Oversat's Avatar
Oversat Oversat is offline
Newcomer
 
Join Date: Jul 2008
Location: El Paso, TX
Posts: 15
Default

It's essentially a look-up program for Dungeons and Dragons. So there are arrays for rings, rods, staffs, wands, 3 for magic items (minor, medium, and major), armor, weapons, etc. Each array contains details about the items, such as price, aura, caster level, and so on. Here's what a few lines look like:

ArmorAbi(0, 0) = " Glamered" : ArmorAbi(0, 1) = "+2,700gp" : ArmorAbi(0, 2) = "Craft Magic Arms and Armor" : ArmorAbi(0, 3) = "Moderate Illusion" : ArmorAbi(0, 4) = "10" : ArmorAbi(0, 5) = "disguise self"
ArmorAbi(1, 0) = " Light Fortification" : ArmorAbi(1, 1) = "+1 bonus" : ArmorAbi(1, 2) = "Craft Magic Arms and Armor" : ArmorAbi(1, 3) = "Strong Abjuration" : ArmorAbi(1, 4) = "13" : ArmorAbi(1, 5) = "limited wish or miracle"
ArmorAbi(2, 0) = " Slick" : ArmorAbi(2, 1) = "+3,750gp" : ArmorAbi(2, 2) = "Craft Magic Arms and Armor" : ArmorAbi(2, 3) = "Faint Conjuration" : ArmorAbi(2, 4) = "4" : ArmorAbi(2, 5) = "grease"
ArmorAbi(3, 0) = " Shadow" : ArmorAbi(3, 1) = "+3,750gp" : ArmorAbi(3, 2) = "Craft Magic Arms and Armor" : ArmorAbi(3, 3) = "Faint Illusion" : ArmorAbi(3, 4) = "5" : ArmorAbi(3, 5) = "invisibility"
ArmorAbi(4, 0) = " Silent Moves" : ArmorAbi(4, 1) = "+3,750gp" : ArmorAbi(4, 2) = "Craft Magic Arms and Armor" : ArmorAbi(4, 3) = "Faint Illusion" : ArmorAbi(4, 4) = "5" : ArmorAbi(4, 5) = "silence"

And there are over 1,000 lines of code to create the arrays in the form_load event. So basically, is there a better place to put them? Like their own code file (which you can't) or something?
Reply With Quote
  #4  
Old 12-29-2014, 11:14 AM
PlausiblyDamp's Avatar
PlausiblyDampArray Placement PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

You could always store the information in an external file (or even a database) and load the details from the file when the program starts. That would also aid in maintenance as you wouldn't need to recompile just to add a new item or adjust the stats etc.

You might also find it better to create a Class to hold the various item properties and have an array (or perhaps a generic List) to hold the items. That way you wouldn't need to be accessing array offsets to retrieve the various properties and it would also allow you to have different data types for the individual properties rather than everything being a string.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 12-29-2014, 06:38 PM
Oversat's Avatar
Oversat Oversat is offline
Newcomer
 
Join Date: Jul 2008
Location: El Paso, TX
Posts: 15
Default

So it's possible to just stick them in a class? I don't want to have to rewrite all these arrays. It took me weeks.
Reply With Quote
  #6  
Old 12-30-2014, 06:24 AM
PlausiblyDamp's Avatar
PlausiblyDampArray Placement PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

You could stick them in a class but other than the code not being in the form load you would still have the problem of over a 1,000 lines of array definitions.

Doing that might make a small difference but I would personally strongly advise looking at using classes to organise this information rather than an array.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #7  
Old 12-30-2014, 10:11 AM
Oversat's Avatar
Oversat Oversat is offline
Newcomer
 
Join Date: Jul 2008
Location: El Paso, TX
Posts: 15
Default

I'm going to take a look at it. Thanks for all the help!
Reply With Quote
  #8  
Old 01-09-2015, 10:52 AM
Gruff's Avatar
GruffArray Placement Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

One thing you could do to make things easier for yourself would be to create a small temporary sub-routine that writes all these arrays to a comma delimited text file.

Dump them once to the file. remove the temporary sub-routine.

Now write an import function that reads the data from disk into whatever structure you wish. An array groups of Arrays, Arrays of structures. List(of Class) whatever you like

The point being that this would take 30 minutes of your time and allow you to play with different memory structures without having to re-enter all your data manually every time.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #9  
Old 01-11-2015, 07:36 PM
dotnetwrassler dotnetwrassler is offline
Regular
 
Join Date: Sep 2014
Location: USA (Pacific/West Coast)
Posts: 71
Default text files as database..

Quote:
Originally Posted by Gruff
The point being that this would take 30 minutes of your time..
There is also the old ini file format.
It's simple text files with key/value combinations.

The working "IniFile_Sampler.zip" code is attached to this post (if you maybe want save the 30 minutes of code writing + debugging):
http://www.xtremevbtalk.com/1391992-post4.html
Reply With Quote
  #10  
Old 01-12-2015, 04:10 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default

I'm just curious as to why you need 2 elements in your
array to store data when 1 element would be plenty.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Array Placement
Array Placement
Array Placement Array Placement
Array Placement
Array Placement
Array Placement Array Placement Array Placement Array Placement Array Placement Array Placement Array Placement
Array Placement
Array Placement
 
Array Placement
Array Placement
 
-->