forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to avoid a lot of @equals

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Knowledge Base
View previous topic :: View next topic  
Author Message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Fri Apr 01, 2005 7:18 am    Post subject: How to avoid a lot of @equals Reply with quote

If you have a word and you want to check if it's value is "A", "B", "C", "D" or "M", you normally need a lot of @equal functions to do this. It makes your code unreadable and it will become quite long.

To avoid this problem, you can use the @pos function to check if the word is in the string "|A|B|C|D|M|". If so, the @pos function will return a value greater than zero. If you like, you can combine the @pos function with the "EXACT" parameter.

The first example shows how such a "A" or "B" or "C" statement looks like:

Code:
%%word = duck

if @equal(%%word, cow) @equal(%%word, chicken) @equal(%%word, duck) @equal(%%word, pig) @equal(%%word, bird) @equal(%%word, sheep) @equal(%%word, cat) @equal(%%word, dog) @equal(%%word, ape)
  info Done
end


The second shows how you can reduce all above code to some smaller one:

Code:
%%word = duck

if @greater(@pos(|%%word|,|cow|chicken|duck|pig|bird|sheep|cat|dog|ape|),0)
  info Done
end

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Fri Apr 01, 2005 7:25 am    Post subject: Reply with quote

Another tip on how to avoid a lot of @both functions if you want to check if the first @equal is true, the second one is true, etc:

Code:
rem The "normal" way
if @both(@both(@both(@both(@both(@both(@both(@equal(1,1),@equal(2,2)),@equal(3,3)),@equal(4,4)),@equal(5,5)),@equal(6,6)),@equal(7,7)),@equal(8,Cool)
  info Done
end


Code:
rem This way, the results of the @equals are examined as a string, so you don't need a lot of @boths Smile
if @equal(@equal(1,1)@equal(2,2)@equal(3,3)@equal(4,4)@equal(5,5)@equal(6,6)@equal(7,7)@equal(8,Cool,11111111)
  info Done
end


If you want not all the @equals to be true, but some of them (for example 2) may be false, you can change the "11111111" into "111111"... Smile

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Fri Apr 01, 2005 7:34 am    Post subject: Reply with quote

Here is an example which combines the two methods shown above. It check if "A is A" and "B is not C", etc., without having to do a lot of @boths... Smile

Code:
rem Old method
if @both(@both(@both(@both(@equal(Jack,Jack),@not(@equal(duck,cow))),@equal(1,1)),@not(@equal(sheep,dog))),@not(@equal(text,book)))
  info Done
end


Code:
rem New method, use || for false and |1| for true:
if @equal(|@equal(Jack,Jack)|@equal(duck,cow)|@equal(1,1)|@equal(sheep,dog)|@equal(text,book)|, "|1||1|||")
  info Done
end

_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Sat Apr 02, 2005 1:11 am    Post subject: Reply with quote

excellent work there skit Smile

serge

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
FreezingFire
Admin Team


Joined: 23 Jun 2002
Posts: 3508

PostPosted: Sun Apr 03, 2005 9:39 pm    Post subject: Reply with quote

Nice job Thumbs Up
_________________
FreezingFire
VDSWORLD.com
Site Admin Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Knowledge Base All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group