473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Storing Variables

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!
Jun 27 '08 #1
9 1159
"Jason Hartsoe" <Ja**********@discussions.microsoft.comschrieb
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

Jun 27 '08 #2
"Jason Hartsoe" <Ja**********@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.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.
Jun 27 '08 #3


"Jason Hartsoe" <Ja**********@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.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#.

Jun 27 '08 #4
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

Jun 27 '08 #5
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
Jun 27 '08 #6
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
Jun 27 '08 #7
"Jason Hartsoe" <Ja**********@discussions.microsoft.comschrieb
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

Jun 27 '08 #8

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:24**********************************@microsof t.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.

Jun 27 '08 #9
The rules around

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

Cor

"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:eG**************@TK2MSFTNGP05.phx.gbl...
>
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:24**********************************@microsof t.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.
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve D | last post by:
I've looked all over but can't find a solid answer. I've got a function that runs from a View and when the function runs the first time it is calculating a Temperature for a group of Formulas. ...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
2
by: Jax | last post by:
Say for example a user of my website makes a selection on the site and I want to store that value for use on a later page what is the best way to do that? My only method at the moment that I know...
2
by: Curt tabor | last post by:
Hi, I have several pages in my app that all use the same oleDBConnection(s). When this connection gets created, I store it as a Session variable so that other pages can access it w/o having...
12
by: Alex D. | last post by:
is it possible? pros and cons?
22
by: guitarromantic | last post by:
Hey everyone, I run a site with staff-submitted reviews, and most of them are written by one author. However, we also do "multiple" reviews. Up until now I just had a userid for a 'Multiple'...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
4
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.