Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an online mysql Database that I am accessing through C++. Is there a difference if I do Version 1 or Version 2? I know thw syntax and other stuff is off, but I'm just trying to get the framework...Any suggestions are welcome....

FIRST VERSION
Field 1 = DCount("IP", "tblURLIP", "IP = 192.168.1.168")
Field 2 = DCount("IPStatus", "tblURLIP", "IP = 192.168.1.168 And IPStatus = 1")
Field 3 = DLookUp("IPMax", "tblURLIP", "IP = 192.168.1.168")
Field 4 = DSum("IPDown", "tblIPAccess", "IP = 192.168.1.168")

If Field 4 <= Field 3 Then
Field 5 = 1
Else
Field 5 = 0
End If

If Field 1 + Field 2 + Field 5 = 3 Then
"Proceed"
Else
"Quit"
End If

SECOND VERSION
Field 1 = DCount("IP", "tblURLIP", "IP = 192.168.1.168")
Field 2 = DCount("IPStatus", "tblURLIP", "IP = 192.168.1.168 And IPStatus = 1")
Field 3 = DLookUp("IPMax", "tblURLIP", "IP = 192.168.1.168")
Field 4 = DSum("IPDown", "tblIPAccess", "IP = 192.168.1.168")

If Field 1 = 1 Then
 If Field 2 = 1 Then
	If Field 3 <= Field 4 Then
	  "Proceed"
        Else
	  "Quit"
	End If
 Else
 	"Quit"
 End If	
Else
  "Quit"
End If
Posted
Updated 1-Aug-11 14:17pm
v2
Comments
Stephen Wiria 1-Aug-11 20:38pm    
Sorry but what is the relation between your code and C++ MySQL?
From what I see it's VB/VBA and MS Access?
Member 7766180 1-Aug-11 20:57pm    
Like I said, it's only filler code. I'm trying to nail down which structure would be better.

1 solution

How about:

if(Field1 != 1 || Field2 != 1 || Field3 > Field4)
    "Quit"
else
    "Proceed"


That way as soon as you find out one of the conditions fails you can quit, and you won't need multiple (separate) if statements.
I'd advise against using something like If Field 1 + Field 2 + Field 5 = 3 Then, even if your quite sure of what the fields will be if something changes in the future you might end up with some unexpected behaviour, like if Field1 = 2, Field2 = 0 and Field5 = 1 it would still go through.
 
Share this answer
 
v2
Comments
Member 7766180 1-Aug-11 22:23pm    
Thats great! More than I was looking for! Simple is best! Thank you so much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900