Results 1 to 3 of 3

Thread: Few questions.

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Few questions.

    Is there no Instr fucntion for VB 2005, if not would this roughly do the trick, havent' tested it?

    VB Code:
    1. Private Function Instr(byval TargetString as String, byval StringToFind as string) as Boolean
    2.  
    3. For i as integer = 1 to TargetString.length
    4.  
    5.   If not StringToFind.length + i > TargetString.length then
    6.   If TargetString.substring(i,StringToFind.length) <> string.empty then
    7.  
    8.     return true
    9.     exit for
    10.  
    11.   End if
    12.   End if
    13.  
    14. Next
    15.  
    16. End Function


    I looks like you dispose of objects now which completly erases them from memory, so what is the need for a
    VB Code:
    1. set myObj = nothing
    ?

    have they done away with API Dec's you just use Import now right as in C++ ?

  2. #2
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: Few questions.

    To your first question,

    you have the method IndexOf of the class string, that is overloaded in order to get more functionallity than with instr

    The objects thats need to be disposed have a method call Dispose that free the resources used for this object.

    Setting the variable that points to your object to nothing only do that, not free any resource, just makes your variable points to nothing.

    hope this helps
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Few questions.

    To elaborate on memory and resource management, setting a variable to Nothing and disposing an object are completely different and neither erases the object from memory.

    The purpose of a Dispose method is to release unmanaged resources. That includes things like window handles for forms and controls, file handles for streams, etc. Because the .NET Framework manages memory automatically, objects may sit around in memory for some time after their usefulness has ended. Having those objects tie up valuable system resources is wasteful, so calling Dispose releases the resources immediately.

    Setting a variable to Nothing removes that reference to the object from the system. Once there are no remaining references to an object it becomes eligible for garbage collection. The next time the garbage collector is invoked the memory that that object occupied can be reclaimed.

    Setting a variable to Nothing is usually pointless in VB.NET. If the variable loses scope immediately or soon then the reference will be removed then anyway. You would only set a variable to Nothing if you have no further use for the object it refers to and the variable will not or may not lose scope fro some time. Note that setting a value type variable to Nothing is always pointless.

    If you don't dispose an object that supports it, when the garbage collector comes to clean up that object it will be unable to. It must invoke the object's Finalize method to release its resources and then the object will remain in memory until the garbage collector makes another pass.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width