Results 1 to 6 of 6

Thread: Using a dimmed integer on a different sub..

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210

    Using a dimmed integer on a different sub..

    How would I refer to a dimmed integer on a different sub?

    I have a button that generates a random number.

    I have another button that compares the number with another user-defined number. But I can't figure out how to compare the dimmed integer on a different sub with the user-defined integer...
    Last edited by nahya^^; Oct 28th, 2002 at 05:07 PM.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you have to fix that bad VB6 habit of expecting the Default property to always be .Text



    If txtGuess.Text < GuessNum Then


    you may also need to cast to integer . The above Might work alone though..but if not...

    If CInt(txtGuess.Text) < Guessnum
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210
    Oops. I was late.

    But I have another problem...

    I made another button that regenerates the number for the user to guess.

    So I dimmed it as an integer, randomly generated the number.

    But I want to use that dimmed integer on another sub. How can I do that?
    Last edited by nahya^^; Oct 28th, 2002 at 04:54 PM.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    hard habit to break since VB6 expected .Text when you did that..

    VB.NET is not as nice

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    210
    Any help on my new question?
    (I edited out my old question that's already been answered.)

    Thanks in advance.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Declare it at the form level and then just assign it a value in the sub or use a function.

    VB Code:
    1. Public Class Form1
    2.  
    3. 'auto generated stuff here
    4.  
    5. 'main block of code
    6. dim returnvalue as integer=GenerateRandom()
    7. CompareRandom(returnvalue,othernumber)
    8.  
    9. 'convert subs to functions
    10. Public Function GenerateRandom() as Integer
    11.   Return Int(rnd)
    12. end Function
    13.  
    14. Public Sub CompareRandom(orig as integer,user as integer)
    15.   If orig>user then Whatever
    16. end Sub

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