Results 1 to 5 of 5

Thread: sounding like a newbie...

  1. #1

    Thread Starter
    Member choochoo's Avatar
    Join Date
    Jun 2001
    Posts
    51

    Unhappy sounding like a newbie...

    i know i sound like a complete newbie right now, but i've been wondering why this doesnt work for a while

    it just basically adding 1 to a variable each time...but for some reason, it doesnt...

    ive tried in a timer, loop, and for/next statement.

    all i want to do is some like

    Code:
    Dim X As Integer
    X = X + 1
    and make it return a new number every second(or whatever the case is: timer, for/next, etc...)

    So why doesnt this work?

    im feeling pretty stupid right now, so thanks to anyone who can correct the stupid error im making. any posts are appreciated. thanks.

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    You have to give it a value first. You can't just say:

    Dim x
    x = x + 1

    because the computer won't know what the value of x is, and therefore can't add to it.
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Try this...

    choochoo, I would reccomend either of the following.

    Using a timer...
    Code:
    Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    Static x As Integer
    
    x = x + 1
    Debug.Print x
    
    End Sub
    Using a public variable...
    Code:
    Public x As Integer
    
    Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    
    x = x + 1
    Debug.Print x
    
    End Sub
    Hope this helps!
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  4. #4

    Thread Starter
    Member choochoo's Avatar
    Join Date
    Jun 2001
    Posts
    51
    thanks for replying to my post.

    wynd, i had tried setting its value before, that hadnt worked either :\

    Digtal-X-Treme, yes that did help, thanks alot.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    // heres a simple loop that prints out the integer values 1 to 10
    // in Java.
    // just to show an example of what you are trying to acheive.
    // in another language.


    public class Test{
    public static void main(String[] args){

    int i = 0; // automatic variable
    // ie.. local to the method block

    while(i != 10){
    i = i + 1;
    System.out.println(" The value of i is: " + i);
    }

    }
    }

    you were doing the right thing i just think you were not doing the timer part properly. From what i remember of VB, variables are
    automatically initialized. Good Luck!!!

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