Cant assign value to lists i defined in module1 from form2

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
please may i get some help with this...
ive setup some lists in module1 so i can reffer to them in all forms. i fill the lists in form1 from textfiles and that works fine. but when i try to add a vale to them in form2 it doesnt seem to get assigned for want of a better explination. ive got a msgbox just b4 the update lists bit to check im not assigning null values.
i just cant get the values to add to the lists can someone please help me
my code...
MODULE1
---------------------
Module Module1
Public DataREF As List(Of String) = New List(Of String)
Public NameREF As List(Of String) = New List(Of String)
Public StatREF As List(Of String) = New List(Of String)
Public AppPATH As String = "C:testDIR"
Public DataPATH As String = "C:testDIRDATA"
End Module
FORM1
----------------------
Imports System.IO

Public Class Form1
Public Temp1 As String = ""
Private count As Integer = 0
Private Temp2 As String = ""
Private IndexMarker As Integer = 0

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

puts item names into NameREF list

If System.IO.File.Exists(AppPATH & "items.txt") = True Then
Dim objreader As New System.IO.StreamReader(AppPATH & "items.txt")
Do While Not Temp1 Is Nothing
Temp1 = objreader.ReadLine
NameREF.Add(Temp1)
Loop
objreader.Close()
Else
MessageBox.Show("Cannot Find Database Item Name Source Files!" & vbCrLf & "Exit App")
Me.Close()
End If

puts item stats filenames into StatREF list
Temp1 = ""
If System.IO.File.Exists(AppPATH & "stats.txt") = True Then
Dim objreader As New System.IO.StreamReader(AppPATH & "stats.txt")
Do While Not Temp1 Is Nothing
Temp1 = objreader.ReadLine
StatREF.Add(Temp1)

Loop
objreader.Close()
Else
MessageBox.Show("Cannot Find Database Statistics Source Files!" & vbCrLf & "Exit App")
Me.Close()
End If

add items to listbox
For Each item In NameREF
ListBox1.Items.Add(item)
Next

End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged


reads statistic file reffered by listbox.Slectedindex a puts into StatLABEL
try/catch handles eof overflow error
Try
IndexMarker = ListBox1.SelectedIndex
MsgBox(StatREF(IndexMarker))
Label1.Text = NameREF(IndexMarker).ToString
Dim line As String
Dim ReadFILE As System.IO.TextReader = New StreamReader(DataPATH & StatREF(IndexMarker) & ".txt")
line = ReadFILE.ReadToEnd()
LABEL1.Text = line
ReadFILE.Close()
Catch ex As IndexOutOfRangeException

End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class
FORM2
--------------------------------
Public Class Form2
Dim Temp1 As String
Dim Temp2 As String
Dim GeneratedRandom As New Random
Public RndTOSAVE As String
Public NameTOSAVE As String
Public SourceTOSAVE As String
Dim count As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

RemakeSaveTag:
RndTOSAVE = GeneratedRandom.Next(1000, 10000).ToString makes number tag for building the new items save filename
NameTOSAVE = Microsoft.VisualBasic.Left(TextBox1.Text.ToString, 4) crops name tag off new item name for save filename

saves Statistic file to data directory
Dim file As System.IO.StreamWriter

first 2 lines checks for matching filename and if so jumps back and creates a new one
the ELSE writes the fle to the defined database source directory as DataPATH string

If System.IO.File.Exists(DataPATH & RndTOSAVE.ToString & Name & ".txt") = True Then
MsgBox("Debugger:" & vbCrLf & "File :" & DataPATH & RndTOSAVE.ToString & NameTOSAVE & ".txt Exists!") -> DELETE LINE LATER <-
GoTo RemakeSaveTag return to start of build new item file name routine

Else
file = My.Computer.FileSystem.OpenTextFileWriter(DataPATH & RndTOSAVE.ToString & NameTOSAVE & ".txt", True)
file.WriteLine(TextBox1.Text)
file.WriteLine(TextBox2.Text)
file.WriteLine(TextBox3.Text)
file.Close()
End If

Append item to listfile

file = My.Computer.FileSystem.OpenTextFileWriter(AppPATH & "Items.txt", True)
file.WriteLine(TextBox1.Text)
file.Close()

Append Database Source Listfile to the defined source list directory and textfile

file = My.Computer.FileSystem.OpenTextFileWriter(AppPATH & "Stats.txt", True)
file.WriteLine(RndTOSAVE.ToString & NameTOSAVE)
file.Close()

update arrays and add to form1 listox

Form1.ListBox1.Items.Add(TextBox1.Text)

NameREF.Add(TextBox1.Text) < ------------------------------value here wont assign to list

Temp1 = RndTOSAVE.ToString + NameTOSAVE.ToString

StatREF.Add(Temp1) < ------------------------------value here wont assign to list either

my debug messagebox
count = 0
Do Until NameREF(count) Is Nothing
MsgBox("Name:" & NameREF(count) & vbCrLf & "stat: " & StatREF(count))
count = count + 1

Loop



Me.Close()


End Sub

End Clas
sorry if i posted too much, wanted to be sure i had enough info up. ty for help in advance... and then some.

View the full article
 
Back
Top