473,659 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1168
"Jason Hartsoe" <Ja**********@d iscussions.micr osoft.comschrie b
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**********@d iscussions.micr osoft.comwrote in message
news:54******** *************** ***********@mic rosoft.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**********@d iscussions.micr osoft.comwrote in message
news:54******** *************** ***********@mic rosoft.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(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'To Insert start up code here.
ReadXML()
ProcessTree(myP Path)
ReadFiles(myPPa th, "HIGHRES")
ReadFiles(myPPa th, "MEDRES")
ReadFiles(myPPa th, "LOWRES")
End
End Sub

Public Sub ReadFiles(ByVal path As String, ByVal imgtype As String)
Dim di As New IO.DirectoryInf o(path & imgtype & "\")
Dim ImgExt As String
If imgtype = "HIGHRES" Then
ImgExt = "*.jpg"
Else
ImgExt = "*.*"
End If
Dim diar1 As IO.FileInfo() = di.GetFiles(Img Ext)
Dim dra As IO.FileInfo
For Each dra In diar1
ReadData(dra.Fu llName)
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.fi le = New System.IO.FileS tream(Path,
IO.FileMode.Ope n)

Catch ex As System.Unauthor izedAccessExcep tion
Exit Sub
Catch ex As System.IO.IOExc eption
Exit Sub
End Try

'Debug.WriteLin e(Now & " Read Start: " &
Path.Substring( InStrRev(Path, "\")))
'Begin Write to write all images to memory then output to directories
ReDim tempStateObj.re tData(Convert.T oInt32(tempStat eObj.file.Lengt h))
tempStateObj.fi le.BeginRead(te mpStateObj.retD ata, 0,
Convert.ToInt32 (tempStateObj.f ile.Length), AddressOf OnReadDone, tempStateObj)

End Sub

Public Sub OnReadDone(ByVa l ar As IAsyncResult)
Dim state As StateObj = CType(ar.AsyncS tate, StateObj)
Dim bytesRecieved As Int32 = state.file.EndR ead(ar)

Debug.WriteLine (Now & " Read Done: " &
state.file.Name .Substring(InSt rRev(state.file .Name, "\")))

state.file.Clos e()
Dim RetNum As String
RetNum = ReturnNumbersOn ly(state.file.N ame)
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.Exist s(mySPath & ReNum3) Then
'Debug.WriteLin e(mySPath & "already exists")
Else
Directory.Creat eDirectory(mySP ath & ReNum3)
End If
Try
'--Open up a new file to write to

state.file = New System.IO.FileS tream(mySPath & ImgTypes & "\" &
ReNum3 & "\" & state.file.Name .Substring(InSt rRev(state.file .Name, "\")),
FileMode.Create )
'
Catch Ex As Exception
'MsgBox(Ex.Mess age)
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(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ReadXML()

ImgTypes = "HIGHRESJPG "
ReadFiles(myPPa th, "HIGHRESJPG ")
ImgTypes = "MEDRESJPG"
ReadFiles(myPPa th, "MEDRESJPG" )
End
End Sub
Jun 27 '08 #7
"Jason Hartsoe" <Ja**********@d iscussions.micr osoft.comschrie b
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(By Val sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
ReadXML()

ImgTypes = "HIGHRESJPG "
ReadFiles(myPPa th, "HIGHRESJPG ")
ImgTypes = "MEDRESJPG"
ReadFiles(myPPa th, "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******** *************** ***********@mic rosoft.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.c omschreef in bericht
news:eG******** ******@TK2MSFTN GP05.phx.gbl...
>
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:24******** *************** ***********@mic rosoft.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
2559
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. What I want to do is calculate this temperature in the UDF on the first pass and store it somewhere (table, global variable etc.). On every execution after that I'd like to use the value stored so I don't have to recalculate the value again for...
6
2564
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 "SEGV" when run (presumably - attempt to delete deleted memory. Please take a look and see if you can notice any mistakes I'm making. Basically, I want to store classes of my objects in a vector. I also have three further questions:
12
3935
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
2024
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 tell, it should work but it doesn't. Can someone tell me where I went wrong? <html><head> <title>Form Test</title> <script language="JavaScript> <!-- function copy(){
2
1736
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 would be to create a static class and static variables inside of that. But if more then one person was using the page would they be using the same variables? Or do they get a version of the static class each? I dont know, which is why I ask. jax
2
1703
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 recreate new connections every time they load. I noticed during development that when ever the app first started, the connection would not be in Session when I navigvated to a page that used it. But with subsequent calls everything would be fine and...
12
4964
by: Alex D. | last post by:
is it possible? pros and cons?
22
2538
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' account and submitted them under that, but this makes it harder to print lists of all the reviews by one person, so ideally I wanna make a multiple select form so we can just select all the contributors and have the values saved in the database - in...
9
7287
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 be 'better' to store an instance of this class in a session-variable, so it's available all the time and needs to be instanced only once. Is this, generally speaking, a good idea, storing objects in session-variables ? Do you guys ever use this...
4
12589
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 'System.Collections.ArrayList' to 'string'"
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.