Results 1 to 15 of 15

Thread: Newbie help..please?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Newbie help..please?

    Alrite so Im doing this assignmen for class, and I think im headed in the right direction, but I know im missing something important and the program isnt working so...I was hoping you could send me in the right direction...

    So heres the program form..


    The whole idea is to enter numbers into the enterbox, and when the "largest" button is clicked, the largest of all the numbers that you entered would be displayed in the picturebox corresponding with the largest button. We must do this using If statements...heres what ive got so far..no laughing, i'm new to this.


    Dim largest As Integer
    Dim holder As Integer
    __________________________________
    Private Sub EnterButton_Click()

    If EnterBox > holder Then
    EnterBox = largest
    Else: EnterBox = holder

    End If

    End Sub
    __________________________________
    Private Sub LargestButton_Click()
    LargestBox.Print largest
    End Sub


    Any light you can shed on the subject would be greatly appreciated! thanks

  2. #2
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Newbie help..please?

    How many numbers are you going to compare?

  3. #3
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Newbie help..please?

    Code:
    Private Sub Command1_Click()
    Dim largest As Integer
    Dim holder As Integer
    
    If enterbox < holder Then
    largest = holder
    Else
    largest = enterbox
    End If
    
    largestbox.Text = Str(largest)
    
    End Sub
    Does this work?

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Newbie help..please?

    no, this doesnt work!

    Im guessing im looking to compare an unlimited amount of numbers..

    When i click the enterbutton, the corresponding textbox automatically changes to a 0, and then when I click the largest button, the picturebox shows a 0 there also...
    Last edited by tryon; Mar 28th, 2007 at 03:27 PM.

  5. #5
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Newbie help..please?

    It worked for me, assuming you've got a textbox whose value goes to largest and a textbox whose value goes to holder.

    For example my code that's working right now is this:

    Code:
    Private Sub Command1_Click()
    Dim largest As Integer
    
    
    If Val(Text1) < val(Text2) Then
    largest = Val(Text2)
    Else
    largest = Val(Text1)
    End If
    
    Label2 = Str(largest)
    
    End Sub
    That's assuming you're only going to compare 2 numbers. If you're going to compare more then I think you'd need an array.
    Last edited by pukisoft; Mar 28th, 2007 at 03:48 PM.

  6. #6
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Newbie help..please?

    okay, I don't want to help too much because this is an assignment...
    If Val(enterbox.text) > Largest then Largest = Val(enterbox.text)

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Newbie help..please?

    Oh woops, didnt see you changed up the code a little bit at the end....sorry. Ill check that out! thanks for all the help!

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Newbie help..please?

    Alrite thanks again for all the help! Heres what ive got now and it seems to be working very well.

    Dim largest As Integer
    __________________________________

    Private Sub EnterButton_Click()
    LargestButton.Enabled = True

    If Val(EnterBox.Text) > largest Then
    largest = Val(EnterBox.Text)
    End If

    End Sub
    __________________________________
    Private Sub LargestButton_Click()
    LargestBox.Cls
    LargestBox.Print largest
    End Sub

  9. #9
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Newbie help..please?

    My code was wrong. I had to use the val function or numbers greater than 9 don't calculate alright. Sorry.

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    8

    Re: Newbie help..please?

    No problems, any help is good help. I was getting frustrated. This visual basic stuff is almost kindof fun when everything works out in the end haha

  11. #11
    Junior Member
    Join Date
    Jan 2007
    Posts
    29

    Re: Newbie help..please?

    From what I could make of the question he needs to have the largest number displayed only when the LARGEST button is clicked. You enter a number into the first text box and then press ENTER, repeat as often as you like. Then hitting the LARGEST button would sort through all the values entered and display the largest of the lot. The codes added so far are only depending on using the ENTER button. I don't know how to sort through arrays though......I'm an absolute beginner at visual basic.......

  12. #12
    Junior Member
    Join Date
    Jan 2007
    Posts
    29

    Re: Newbie help..please?

    Ignore me! I copied tryon's code but shortened it slightly to:

    Option Explicit
    Dim intlargest As Integer


    Private Sub Command1_Click()

    If Val(Text1.Text) > intlargest Then
    intlargest = Val(Text1.Text)
    End If

    End Sub

    Private Sub Command2_Click()
    Text2.Text = intlargest

    End Sub

  13. #13
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Newbie help..please?

    Quote Originally Posted by winterlight
    Ignore me! I copied tryon's code but shortened it slightly to:

    Option Explicit
    Dim intlargest As Integer


    Private Sub Command1_Click()

    If Val(Text1.Text) > intlargest Then
    intlargest = Val(Text1.Text)
    End If

    End Sub

    Private Sub Command2_Click()
    Text2.Text = intlargest

    End Sub
    There I think that if intlargest happens to be less then the value of text1 it'll return a 0. You need to set another condition.

  14. #14
    Junior Member
    Join Date
    Mar 2007
    Posts
    23

    Re: Newbie help..please?

    Private Sub Command2_Click()
    Text2.Text = intlargest

    End Sub
    I wouldnt even bother with the second button. Just put the code for the second button in the first buttons code so it updates automatically.

    Code:
    Option Explicit
    Dim intLargest
    
    Private Sub Command1_Click()
    
    
    If Val(Text1.Text) > intLargest Then
      intLargest = Val(Text1.Text)
    End If
    
    Text2.Text = intLargest
    End Sub
    
    Private Sub Form_Load()
    intLargest = 0
    End Sub

  15. #15
    Lively Member
    Join Date
    Mar 2007
    Posts
    124

    Re: Newbie help..please?

    Assign the first value to a variable. Compare if larger to the newly entered value. If larger the reassign it to the previous variable.

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