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!

Re: Storing Variables by Armin

Armin
Thu May 08 15:45:44 CDT 2008

"Jason Hartsoe" <JasonHartsoe@discussions.microsoft.com> schrieb
> 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


Re: Storing Variables by Harry

Harry
Thu May 08 16:04:51 CDT 2008

"Jason Hartsoe" <JasonHartsoe@discussions.microsoft.com> wrote in message
news:5453D57A-EAC4-4668-9C5F-DE1DC949B3E9@microsoft.com...
>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.



Re: Storing Variables by Mr

Mr
Thu May 08 17:52:55 CDT 2008



"Jason Hartsoe" <JasonHartsoe@discussions.microsoft.com> wrote in message
news:5453D57A-EAC4-4668-9C5F-DE1DC949B3E9@microsoft.com...
>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#.


Re: Storing Variables by Cor

Cor
Fri May 09 02:56:22 CDT 2008

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


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

RE: Storing Variables by JasonHartsoe

JasonHartsoe
Fri May 09 08:50:05 CDT 2008

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

Re: Storing Variables by Armin

Armin
Fri May 09 09:41:22 CDT 2008

"Jason Hartsoe" <JasonHartsoe@discussions.microsoft.com> schrieb
> 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


Re: Storing Variables by Mr

Mr
Fri May 09 13:22:01 CDT 2008


"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:24841633-E39C-44EB-8444-DE5D8990D552@microsoft.com...
> 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#.
>
>

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.


Re: Storing Variables by Cor

Cor
Fri May 09 23:32:22 CDT 2008

The rules around

C# "ref" and VB "ByRef" are exactly the same

Cor

"Mr. Arnold" <MR. Arnold@Arnold.com> schreef in bericht
news:eG8DZGgsIHA.4952@TK2MSFTNGP05.phx.gbl...
>
> "Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
> news:24841633-E39C-44EB-8444-DE5D8990D552@microsoft.com...
>> 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#.
>>
>>
>
> 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.