Results 1 to 12 of 12

Thread: squred

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    squred

    in a visual basic function how do I square something like

    cnsquared

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: squred

    2^2 = 4
    3^2 = 9
    4^2 = 16
    5^2 = 25
    ...
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: squred

    Thanks for helping

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: squred

    x = y ^ 2
    Or use the Math.Pow function
    x = Math.Pow(y, 2)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: squred

    cool how do I then create a global variable

    I want to store the answer in a global variable

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: squred

    How global do you mean? You could add a module to your project, and make a public variable in the module. That variable would be visible to the whole project. However, it is generally good practice to limit visibility to only those parts that actually need to see it, so globals are not used all that much.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: squred

    Well if I save a sum as answer and I want to display it on the next form what is the best way I can do that

  8. #8
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: squred

    Yea... if you have in your form:

    Code:
    Public Class Form1
        Dim blah as Integer
    
    End Class
    Then "blah" will be seen to everything in Form1, and that's good enough for 99.9% of things.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  9. #9
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: squred

    If you want to send it to another form, then make a Property on that form and send it over, here's Form1:

    Code:
    Public Class Form1
        Dim _blah As Integer
    
        Private Sub MakeForm2()
            Dim f As New Form2
            f.Blah = _blah
            f.Show()
    
        End Sub
       
    End Class
    Here's Form2:
    Code:
    Public Class Form2
        Dim _blah As Integer
    
        Public Property Blah() As Integer
            Get
                Return _blah
            End Get
            Set(ByVal value As Integer)
                _blah = value
            End Set
        End Property
    
    End Class
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: squred

    A global is the easiest.

    The major issue people are dealing with concerning globals is that any part of a program can change a global, so you have the problem that the name of the variable could conflict (if you don't keep track of what names you have for variables), and the state of the global could be changed by other parts of a program. In many programs, especially smaller ones, the first issue is unlikely to be a problem, and the second issue won't be a problem.

    However, it's not a good habit to get into. If the sum is calculated on one form, and you want to display it on another form, there are many options you can choose from:

    If the second form is not created until after the sum has been calculated, then you can either add a custom constructor to the new form that takes the sum as an argument, or you can put a WriteOnly property on the new form that accepts the sum and shows it, or you can expose the sum via a property on the first form, though this could be much more difficult. In addition to those, you can simply add the sum to a control when you create the second form.

    If the second form already exists when the sum is generated, then if the second form is visible to the first form, you can either add a WriteOnly property to the second form, or you can add the sum as a string directly to a control.
    My usual boring signature: Nothing

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: squred

    Boy was I slow.
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: squred

    Alright cause normally to pass variables to another form I create a variable on the form I want to pass it to and say the variable was username and the user entered their username in a text box on the prvious form i just say

    dim username = form1.username_txt

    so if the other way is better I wil have to start using it

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