Empty a Static value


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Empty a Static value

  1. #1
    Steve Guest

    Empty a Static value


    I have a value assigned as Static in a module like this

    Private Sub txtRental_KeyPress(KeyAscii As Integer)
    Static ValueA
    ...

    End sub

    I would like to set ValueA to empty or 0 before the
    program is terminated but doesn't know how to do it.
    Does anyone know a way to set the ValueA to nothing before the program ends.

    Thanks for your help,
    Steve

  2. #2
    Dean Earley Guest

    Re: Empty a Static value

    As it is a variant, just do:
    ValueA = Empty

    If it is an object, try:
    Set ValueA = Nothing

    --
    Dean Earley (dean.earley@icode.co.uk)
    Assistant Developer

    iCode Systems
    "Steve" <SGilleary@yahoo.com> wrote in message news:3be94c7a$1@147.208.176.211...
    >
    > I have a value assigned as Static in a module like this
    >
    > Private Sub txtRental_KeyPress(KeyAscii As Integer)
    > Static ValueA
    > ..
    >
    > End sub
    >
    > I would like to set ValueA to empty or 0 before the
    > program is terminated but doesn't know how to do it.
    > Does anyone know a way to set the ValueA to nothing before the program ends.
    >
    > Thanks for your help,
    > Steve




  3. #3
    Arthur Wood Guest

    Re: Empty a Static value


    "Steve" <SGilleary@yahoo.com> wrote:
    >
    >I have a value assigned as Static in a module like this
    >
    >Private Sub txtRental_KeyPress(KeyAscii As Integer)
    >Static ValueA
    >...
    >
    >End sub
    >
    >I would like to set ValueA to empty or 0 before the
    >program is terminated but doesn't know how to do it.
    >Does anyone know a way to set the ValueA to nothing before the program ends.
    >
    >Thanks for your help,
    >Steve

    What is it about that Static value that you want to change? and When?

    The fact that a variable is static simply means that the value of that variable
    is Preserved from one call to your Sub to the Next. It does NOT prevent
    you from setting the variable to whatever value you want, at any point in
    the execution od that sub. for instance, if you wnat it to count up to 10,
    and then start over back at 0:


    Private Sub MySub()
    Static CallCount as Integer
    if CallCount = 10 then
    CallCount = 0
    end if
    CallCount = CallCount + 1
    End Sub

    the very first time the sub is called, CallCOunt (being an Integer) defaults
    to 0, and is then incremented each time the Sub is executed. At some point,
    Callcount will reach the value 10, and the If test will then cause it to
    be reset, back to 0, to start over again.

    Is this what you are asking about?

    Arthur Wood



  4. #4
    Daryl Muellenberg Guest

    Re: Empty a Static value

    If the program is ending, why would you care what the value of ValueA is?
    When you restart the program, ValueA will reinitialize automatically.

    But if you really want to reset this value, in the form unload event, set
    your form to nothing (Set Form1 = Nothing), which will clear all variables
    associated with the form.

    Daryl

    "Steve" <SGilleary@yahoo.com> wrote in message
    news:3be94c7a$1@147.208.176.211...
    >
    > I have a value assigned as Static in a module like this
    >
    > Private Sub txtRental_KeyPress(KeyAscii As Integer)
    > Static ValueA
    > ..
    >
    > End sub
    >
    > I would like to set ValueA to empty or 0 before the
    > program is terminated but doesn't know how to do it.
    > Does anyone know a way to set the ValueA to nothing before the program

    ends.
    >
    > Thanks for your help,
    > Steve




  5. #5
    Steve Guest

    Re: Empty a Static value


    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >"Steve" <SGilleary@yahoo.com> wrote:
    >>
    >>I have a value assigned as Static in a module like this
    >>
    >>Private Sub txtRental_KeyPress(KeyAscii As Integer)
    >>Static ValueA
    >>...
    >>
    >>End sub
    >>
    >>I would like to set ValueA to empty or 0 before the
    >>program is terminated but doesn't know how to do it.
    >>Does anyone know a way to set the ValueA to nothing before the program

    ends.
    >>
    >>Thanks for your help,
    >>Steve

    > What is it about that Static value that you want to change? and When?
    >
    >The fact that a variable is static simply means that the value of that variable
    >is Preserved from one call to your Sub to the Next. It does NOT prevent
    >you from setting the variable to whatever value you want, at any point in
    >the execution od that sub. for instance, if you wnat it to count up to

    10,
    >and then start over back at 0:
    >
    >
    >Private Sub MySub()
    >Static CallCount as Integer
    > if CallCount = 10 then
    > CallCount = 0
    > end if
    > CallCount = CallCount + 1
    >End Sub
    >
    >the very first time the sub is called, CallCOunt (being an Integer) defaults
    >to 0, and is then incremented each time the Sub is executed. At some point,
    >Callcount will reach the value 10, and the If test will then cause it to
    >be reset, back to 0, to start over again.
    >
    >Is this what you are asking about?
    >
    >Arthur Wood

    Basically, I want to be able to clear out the text value txtRental and re-enter

    another value into the txtRental before the program ends.
    For example, at the cmdClear_click():
    I need to set ValueA to nothing or empty out the last values and re-enter

    new value without the carrying over values.
    txtRental.text = 0 wouldn't work here, as I tried.




  6. #6
    Arthur Wood Guest

    Re: Empty a Static value


    Steve,
    if you are only doing this "before the program ends" then why worry about
    what value txtRental has?


    Now are you refering to a value, in a TextBox control? (txtRental appears
    to be the name of a TextBox Control).

    Exacty what is the program attempting to do? Do you, perhaps, have a Bound
    control (that is the textbox is bound to a field in you database)?



    "Steve" <SGillerary@yahoo.com> wrote:
    >
    >"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>
    >>"Steve" <SGilleary@yahoo.com> wrote:
    >>>
    >>>I have a value assigned as Static in a module like this
    >>>
    >>>Private Sub txtRental_KeyPress(KeyAscii As Integer)
    >>>Static ValueA
    >>>...
    >>>
    >>>End sub
    >>>
    >>>I would like to set ValueA to empty or 0 before the
    >>>program is terminated but doesn't know how to do it.
    >>>Does anyone know a way to set the ValueA to nothing before the program

    >ends.
    >>>
    >>>Thanks for your help,
    >>>Steve

    >> What is it about that Static value that you want to change? and When?
    >>
    >>The fact that a variable is static simply means that the value of that

    variable
    >>is Preserved from one call to your Sub to the Next. It does NOT prevent
    >>you from setting the variable to whatever value you want, at any point

    in
    >>the execution od that sub. for instance, if you wnat it to count up to

    >10,
    >>and then start over back at 0:
    >>
    >>
    >>Private Sub MySub()
    >>Static CallCount as Integer
    >> if CallCount = 10 then
    >> CallCount = 0
    >> end if
    >> CallCount = CallCount + 1
    >>End Sub
    >>
    >>the very first time the sub is called, CallCOunt (being an Integer) defaults
    >>to 0, and is then incremented each time the Sub is executed. At some point,
    >>Callcount will reach the value 10, and the If test will then cause it to
    >>be reset, back to 0, to start over again.
    >>
    >>Is this what you are asking about?
    >>
    >>Arthur Wood

    >Basically, I want to be able to clear out the text value txtRental and re-enter
    >
    >another value into the txtRental before the program ends.
    >For example, at the cmdClear_click():
    >I need to set ValueA to nothing or empty out the last values and re-enter
    >
    >new value without the carrying over values.
    >txtRental.text = 0 wouldn't work here, as I tried.
    >
    >
    >



  7. #7
    Media Lint Guest

    Re: Empty a Static value


    I'm as confused as all the rest as to what you want to do this for. I can
    only presume that since you are responding to keypress events you are probably
    writing some data or otherwise storing something-or-other and you want to
    make sure that the last thing you store/write is something like a null character
    or what not.

    If so, just call the event!

    txtRental_KeyPress 0




    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >Steve,
    > if you are only doing this "before the program ends" then why worry

    about
    >what value txtRental has?
    >
    >
    >Now are you refering to a value, in a TextBox control? (txtRental appears
    >to be the name of a TextBox Control).
    >
    >Exacty what is the program attempting to do? Do you, perhaps, have a Bound
    >control (that is the textbox is bound to a field in you database)?
    >
    >
    >
    >"Steve" <SGillerary@yahoo.com> wrote:
    >>
    >>"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>>
    >>>"Steve" <SGilleary@yahoo.com> wrote:
    >>>>
    >>>>I have a value assigned as Static in a module like this
    >>>>
    >>>>Private Sub txtRental_KeyPress(KeyAscii As Integer)
    >>>>Static ValueA
    >>>>...
    >>>>
    >>>>End sub
    >>>>
    >>>>I would like to set ValueA to empty or 0 before the
    >>>>program is terminated but doesn't know how to do it.
    >>>>Does anyone know a way to set the ValueA to nothing before the program

    >>ends.
    >>>>
    >>>>Thanks for your help,
    >>>>Steve
    >>> What is it about that Static value that you want to change? and When?
    >>>
    >>>The fact that a variable is static simply means that the value of that

    >variable
    >>>is Preserved from one call to your Sub to the Next. It does NOT prevent
    >>>you from setting the variable to whatever value you want, at any point

    >in
    >>>the execution od that sub. for instance, if you wnat it to count up to

    >>10,
    >>>and then start over back at 0:
    >>>
    >>>
    >>>Private Sub MySub()
    >>>Static CallCount as Integer
    >>> if CallCount = 10 then
    >>> CallCount = 0
    >>> end if
    >>> CallCount = CallCount + 1
    >>>End Sub
    >>>
    >>>the very first time the sub is called, CallCOunt (being an Integer) defaults
    >>>to 0, and is then incremented each time the Sub is executed. At some

    point,
    >>>Callcount will reach the value 10, and the If test will then cause it

    to
    >>>be reset, back to 0, to start over again.
    >>>
    >>>Is this what you are asking about?
    >>>
    >>>Arthur Wood

    >>Basically, I want to be able to clear out the text value txtRental and

    re-enter
    >>
    >>another value into the txtRental before the program ends.
    >>For example, at the cmdClear_click():
    >>I need to set ValueA to nothing or empty out the last values and re-enter
    >>
    >>new value without the carrying over values.
    >>txtRental.text = 0 wouldn't work here, as I tried.
    >>
    >>
    >>

    >



  8. #8
    Steve Guest

    Re: Empty a Static value


    I got it figured out! Thank you to all.



    "Media Lint" <webmaster@magicdb.net> wrote:
    >
    >I'm as confused as all the rest as to what you want to do this for. I can
    >only presume that since you are responding to keypress events you are probably
    >writing some data or otherwise storing something-or-other and you want to
    >make sure that the last thing you store/write is something like a null character
    >or what not.
    >
    >If so, just call the event!
    >
    >txtRental_KeyPress 0
    >
    >
    >
    >
    >"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>
    >>Steve,
    >> if you are only doing this "before the program ends" then why worry

    >about
    >>what value txtRental has?
    >>
    >>
    >>Now are you refering to a value, in a TextBox control? (txtRental appears
    >>to be the name of a TextBox Control).
    >>
    >>Exacty what is the program attempting to do? Do you, perhaps, have a Bound
    >>control (that is the textbox is bound to a field in you database)?
    >>
    >>
    >>
    >>"Steve" <SGillerary@yahoo.com> wrote:
    >>>
    >>>"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>>>
    >>>>"Steve" <SGilleary@yahoo.com> wrote:
    >>>>>
    >>>>>I have a value assigned as Static in a module like this
    >>>>>
    >>>>>Private Sub txtRental_KeyPress(KeyAscii As Integer)
    >>>>>Static ValueA
    >>>>>...
    >>>>>
    >>>>>End sub
    >>>>>
    >>>>>I would like to set ValueA to empty or 0 before the
    >>>>>program is terminated but doesn't know how to do it.
    >>>>>Does anyone know a way to set the ValueA to nothing before the program
    >>>ends.
    >>>>>
    >>>>>Thanks for your help,
    >>>>>Steve
    >>>> What is it about that Static value that you want to change? and When?
    >>>>
    >>>>The fact that a variable is static simply means that the value of that

    >>variable
    >>>>is Preserved from one call to your Sub to the Next. It does NOT prevent
    >>>>you from setting the variable to whatever value you want, at any point

    >>in
    >>>>the execution od that sub. for instance, if you wnat it to count up

    to
    >>>10,
    >>>>and then start over back at 0:
    >>>>
    >>>>
    >>>>Private Sub MySub()
    >>>>Static CallCount as Integer
    >>>> if CallCount = 10 then
    >>>> CallCount = 0
    >>>> end if
    >>>> CallCount = CallCount + 1
    >>>>End Sub
    >>>>
    >>>>the very first time the sub is called, CallCOunt (being an Integer) defaults
    >>>>to 0, and is then incremented each time the Sub is executed. At some

    >point,
    >>>>Callcount will reach the value 10, and the If test will then cause it

    >to
    >>>>be reset, back to 0, to start over again.
    >>>>
    >>>>Is this what you are asking about?
    >>>>
    >>>>Arthur Wood
    >>>Basically, I want to be able to clear out the text value txtRental and

    >re-enter
    >>>
    >>>another value into the txtRental before the program ends.
    >>>For example, at the cmdClear_click():
    >>>I need to set ValueA to nothing or empty out the last values and re-enter
    >>>
    >>>new value without the carrying over values.
    >>>txtRental.text = 0 wouldn't work here, as I tried.
    >>>
    >>>
    >>>

    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center