Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using comparison operators on more than one variable

Posted on 2003-10-21
12
Medium Priority
?
234 Views
Last Modified: 2010-05-03
I have a program in which I have 10 numbers, and am trying to see which one is the highest.  This will return odd results when I know for a fact that the variables are set correctly.

CODE:

If frmp1.p10balence > frmp1.p2balence And frmp1.p10balence > frmp1.p3balence And frmp1.p10balence > frmp1.p4balence And frmp1.p10balence > frmp1.p5balence And frmp1.p10balence > frmp1.p6balence And frmp1.p10balence > frmp1.p7balence And frmp1.p10balence > frmp1.p8balence Then MsgBox ("Player 1 Wins!")
If frmp1.p2balence > frmp1.p10balence And frmp1.p2balence > frmp1.p3balence And frmp1.p2balence > frmp1.p4balence And frmp1.p2balence > frmp1.p5balence And frmp1.p2balence > frmp1.p6balence And frmp1.p2balence > frmp1.p7balence And frmp1.p2balence > frmp1.p8balence Then MsgBox ("Player 2 Wins!")
If frmp1.p3balence > frmp1.p2balence And frmp1.p3balence > frmp1.p10balence And frmp1.p3balence > frmp1.p4balence And frmp1.p3balence > frmp1.p5balence And frmp1.p3balence > frmp1.p6balence And frmp1.p3balence > frmp1.p7balence And frmp1.p3balence > frmp1.p8balence Then MsgBox ("Player 3 Wins!")
If frmp1.p4balence > frmp1.p2balence And frmp1.p4balence > frmp1.p3balence And frmp1.p4balence > frmp1.p10balence And frmp1.p4balence > frmp1.p5balence And frmp1.p4balence > frmp1.p6balence And frmp1.p4balence > frmp1.p7balence And frmp1.p4balence > frmp1.p8balence Then MsgBox ("Player 4 Wins!")
If frmp1.p5balence > frmp1.p2balence And frmp1.p5balence > frmp1.p3balence And frmp1.p5balence > frmp1.p4balence And frmp1.p5balence > frmp1.p10balence And frmp1.p5balence > frmp1.p6balence And frmp1.p5balence > frmp1.p7balence And frmp1.p5balence > frmp1.p8balence Then MsgBox ("Player 5 Wins!")
If frmp1.p6balence > frmp1.p2balence And frmp1.p6balence > frmp1.p3balence And frmp1.p6balence > frmp1.p4balence And frmp1.p6balence > frmp1.p5balence And frmp1.p6balence > frmp1.p10balence And frmp1.p6balence > frmp1.p7balence And frmp1.p6balence > frmp1.p8balence Then MsgBox ("Player 6 Wins!")
If frmp1.p7balence > frmp1.p2balence And frmp1.p7balence > frmp1.p3balence And frmp1.p7balence > frmp1.p4balence And frmp1.p7balence > frmp1.p5balence And frmp1.p7balence > frmp1.p6balence And frmp1.p7balence > frmp1.p10balence And frmp1.p7balence > frmp1.p8balence Then MsgBox ("Player 7 Wins!")
If frmp1.p8balence > frmp1.p2balence And frmp1.p8balence > frmp1.p3balence And frmp1.p8balence > frmp1.p4balence And frmp1.p8balence > frmp1.p5balence And frmp1.p8balence > frmp1.p6balence And frmp1.p8balence > frmp1.p7balence And frmp1.p8balence > frmp1.p10balence Then MsgBox ("Player 8 Wins!")
0
Comment
Question by:drtsystems
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9595771
Please maintain your open questions:

1 03/11/2003 60 Serial LCD  Unlocked Hardware
2 02/21/2003 50 Windows RARP Server  Unlocked Microsoft Network

Thanks,
Anthony
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 9596088
You need to put () around the compares.  AND is higher precedence so it executes first.

If (frmp1.p10balence > frmp1.p2balence) And (frmp1.p10balence > frmp1.p3balence) And

ETC

mlmcc
0
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 200 total points
ID: 9597684
Make is this way--> bubble sort

dim myarray(9) as integer
myarray(0) = frmp1.p1balence
myarray(1) = frmp1.p2balence
myarray(2) = frmp1.p3balence
myarray(3) = frmp1.p4balence
myarray(4) = frmp1.p5balence
myarray(5) = frmp1.p6balence
myarray(6) = frmp1.p7balence
myarray(7) = frmp1.p8balence
myarray(8) = frmp1.p9balence  
myarray(9) = frmp1.p10balence

Do
    AnyChanges = False
    For i = 1 To UBound(myarray()) - 1
         If myarray(i) > myarray(i + 1) Then
              ' These two need to be swapped
              SwapFH = myarray(i)
              myarray(i) = myarray(i + 1)
              myarray(i + 1) = SwapFH
              AnyChanges = True
         End If
    Next i
Loop Until Not AnyChanges

Thanks & Cheers
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 101

Expert Comment

by:mlmcc
ID: 9603570
This probably a homework problem and they haven't gotten to arrays just yet.

mlmcc
0
 

Author Comment

by:drtsystems
ID: 9603796
actually, this isnt a homework project, it is a little "game" i started a while back, when i didnt know too much about programming.  I now program primarily in C++, and have trouble with VB, considering C++ is a "stronger-typed language" (or whatever it called, having to difine variables more explicitly) and I always end up screwing up my program with anything more than a simple variable.
0
 

Author Comment

by:drtsystems
ID: 9603810
Sorry for the double post, I forgot to add this.  I will give credit to someone when I am able to test it.  I know fantasy1001 is probably better, but mlmcc has a more quick fix it seems, as I dont feel like rewriting a whole section of code.
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9603833
There is not need to write all the code again. You can just copy the code I gave in replace with your original, and add this line

msgbox "Player " & myarray(9) & " wins"

Anyway, the code also show the bubble sort technique which is popular in c++.

thanks & cheers
0
 

Author Comment

by:drtsystems
ID: 9610801
using fantasy's way, i end up with "Player 0 wins" when player 2 should have won.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9610942
No telling, but I suspect this line:
For i = 1 To UBound(myarray()) - 1

is supposed to be:
For i = 0 To UBound(myarray()) - 1

Anthony

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 9610954
Also, let me know if you need help maintaining your open questions:

Question Title: Serial LCD
Author: drtsystems
Points: 60
Date: 03/11/2003 08:02PM CST
http://www.experts-exchange.com/Hardware/Q_20547165.html

Question Title: Windows RARP Server
Author: drtsystems
Points: 50
Date: 02/21/2003 05:45PM CST
http://www.experts-exchange.com/Networking/Microsoft_Network/Q_20524577.html

Thanks,
Anthony
0
 

Author Comment

by:drtsystems
ID: 9610995
Fixed.  The only problem is that this displayes the value of the variables.  Lets say p2 balence is higher, i want "Player 2 Wins" not "Player 777 Wins" beucase player 2 had 777

Thanks!
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9624528
Sorry for the confusion, add a integer variable name UserWon

         If myarray(i) > myarray(i + 1) Then
              ' These two need to be swapped
              SwapFH = myarray(i)
              myarray(i) = myarray(i + 1)
              myarray(i + 1) = SwapFH
              AnyChanges = True

              UserWon = i + 1       'Add here
         End If

Thanks & cheers
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question