|
-
Mar 28th, 2007, 02:54 PM
#1
Thread Starter
New Member
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
-
Mar 28th, 2007, 03:17 PM
#2
Addicted Member
Re: Newbie help..please?
How many numbers are you going to compare?
-
Mar 28th, 2007, 03:22 PM
#3
Addicted Member
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?
-
Mar 28th, 2007, 03:24 PM
#4
Thread Starter
New Member
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.
-
Mar 28th, 2007, 03:26 PM
#5
Addicted Member
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.
-
Mar 28th, 2007, 03:27 PM
#6
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)
-
Mar 28th, 2007, 03:29 PM
#7
Thread Starter
New Member
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!
-
Mar 28th, 2007, 03:43 PM
#8
Thread Starter
New Member
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
-
Mar 28th, 2007, 03:45 PM
#9
Addicted Member
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.
-
Mar 28th, 2007, 03:47 PM
#10
Thread Starter
New Member
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
-
Mar 28th, 2007, 03:48 PM
#11
Junior Member
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.......
-
Mar 28th, 2007, 03:55 PM
#12
Junior Member
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
-
Mar 28th, 2007, 03:59 PM
#13
Addicted Member
Re: Newbie help..please?
 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.
-
Mar 28th, 2007, 04:07 PM
#14
Junior Member
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
-
Mar 29th, 2007, 12:58 AM
#15
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|