Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2008

Tip: Looking for answers? Try searching our database.

Storing Variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Hartsoe - 08 May 2008 21:26 GMT
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!
Armin Zingler - 08 May 2008 21:45 GMT
> 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.
[quoted text clipped - 7 lines]
> 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
Harry - 08 May 2008 22:04 GMT
>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.
[quoted text clipped - 14 lines]
>
> 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.
Mr. Arnold - 08 May 2008 23:52 GMT
>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.
[quoted text clipped - 14 lines]
>
> 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#.
Cor Ligthert[MVP] - 09 May 2008 08:56 GMT
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
Mr. Arnold - 09 May 2008 19:22 GMT
> Mr. Arnold,
>
[quoted text clipped - 3 lines]
>> 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.
Cor Ligthert[MVP] - 10 May 2008 05:32 GMT
The rules around

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

Cor

>> Mr. Arnold,
>>
[quoted text clipped - 11 lines]
> VB.net at client sites and used VB6 for many years. My recollection was
> from VB6 on the Ref.
Jason Hartsoe - 09 May 2008 14:13 GMT
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
Jason Hartsoe - 09 May 2008 14:50 GMT
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
Armin Zingler - 09 May 2008 15:41 GMT
> I believe i figured it out by doing the following...is this proper?
> or a better way?
[quoted text clipped - 11 lines]
>
>        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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.