Storing Variables

J

Jason Hartsoe

I have a sub routine that's passing in a variable. I need to take that
variable and store it globally...but here's what's happening.

ex: I'm executing my routine: doMyThing(path, "test")
I'm executing that command at least 10 times replacing the word test with my
next object. When im receving that variable:
Sub doMyThing(ByVal Path As String, ByVal other As String)
I can use my variable...now how can I take that variable from this sub and
pass it to another sub? Is there a way to store that variable or set during
each call of doMyThing? Does that make sense? lol

Basically I want to store it and change it during each call...i'm doing some
async stuff and need it to change each time it's called....

thanks!
 
A

Armin Zingler

Jason Hartsoe said:
I have a sub routine that's passing in a variable. I need to take
that variable and store it globally...but here's what's happening.

ex: I'm executing my routine: doMyThing(path, "test")
I'm executing that command at least 10 times replacing the word test
with my next object. When im receving that variable:
Sub doMyThing(ByVal Path As String, ByVal other As String)
I can use my variable...now how can I take that variable from this
sub and pass it to another sub? Is there a way to store that
variable or set during each call of doMyThing? Does that make
sense? lol

Probably it makes sense, but you should explain it to us. ;-)
Basically I want to store it and change it during each call...i'm
doing some async stuff and need it to change each time it's
called....

thanks!

Could you please give a complete example of what the input and output
values of the whole process are?


AZ
 
H

Harry

Jason Hartsoe said:
I have a sub routine that's passing in a variable. I need to take that
variable and store it globally...but here's what's happening.

ex: I'm executing my routine: doMyThing(path, "test")
I'm executing that command at least 10 times replacing the word test with
my
next object. When im receving that variable:
Sub doMyThing(ByVal Path As String, ByVal other As String)
I can use my variable...now how can I take that variable from this sub and
pass it to another sub? Is there a way to store that variable or set
during
each call of doMyThing? Does that make sense? lol

Basically I want to store it and change it during each call...i'm doing
some
async stuff and need it to change each time it's called....

thanks!
Don't know if I understand you correctly, but you may be looking for a
Static variable. Static variables hold their values between calls to a
method.
 
M

Mr. Arnold

Jason Hartsoe said:
I have a sub routine that's passing in a variable. I need to take that
variable and store it globally...but here's what's happening.

ex: I'm executing my routine: doMyThing(path, "test")
I'm executing that command at least 10 times replacing the word test with
my
next object. When im receving that variable:
Sub doMyThing(ByVal Path As String, ByVal other As String)
I can use my variable...now how can I take that variable from this sub and
pass it to another sub? Is there a way to store that variable or set
during
each call of doMyThing? Does that make sense? lol

Basically I want to store it and change it during each call...i'm doing
some
async stuff and need it to change each time it's called....

thanks!

Public HoldOther as string.

HoldOther = "Help"


doMything(path, HoldOther)


doMyThing(byval ppath as string byref pholdother as string)

dowhaterver

pholderother = "Help Me" -- and HoldOther should contain "Help Me"


I don't know if that's what you're looking for or not, well you can get
away with in C#.
 
C

Cor Ligthert[MVP]

Mr. Arnold,

Sorry but I am curious what you mean by this sentence, I don't understand
why it is added to your message?

I don't know if that's what you're looking for or not, well you can get
away with in C#.


Cor
 
J

Jason Hartsoe

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
 
J

Jason Hartsoe

I believe i figured it out by doing the following...is this proper? or a
better way?

Public Shared ImgTypes As String
Public Shared ImgExt As String
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ReadXML()

ImgTypes = "HIGHRESJPG"
ReadFiles(myPPath, "HIGHRESJPG")
ImgTypes = "MEDRESJPG"
ReadFiles(myPPath, "MEDRESJPG")


End
End Sub
 
A

Armin Zingler

Jason Hartsoe said:
I believe i figured it out by doing the following...is this proper?
or a better way?

Public Shared ImgTypes As String
Public Shared ImgExt As String
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
ReadXML()

ImgTypes = "HIGHRESJPG"
ReadFiles(myPPath, "HIGHRESJPG")
ImgTypes = "MEDRESJPG"
ReadFiles(myPPath, "MEDRESJPG")


End
End???


End Sub

I looked at the code above and I took your code from the previous
message and made it compilable, and had a look at the inline comment.
However, I'm still not sure what you're trying.

I _guess_ that the problem is the following:
The sub OnReadDone is executed asynchronusly. Right? You want to pass
information to OnReadDone. It's a different String each time, and you
don't know how to pass it. If this is correct, you can add another
property to the StateObj class, set it to any value and get the value
inside OnReadDone.

I didn't evaluate the whole concept of the task, but aren't you reading
several files in different threads? This would slow down the whole
process compared to reading them sequentially.

Setting "ImgTypes" as you've shown above will probably fail due to
asynchronous execution.


AZ
 
M

Mr. Arnold

Cor Ligthert said:
Mr. Arnold,

Sorry but I am curious what you mean by this sentence, I don't understand
why it is added to your message?

The times I have tied to ref a variable was in C# recently where you have to
add MyMethod(ref myvar)

And then you had to do this MyMethod(ref string pmyvar). I have not tried it
in VB. My main language in .Net that I use is C#, although I have used
VB.net at client sites and used VB6 for many years. My recollection was from
VB6 on the Ref.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top