Results 1 to 5 of 5

Thread: save value as variable

  1. #1

    Thread Starter
    Addicted Member stealmysanity's Avatar
    Join Date
    Oct 2001
    Location
    THELANDOFRULERS
    Posts
    165

    save value as variable

    Hi I want the value of the progress bar t obe saved as a variable the second time a user clicks the button, please help! HERES MY CODE:
    [Highlight=VB]
    Command1.Caption = "Stop the strength O' meter"
    Static Quit As Boolean
    Dim i As Integer
    Dim t As Integer
    Quit = Not Quit
    If Quit = False Then Exit Sub
    i = 1
    Do Until Quit = False
    DoEvents
    If t = 800 Then
    ProgressBar2.Value = ProgressBar2.Value + i
    If ProgressBar2.Value = ProgressBar2.Max Or ProgressBar2.Value = ProgressBar2.Min Then i = -i
    t = 0
    End If
    t = t + 1
    Loop
    strength = ProgressBar2.Value
    Command1.Enabled = False
    everything is made of carbon, except some stuff!!BTW LOOK AT ME PROFILE!!

  2. #2
    hellswraith
    Guest
    You can create a global variable in the General Dec section to hold the value. The value won't change throughout the running of the app unless you change it.

  3. #3
    hellswraith
    Guest
    Or, as a static variable. This is from the MSDN library:


    You can preserve the value of a local variable by making the variable static. Use the Static keyword to declare one or more variables inside a procedure, exactly as you would with the Dim statement:

    Static Depth

    For example, the following function calculates a running total by adding a new value to the total of previous values stored in the static variable Accumulate:

    Function RunningTotal(num)
    Static ApplesSold
    ApplesSold = ApplesSold + num
    RunningTotal = ApplesSold
    End Function

    If ApplesSold was declared with Dim instead of Static, the previous accumulated values would not be preserved across calls to the function, and the function would simply return the same value with which it was called.

  4. #4
    Megatron
    Guest
    Personally, I would use a static variable (instead of a module-level variable) if you just need it in this sub routine.

  5. #5

    Thread Starter
    Addicted Member stealmysanity's Avatar
    Join Date
    Oct 2001
    Location
    THELANDOFRULERS
    Posts
    165

    how

    can i do that , btw i just tell you im dumb now so dont make fun of me
    everything is made of carbon, except some stuff!!BTW LOOK AT ME PROFILE!!

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