English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have five txtboxes that will be inputed with numbers.......I then have a button that will compute the maximum number...............................example.....i impute 3,6,7,8,9, the answer would be 9 when the button is pressed........the answer would be put in another txt box........................MAY U PLEASE HELP ME WITH THE CODES FOR FINDING THE MAX

2007-01-29 17:17:25 · 4 answers · asked by y0ger_19 4 in Computers & Internet Programming & Design

4 answers

Private Sub Command1_Click()
Dim a, b, c, d, e As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
d = Val(Text4.Text)
e = Val(Text5.Text)
If a > b And a > c And a > d And a > e Then
Text6.Text = Val(Text1.Text)
End If
If b > a And b > c And b > d And b > e Then
Text6.Text = Val(Text2.Text)
End If
If c > a And c > b And c > d And c > e Then
Text6.Text = Val(Text3.Text)
End If
If d > a And d > b And d > c And d > e Then
Text6.Text = Val(Text4.Text)
End If
If e > a And e > b And e > c And e > d Then
Text6.Text = Val(Text5.Text)
End If
End Sub

hope give 10 full point to me
thank u
vishal

2007-01-29 17:43:50 · answer #1 · answered by vishal b 2 · 1 0

Using VB express: The following code will loop through the controls collection of the form. All controls (Button, Label and Textboxes use there default names)

You must convert the textbox.text from a string into a number using the Val() function. The code below initializes the maxVal to the vaule of the first text box. The FOR EACH NEXT loop will look at each control on the form. As each control is extracted from the collection it is tested with IF TypeOf to see if it is a textbox.

Only textbox strings are converted into numbers and compared with the existing maxValue. If a larger value is found then it becomes the new maxvalue. This code will handle any number of text boxes you place on the form.

........Dim ctrl As Control
........Dim maxVal, txtVal As Double

........'initialize maxval with any textbox value
.........maxVal = Val(TextBox1.Text)

.........For Each ctrl In Me.Controls
............'look at each control placed on form
............'determine if it is a textbox
.............If TypeOf ctrl Is TextBox Then
..................'found a textbox
...................txtVal = Val(ctrl.Text) 'value of text
...................If txtVal > maxVal Then
.......................'A larger value has been found
.......................maxVal = txtVal 'reassign new max value
...................End If
.............End If
........Next
........Me.Label1.Text = maxVal ' display max value

2007-01-30 01:09:32 · answer #2 · answered by MarkG 7 · 0 0

pretty much set a variable to hold one of the numbers like in sanama example but you can't compare a string to a double so you need to find a way to make that happen by ethier using double.parse() or convert.tostring() (which i beleive would just compare its ascii value) then use if statements like in sanama but in visual basic you need an end if statement at the end of every if statement

2007-01-29 18:19:04 · answer #3 · answered by the man the myth the answerer 5 · 0 0

Dim maxno As Double

maxno = Text1.Text

If Text2.Text > maxno Then maxno = Text2.Text
If Text3.Text > maxno Then maxno = Text3.Text
If Text4.Text > maxno Then maxno = Text4.Text
If Text5.Text > maxno Then maxno = Text5.Text

txtresult.Text = maxno

2007-01-29 17:26:06 · answer #4 · answered by Sanama 2 · 0 1

fedest.com, questions and answers