CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: NEED HELP

  1. #1
    Join Date
    May 2001
    Posts
    1

    NEED HELP

    Im new at doing this Vb and im not understanding the variables to well. I have to code the square root button so that it calculates and displays the square root of a whole number. I have to assign a numeric equivalent of the txtNumber.text property to an integer variable. And assign the square root to a single variable. All using the Sqr function to calculate. Can anyone help me with this? And try and explain to me how to get to remember all the variables? I really appreciate any help Thankyou.


  2. #2
    Join Date
    May 2001
    Location
    Russia
    Posts
    200

    Re: NEED HELP

    i = Sqr(txtNumber.Text)



    After this variable i contents needed value.

    Andy Tower

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: NEED HELP

    ...and (read tower answer, first) you may want to put it under the click event of a command button. So, add a command button to your form, change its name to cmdSquare (just for better understanding), then double click on it, and you will have the place where to put Tower code
    Private Sub cmdSquare_click()
    'codes go here
    Dim i As Integer
    'check if it is a number
    If IsNumeric(text1.Text) Then
    'make some conversions: sqr expect a double
    'while text1 is a string
    'while i is integer.
    'Vb will do it for you, but you may want
    'to set it manually. Look at differences between
    'Cint and Int functions about rounding numbers...
    i = CInt(Sqr(CDbl(text1.Text)))
    '..do what you need with i
    Else
    MsgBox "You did not insert a number in TextBox"
    End If
    End Sub

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: NEED HELP

    whoops, made a mistake!
    dim i as integer is not correct, you spoike about a single variable!
    substitute it with
    dim sngNumber as single
    and instead of
    i= =cint(...
    write
    sngNumber=CSng(...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured