ArrayList help.

Worf

Newcomer
Joined
Dec 19, 2008
Messages
17
Hi.

I have tried to make a small database using arraylist to store the information in text files and doing ok. The only problem i am having is Catagories and Sub-Catagories. Below is the code i am using, it's still a bit messy at the moment with trying out different methods. I would be greatful with help with this code if i am doing it wrong.

Below is the main menu.

Code:
view plaincopy to clipboardprint?
Public Class Menu    
  
Private Sub Menu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load    
  
' Get user name    
Username = System.Environment.UserName    
  
End Sub    
  
Private Sub ImportFPI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportFPI.Click ' If FPI selected then load Catagory with FPI and show the import form to import .FPI files   
Catagory = "FPI"    
ImpFpi.Show()    
  
End Sub ' View the Database   
Private Sub ViewFPI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewFPI.Click    
  
If FPIEmpty = Nothing Then    
  
MsgBox(Username + " Database empty, nothing to display.")    
  
Return    
  
Else    
  
ViewFPIScript.Show()    
  
End If    
  
End Sub ' Show FPI form to import .FPI text files.   
Private Sub FPIImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FPIImport.Click    
  
Catagory = "FPI"    
  
ImpFpi.Show()    
  
End Sub ' Show .FPE form to import .FPE files.   
Private Sub FPEImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FPEImport.Click    
  
Catagory = "FPE"    
  
  
End Sub

 ' Sub-Catagories that the FPE\FPI files will be stored under.

Private Sub Enemies_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enemies.Click    
  
SubCat = "Enemies"    
  
End Sub    
  
Private Sub Electronics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Electronics.Click    
  
SubCat = "Electronics"    
  
End Sub    
  
Private Sub Items_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Items.Click    
  
SubCat = "Items"    
  
End Sub    
  
Private Sub Objects_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Objects.Click    
  
SubCat = "Objects"    
  
End Sub    
  
Private Sub Weapons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Weapons.Click    
  
SubCat = "Weapons"    
  
End Sub    
  
Private Sub Water_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Water.Click    
  
SubCat = "Water"    
  
End Sub    
End Class

This code imports .FPI text files and stores the information.

Code:
Imports System    
  
Public Class ImpFpi    
  
Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click    
  
With openfiledlg    
  
'.InitialDirectory = "C:\"    
.Filter = "FPI Files (*.fpi)/*.fpi|"    
.CheckFileExists = True    
  
If openfiledlg.ShowDialog = Windows.Forms.DialogResult.OK Then    
  
TxtFile = openfiledlg.SafeFileName    
  
  
If Not System.IO.Path.GetExtension(TxtFile) = ".fpi" Then    
MessageBox.Show(Username + " please select an FPI file")    
TxtFile = "...."    
  
Else    
  
Dim ii As Integer = openfiledlg.FileName.LastIndexOf("\"c)    
TxtPath = openfiledlg.FileName.Substring(0, ii)    
End If    
End If    
End With    
  
If (Not TxtPath Is Nothing AndAlso String.IsNullOrEmpty(TxtFile)) Then    
  
MsgBox(Username + " No .fpi file selected.")    
  
Return    
  
Else    
  
TempPath = TxtPath + "\" + TxtFile    
  
Dim s As String = TempPath    
Dim txt As String = IO.File.ReadAllText(s)    
  
ViewFPI.Text = txt    
  
FPIFName.Text = TxtFile    
FPIPath.Text = TempPath    
  
End If    
  
End Sub    
  
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click    
  
Close()    
  
End Sub    
  
Private Sub AddFPI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFPI.Click    
  
If (Not TempPath Is Nothing AndAlso String.IsNullOrEmpty(TxtFile)) Then    
  
MsgBox(Username + " No .fpi file selected.")    
  
Return    
  
Else    
  
Try    
Dim s As String = TempPath    
Dim txt As String = IO.File.ReadAllText(s)    
  
  
FPITxtName.Add(TxtFile) ' Add .FPI file name to list    
ScriptDesc.Add(DescriptionInput.Text) ' Add description about the .FPI text file to list.   
Usage.Add(UsageInput.Text) ' Add Usage of the .FPI text file to list    
FPIItemList.Add(txt) ' Add the .FPI text file file to list.    
  
FPIEmpty = 1 ' Set to one if the FPI database is not empty.    
  
TxtFile = Nothing    
DescriptionInput.Text = Nothing    
UsageInput.Text = Nothing    
txt = ""    
  
Catch ex As Exception    
  
End Try    
  
End If    
  
End Sub    
  
End Class


This code allows you to view the FPI text files stored.

Code:
Public Class ViewFPIScript    
  
Private Sub ViewScript_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Add each FPI file name to the listbox.    
  
For Each s As String In FPITxtName    
' Dim i As New items(s)    
ListBox1.Items.Add(s)    
Next    
  
End Sub    
  
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click    
  
Close()    
  
End Sub ' Display FPI scripts that the user selects from the listbox.Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged    
  
For j As Integer = 0 To ListBox1.Items.Count - 1    
If ListBox1.SelectedIndex = j Then    
  
Label2.Text = FPITxtName.Item(j)    
ScriptDescr.Text = Convert.ToString(ScriptDesc.Item(j), CultureInfo.CurrentCulture)    
UsageInput.Text = Convert.ToString(Usage.Item(j), CultureInfo.CurrentCulture)    
FPIScript.Text = Convert.ToString(FPIItemList.Item(j), CultureInfo.CurrentCulture)    
  
End If    
Next    
  
End Sub    
End Class

What i can't figure out is how to apply the Catagory and Sub-Catagory for each FPI script so that when the user selects a sub-catagory, any FPI text files stored under it is displayed.

So, if the user selected Catagory - FPI and Sub-Catagory - Enemies, the FPI text file is stored under this Catagory and Sub-Catagory. As you can see in the menu code there is also an 'FPE' and other Subcatagory.

Thank you for your help.

Worf.
 
Back
Top