Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Decision making help, VB 6.0

views
     
TSMr Ez
post Feb 7 2006, 10:31 AM, updated 20y ago

Super Cool
*****
Senior Member
700 posts

Joined: Dec 2005
From: KL


Okay here's the objective: user suppose to enter any 3 numbers, the program will display the largest number among the 3.

Problem is i keep getting blank answer.

user posted image

Private Sub cmdFindLargest_Click()
'delcare variable
Dim intNum1 As Integer
Dim intNum2 As Integer
Dim intNum3 As Integer


'convert input value to numeric value
intNum1 = Val(txtNum1.Text)
intNum2 = Val(txtNum2.Text)
intNum3 = Val(txtNum3.Text)


'making decision
If intNum1 > intNum2 Then
ElseIf intNum1 > intNum3 Then
lblResult.Caption = "" & txtNum1.Text
End If

If intNum2 > intNum1 Then
ElseIf intNum2 > intNum3 Then
lblResult.Caption = "" & txtNum2.Text
End If

If intNum3 > intNum1 Then
ElseIf intNum3 > intNum2 Then
lblResult.Caption = "" & txtNum3.Text
End If

End Sub


hope any VB master here can enlight me notworthy.gif
cpteoh
post Feb 7 2006, 10:47 AM

Starcraft - Broodwar
******
Senior Member
1,093 posts

Joined: Jun 2005



homework assignment??
astalavista_baby
post Feb 7 2006, 10:51 AM

Enthusiast
*****
Senior Member
818 posts

Joined: Jan 2003
I think you shouldn't be using ELSEIF in your decision making. You should use a IF within your IF statement.

Using ELSEIF gives you a different effect in your decision making. It's not the effect you are expecting. Revise your code and you will know what I mean.

So it becomes:

CODE

Private Sub cmdFindLargest_Click()
'delcare variable
Dim intNum1 As Integer
Dim intNum2 As Integer
Dim intNum3 As Integer


'convert input value to numeric value
intNum1 = Val(txtNum1.Text)
intNum2 = Val(txtNum2.Text)
intNum3 = Val(txtNum3.Text)


'making decision
If intNum1 > intNum2 Then
   If intNum1 > intNum3 Then
       lblResult.Caption = "" & txtNum1.Text
   End If
End If

If intNum2 > intNum1 Then
   If intNum2 > intNum3 Then
       lblResult.Caption = "" & txtNum2.Text
   End If
End If

If intNum3 > intNum1 Then
   If intNum3 > intNum2 Then
       lblResult.Caption = "" & txtNum3.Text
   End If
End If

End Sub


In fact there are easier ways to do it but I'll just correct your way. smile.gif Bear in mind the code has not been tested but the logic is there. smile.gif Hope that helped. Cheers. smile.gif

This post has been edited by astalavista_baby: Feb 7 2006, 10:53 AM
knokie
post Feb 7 2006, 10:53 AM

Getting Started
**
Junior Member
205 posts

Joined: Feb 2006


Hmm.....sounds like an assignment ya?
I will give you the algorithm, but you will need to write it in VB by your own.

max = num1

if num2 > max then max = num2
if num3 > max then max = num3

print max

Good luck.
shinchan^^
post Feb 7 2006, 10:55 AM

K66
*********
All Stars
21,256 posts

Joined: Jan 2003
From: Pekopon


if intNum1 > intNum2 and intNum1 > intNum3 then
lblResult.Caption = "" & txtNum1.Text
end

if intNum2 > intNum1 and intNum2 > intNum3 then
lblResult.Caption = "" & txtNum2.Text
end

if intNum3> intNum1 and intNum3 > intNum2 then
lblResult.Caption = "" & txtNum3.Text
end

This post has been edited by shinchan^^: Feb 7 2006, 10:56 AM
TSMr Ez
post Feb 7 2006, 10:59 AM

Super Cool
*****
Senior Member
700 posts

Joined: Dec 2005
From: KL


Yes it's an assignment.

Thanks a lot astalavista_baby, i don't know how to thank enough for the quick respond thumbup.gif

hey shinchan^^ your code is much simpler, it works too biggrin.gif thanks dude.

Thanks all for the help and tips. smile.gif

This post has been edited by Mr Ez: Feb 7 2006, 11:05 AM
astalavista_baby
post Feb 7 2006, 02:00 PM

Enthusiast
*****
Senior Member
818 posts

Joined: Jan 2003
QUOTE(Mr Ez @ Feb 7 2006, 10:59 AM)
Yes it's an assignment.

Thanks a lot astalavista_baby, i don't know how to thank enough for the quick respond  thumbup.gif

hey shinchan^^ your code is much simpler, it works too biggrin.gif thanks dude.

Thanks all for the help and tips. smile.gif
*
No worries mate. What is more important is that you learned something. smile.gif
shinchan^^
post Feb 7 2006, 02:04 PM

K66
*********
All Stars
21,256 posts

Joined: Jan 2003
From: Pekopon


that is just beginner
;p wait till u make bigger program

headache

 

Change to:
| Lo-Fi Version
0.0127sec    0.53    5 queries    GZIP Disabled
Time is now: 23rd December 2025 - 06:30 AM