RE: Storing Variables by JasonHartsoe
JasonHartsoe
Fri May 09 08:13:01 CDT 2008
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'To Insert start up code here.
ReadXML()
ProcessTree(myPPath)
ReadFiles(myPPath, "HIGHRES")
ReadFiles(myPPath, "MEDRES")
ReadFiles(myPPath, "LOWRES")
End
End Sub
Public Sub ReadFiles(ByVal path As String, ByVal imgtype As String)
Dim di As New IO.DirectoryInfo(path & imgtype & "\")
Dim ImgExt As String
If imgtype = "HIGHRES" Then
ImgExt = "*.jpg"
Else
ImgExt = "*.*"
End If
Dim diar1 As IO.FileInfo() = di.GetFiles(ImgExt)
Dim dra As IO.FileInfo
For Each dra In diar1
ReadData(dra.FullName)
Next
'''*** Here is where i want to set the variable for global for each run....
''' example: highres, then set the global varable for medres etc as it's
executed
''' from frmMain. Then read that variable in any other sub below with it's
current value.
End Sub
Public Sub ReadData(ByVal Path As String)
Dim tempStateObj As New StateObj
Try
tempStateObj.file = New System.IO.FileStream(Path,
IO.FileMode.Open)
Catch ex As System.UnauthorizedAccessException
Exit Sub
Catch ex As System.IO.IOException
Exit Sub
End Try
'Debug.WriteLine(Now & " Read Start: " &
Path.Substring(InStrRev(Path, "\")))
'Begin Write to write all images to memory then output to directories
ReDim tempStateObj.retData(Convert.ToInt32(tempStateObj.file.Length))
tempStateObj.file.BeginRead(tempStateObj.retData, 0,
Convert.ToInt32(tempStateObj.file.Length), AddressOf OnReadDone, tempStateObj)
End Sub
Public Sub OnReadDone(ByVal ar As IAsyncResult)
Dim state As StateObj = CType(ar.AsyncState, StateObj)
Dim bytesRecieved As Int32 = state.file.EndRead(ar)
Debug.WriteLine(Now & " Read Done: " &
state.file.Name.Substring(InStrRev(state.file.Name, "\")))
state.file.Close()
Dim RetNum As String
RetNum = ReturnNumbersOnly(state.file.Name)
Dim RNFolder As Integer
RNFolder = Len(RetNum)
Dim ReNum As Integer
Dim ReNum2 As String
Dim ReNum3 As String
ReNum2 = ""
ReNum3 = ""
Dim x As Integer
If RNFolder < 8 Then
ReNum = (8 - RNFolder)
ReNum2 = RetNum
For x = 0 To (ReNum - 1)
ReNum2 = "0" & ReNum2
Next x
ReNum3 = ReNum2
Else
ReNum3 = RetNum
End If
If Directory.Exists(mySPath & ReNum3) Then
'Debug.WriteLine(mySPath & "already exists")
Else
Directory.CreateDirectory(mySPath & ReNum3)
End If
Try
'--Open up a new file to write to
state.file = New System.IO.FileStream(mySPath & ImgTypes & "\" &
ReNum3 & "\" & state.file.Name.Substring(InStrRev(state.file.Name, "\")),
FileMode.Create)
'
Catch Ex As Exception
'MsgBox(Ex.Message)
End Try
End Sub