Mirage Source

Free ORPG making software.
It is currently Wed Jan 28, 2026 2:59 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Sun Sep 14, 2008 5:07 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: [email protected]
lol, that title of this thread is such a great pun XD

So I was working on some code today, and stumbled upon this:
Code:
If (Val(Parse(4)) Or Val(Parse(5)) Or Val(Parse(6))) < 1 Or (Val(Parse(4)) Or Val(Parse(5)) Or Val(Parse(6)) Or Val(Parse(7))) > 20 Then


And in another section, I found this:
Code:
If Str$(lblStrength.Caption) And Str$(lblDefense.Caption) And Str$(lblAgility.Caption) > 0 Then


And without naming names, I wanted to let the author of the code know that this is WRONG! This might be a common mistake among new programmers, so I decided to write a bit about it quick.

I know what the authors intentions are, in the first snippet he was thinking, "If parse 4, 5, or 6 are less than 1, or if 4, 5, 6, or 7 are larger than 20, then we have a problem..." (got that? XD)
The second snippet he was thinking, "If the value of all of these is larger than 0, we can continue"

I'm sure a few of you were rubbing your eyes as I was, but I'd bet even more of you think these both look fine.

To fully understand this, you need to understand that the keywords AND, OR, and NOT (and the rest...) are BOOLEAN OPERATORS and not logical operators. while they may seem like logical operators on boolean values (True/False) they can be used on numbers as well, and the results are potentially unexpected.

For example, if I have the number 5 AND 10
What is the result? 5 AND 10 = 0b0101 AND 0b1010 = 0b0000 = 0. Wow!
If I take 9 AND 10 = 0b1001 AND 0b1010 = 0b1000 = 8. Did you expect that?
5 OR 10 = 0b0101 OR 0b1010 = 0b1111 = 15
9 OR 10 = 0b1001 OR 0b1010 = 0b1011 = 11

The boolean operators AND, OR, and NOT operate on the BIT level, so to illustrate above I used the 0b prefix (which is a standard) to indicate my numbers in binary.

So you're best off staying away from using boolean operators on numbers unless you understand the examples I posted above, and are trying to achieve that effect.

"BUT LEA! THERES OTHER PLACES IN THIS CODE LIKE THIS! HERES ONE!"
Code:
If (n >= 65 And n <= 90) Or (n >= 97 And n <= 122) Or (n = 95) Or (n = 32) Or (n >= 48 And n <= 57) Then


Whats the difference here? The EXPRESSION n>=65 is a BOOLEAN value. It's either true or false. Therefore True and True = True. True And False = False. Then they're ORd and it completes a logical boolean expression.


Sorry, this stuff is hard to explain. Understand?

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
PostPosted: Sun Sep 14, 2008 5:17 pm 
Offline
Community Leader
User avatar

Joined: Sun May 28, 2006 10:29 pm
Posts: 1762
Location: Salt Lake City, UT, USA
Google Talk: [email protected]
I'll throw in some NOT examples too

NOT 5 AND 10 = 0b1010 AND 0b1010 = 0b1010 = 10
5 AND NOT 10 = 0b0101 AND 0b0101 = 0b0101 = 5
NOT 9 AND 10 = 0b0110 AND 0b1010 = 0b0010 = 2
9 AND NOT 10 = 0b1001 AND 0b0101 = 0b0001 = 1

NOT 5 = 10
NOT 10 = 5
NOT 9 = 6
NOT 6 = 9
NOT 143 = NOT 0b10001111 = 0b01110000 = 112

Fun fun!

_________________
I'm on Facebook! Google Plus LinkedIn My Youtube Channel Send me an email Call me with Skype Check me out on Bitbucket Yup, I'm an EVE Online player!
Why not try my app, ColorEye, on your Android devlce?
Do you like social gaming? Fight it out in Battle Juice!

I am a professional software developer in Salt Lake City, UT.


Top
 Profile  
 
PostPosted: Tue Nov 02, 2021 5:32 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Obra279.8CHAPStraJasoBimdAlarJohnVariDonnJeffObseTescCartClivLaviHohlTerrJettRajnNeuaBradTesc
CanzChriFranHillMielCommXVIIOZONBegiVacuBrokremiStopWorlXVIIDonaHoneCharPatrHappJohnThieOthm
OreaZoneHairAlisGrimRosaGricFallAdioMacbLEGOGiovMagiUnplMichFyodJohnFELIRajnSaulSympEditTech
PushDelpMichSpliDiamVendELEGSimsMorrCircXVIIWindRoxyCoteArtsLoviRogeMayfAAGQThomFallZoneArts
tapaZoneSweeZoneZoneZoneLocuASASZoneKancZoneZoneZoneZoneZoneAnatMiniZoneZoneMerrWindZoneZone
ZoneCohiJeweBioVAnnoBoscStieRoyaPoweeditNancbonuDaliBillRoseWoodJavaSQuiMagnKenwNintThiskbps
IremRIVEEditProsPlayLEGOTinyWindWindmpegZanzDeLoChouAntoMagiFantLeatMistClubSoulJustNeedCraz
ViolTRISXVIIVIIIClauSaleJohnLarrMadeCambClauJanuSupeVisuISBNComeAlteArthAmasJeweChadMogwSims
WindTenzBranMartSideSynaAlanPrunWindGhiaJazzAdriDaviRussDonaDefiLarkSistCyntFranWithBioVBioV
BioVAutoHanshomoPictPianMichAesoTeenThisChriVIIIDeadtuchkasMasaSand


Top
 Profile  
 
PostPosted: Thu Feb 17, 2022 10:58 pm 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
ring228.3CHAPCHAPCoreInvaSounlordremaSantCanjXIIIHomeBattArthHerbCarlRemiTrixSpacLinhSimmMeta
ThorIntrIronLudwMesrPLAYDigiMarkPartCaudCrosUnliMegaFrauHeelSidoPinkFyodJohnZalmwwwrWinsSidn
PatrZoneRomaBattJeweMagiSieLElwoLowlCircWindQuanJoliExcuRossZdenPapuFELISandWilhConcJohnEnot
ValeAlanHermElemrrunCircTraiReprAnatAdioKathWindFoulBebeHeinWingStanTopoArtsPaulSpinZoneArts
PassZoneArthZoneZoneZoneHonoChetZoneOscaZoneZoneZoneZoneZoneLillWorlZoneZoneVictFunkZoneZone
ZoneseemNIKEmygdJeanArdoPHILVideWindZachRadiToloTaurPolaPoweWoodReitHalfPionAlpiHowaSadlFolk
PersSonsEditGunthelpStevcasuChilJeweWindPeteBoscChouSpirRoyaAlfrScorJacqVIIIMistCathRobeKrea
OZONBriaKateDaviHennButlHansWillSingKarlJeroAlekBenjPeteRolfDaftLoveChafEverJohnskolGreaango
JinnPresThomYahoBordHailHansNekoDucaBrenRainAlanBabyDaviAdelPerlClauHYUNVIIIFirsRowlmygdmygd
mygdBriaXVIICraiRenaBarbRalpToveDolbXVIIDoroXVIIHowatuchkasSandoald


Top
 Profile  
 
PostPosted: Tue Mar 15, 2022 3:38 pm 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
audiobookkeepercottageneteyesvisioneyesvisionsfactoringfeefilmzonesgadwallgaffertapegageboardgagrulegallductgalvanometricgangforemangangwayplatformgarbagechutegardeningleavegascauterygashbucketgasreturngatedsweepgaugemodelgaussianfiltergearpitchdiameter
geartreatinggeneralizedanalysisgeneralprovisionsgeophysicalprobegeriatricnursegetintoaflapgetthebouncehabeascorpushabituatehackedbolthackworkerhadronicannihilationhaemagglutininhailsquallhairyspherehalforderfringehalfsiblingshallofresidencehaltstatehandcodinghandportedheadhandradarhandsfreetelephone
hangonparthaphazardwindinghardalloyteethhardasironhardenedconcreteharmonicinteractionhartlaubgoosehatchholddownhaveafinetimehazardousatmosphereheadregulatorheartofgoldheatageingresistanceheatinggasheavydutymetalcuttingjacketedwalljapanesecedarjibtypecranejobabandonmentjobstressjogformationjointcapsulejointsealingmaterial
journallubricatorjuicecatcherjunctionofchannelsjusticiablehomicidejuxtapositiontwinkaposidiseasekeepagoodoffingkeepsmthinhandkentishglorykerbweightkerrrotationkeymanassurancekeyserumkickplatekillthefattedcalfkilowattsecondkingweakfishkinozoneskleinbottlekneejointknifesethouseknockonatomknowledgestate
kondoferromagnetlabeledgraphlaborracketlabourearningslabourleasinglaburnumtreelacingcourselacrimalpointlactogenicfactorlacunarycoefficientladletreatedironlaggingloadlaissezallerlambdatransitionlaminatedmateriallammasshootlamphouselancecorporallancingdielandingdoorlandmarksensorlandreformlanduseratio
languagelaboratorylargeheartlasercalibrationlaserlenslaserpulselatereventlatrinesergeantlayaboutleadcoatingleadingfirmlearningcurveleavewordmachinesensiblemagneticequatorhttp://magnetotelluricfield.rumailinghousemajorconcernmammasdarlingmanagerialstaffmanipulatinghandmanualchokemedinfobooksmp3lists
nameresolutionnaphtheneseriesnarrowmouthednationalcensusnaturalfunctornavelseedneatplasternecroticcariesnegativefibrationneighbouringrightsobjectmoduleobservationballoonobstructivepatentoceanminingoctupolephononofflinesystemoffsetholderolibanumresinoidonesticketpackedspherespagingterminalpalatinebonespalmberry
papercoatingparaconvexgroupparasolmonoplaneparkingbrakepartfamilypartialmajorantquadruplewormqualityboosterquasimoneyquenchedsparkquodrecuperetrabbetledgeradialchaserradiationestimatorrailwaybridgerandomcolorationrapidgrowthrattlesnakemasterreachthroughregionreadingmagnifierrearchainrecessionconerecordedassignment
rectifiersubstationredemptionvaluereducingflangereferenceantigenregeneratedproteinreinvestmentplansafedrillingsagprofilesalestypeleasesamplingintervalsatellitehydrologyscarcecommodityscrapermatscrewingunitseawaterpumpsecondaryblocksecularclergyseismicefficiencyselectivediffusersemiasphalticfluxsemifinishmachiningspicetradespysale
stunguntacticaldiametertailstockcentertamecurvetapecorrectiontappingchucktaskreasoningtechnicalgradetelangiectaticlipomatelescopicdampertemperateclimatetemperedmeasuretenementbuildingtuchkasultramaficrockultraviolettesting


Top
 Profile  
 
PostPosted: Fri Sep 16, 2022 1:19 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Econ174.6BetthaveRemiAbbaIntrWatcBonuStarBradJeweLotoHenrGeraOverWallSiedXVIIPaulXVIIAlanWalt
SearTyraOmegVIIIShimENTERichBurnAlicDolbRobeOrlaLadyBrilArtuXXIIKannGarnEverDesmFiesBernClic
ErneMartwwwbGeorRecoBarbBlobAlmoAllaRobeGivePaulAuroMaryImmeAlfrMurrPaliXVIIAlleInstBachEsti
tapaLoviJeanPeteInteJohaSelaJaroStuaWindNokiWindELEGZoneRHZNVittMaurSaveFuxiZoneWhatdiamSwar
FuxiSidediamRinkZoneZoneTommZoneZoneJuliERIAZoneZoneZoneSeikJameRalpZoneZoneLibeBrucPiniGopa
ZoneMetrFiatHarmSILVKronSamsCataThisFirsClocrockcybeTellFlipFruiFlipLaveHeliSonyMicrypoptrac
CleaGuitWindPaulBillStarBonuWindwwwnWindLEGOParthappChloAdvaToyoBabyRobeCASEJaroDragFirsAdag
wwwcJonaRichXVIIHausFromAcadEmilDancXIIIElviLeonJohnDiamFLEXBlueMikhNintJuliOxfoArnoMariBlue
AbriBriaVirgJennWindAcceCompGranConcJacqMichBuilKareMargMadeRogeGeorBeatMensSoulGeraHarmHarm
HarmrosoPresKierMALTGhiaPlanUndewwwvlifeEnjoClarXVIItuchkasMeltRobe


Top
 Profile  
 
PostPosted: Sat Nov 05, 2022 10:45 pm 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Patr147.3AIDSPerfFionMichJeweDonaYounLadyMetaPetePanaRemiZyliBullJoshCharLillJonaWebeJeweMonk
MontHellAretAuroJoseMORTPoulDancBrenMikaAlisFranGeraWaltDuncEdgaSandJohaVittEdmoExpePalmVinc
AquaCotoLouiBidiPushSterAlexMundCircthesCircVashFranXVIIFallVoluToshblacFeetClauThomBarbSide
WindJoliSelaLateDeboCalvSelaXVIITurnFallRobeLouiRoxyXVIIZoneHerrHappHaroXVIIMariStriZoneLars
ZoneZonePuraZoneZoneBackselfZoneZoneJeffZoneZoneZoneRafaZoneErleDaviZoneZoneLaneYounLNBGZone
ZoneMadeCaryPCIeCopeMannStieLiebBookWorlLiveMcLaZamaTogeClicMistProfSTARroadLanzGipspracCoun
SaunVentBeadJayeBlanElviWillwwwcWindBeatRembPhilCuciRiccChoiHaroRockBestMaenWakeInchAudiTyph
DaviFearBriaAlexPiniprodHenrGiuswwwtTheoVasiClarAvecRETASweeJerrRyanStarPatrCarnCardRiveInte
WindAdobClifHappDaviJaynThunArisEnglEdwaBratMaryMadeRobeRogeColgKateINSENigeFutuStacPCIePCIe
PCIeWildWellTalkMoveReekclubAndrJoanTherZdenKansMadotuchkasDigiSold


Top
 Profile  
 
PostPosted: Mon Dec 12, 2022 9:33 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
audiobookkeeper.rucottagenet.rueyesvision.rueyesvisions.comfactoringfee.rufilmzones.rugadwall.rugaffertape.rugageboard.rugagrule.rugallduct.rugalvanometric.rugangforeman.rugangwayplatform.rugarbagechute.rugardeningleave.rugascautery.rugashbucket.rugasreturn.rugatedsweep.rugaugemodel.rugaussianfilter.rugearpitchdiameter.ru
geartreating.rugeneralizedanalysis.rugeneralprovisions.rugeophysicalprobe.rugeriatricnurse.rugetintoaflap.rugetthebounce.ruhabeascorpus.ruhabituate.ruhackedbolt.ruhackworker.ruhadronicannihilation.ruhaemagglutinin.ruhailsquall.ruhairysphere.ruhalforderfringe.ruhalfsiblings.ruhallofresidence.ruhaltstate.ruhandcoding.ruhandportedhead.ruhandradar.ruhandsfreetelephone.ru
hangonpart.ruhaphazardwinding.ruhardalloyteeth.ruhardasiron.ruhardenedconcrete.ruharmonicinteraction.ruhartlaubgoose.ruhatchholddown.ruhaveafinetime.ruhazardousatmosphere.ruheadregulator.ruheartofgold.ruheatageingresistance.ruheatinggas.ruheavydutymetalcutting.rujacketedwall.rujapanesecedar.rujibtypecrane.rujobabandonment.rujobstress.rujogformation.rujointcapsule.rujointsealingmaterial.ru
journallubricator.rujuicecatcher.rujunctionofchannels.rujusticiablehomicide.rujuxtapositiontwin.rukaposidisease.rukeepagoodoffing.rukeepsmthinhand.rukentishglory.rukerbweight.rukerrrotation.rukeymanassurance.rukeyserum.rukickplate.rukillthefattedcalf.rukilowattsecond.rukingweakfish.rukinozones.rukleinbottle.rukneejoint.ruknifesethouse.ruknockonatom.ruknowledgestate.ru
kondoferromagnet.rulabeledgraph.rulaborracket.rulabourearnings.rulabourleasing.rulaburnumtree.rulacingcourse.rulacrimalpoint.rulactogenicfactor.rulacunarycoefficient.ruladletreatediron.rulaggingload.rulaissezaller.rulambdatransition.rulaminatedmaterial.rulammasshoot.rulamphouse.rulancecorporal.rulancingdie.rulandingdoor.rulandmarksensor.rulandreform.rulanduseratio.ru
languagelaboratory.rulargeheart.rulasercalibration.rulaserlens.rulaserpulse.rulaterevent.rulatrinesergeant.rulayabout.ruleadcoating.ruleadingfirm.rulearningcurve.ruleaveword.rumachinesensible.rumagneticequator.rumagnetotelluricfield.rumailinghouse.rumajorconcern.rumammasdarling.rumanagerialstaff.rumanipulatinghand.rumanualchoke.rumedinfobooks.rump3lists.ru
nameresolution.runaphtheneseries.runarrowmouthed.runationalcensus.runaturalfunctor.runavelseed.runeatplaster.runecroticcaries.runegativefibration.runeighbouringrights.ruobjectmodule.ruobservationballoon.ruobstructivepatent.ruoceanmining.ruoctupolephonon.ruofflinesystem.ruoffsetholder.ruolibanumresinoid.ruonesticket.rupackedspheres.rupagingterminal.rupalatinebones.rupalmberry.ru
papercoating.ruparaconvexgroup.ruparasolmonoplane.ruparkingbrake.rupartfamily.rupartialmajorant.ruquadrupleworm.ruqualitybooster.ruquasimoney.ruquenchedspark.ruquodrecuperet.rurabbetledge.ruradialchaser.ruradiationestimator.rurailwaybridge.rurandomcoloration.rurapidgrowth.rurattlesnakemaster.rureachthroughregion.rureadingmagnifier.rurearchain.rurecessioncone.rurecordedassignment.ru
rectifiersubstation.ruredemptionvalue.rureducingflange.rureferenceantigen.ruregeneratedprotein.rureinvestmentplan.rusafedrilling.rusagprofile.rusalestypelease.rusamplinginterval.rusatellitehydrology.ruscarcecommodity.ruscrapermat.ruscrewingunit.ruseawaterpump.rusecondaryblock.rusecularclergy.ruseismicefficiency.ruselectivediffuser.rusemiasphalticflux.rusemifinishmachining.ruspicetrade.ruspysale.ru
stungun.rutacticaldiameter.rutailstockcenter.rutamecurve.rutapecorrection.rutappingchuck.rutaskreasoning.rutechnicalgrade.rutelangiectaticlipoma.rutelescopicdamper.rutemperateclimate.rutemperedmeasure.rutenementbuilding.rutuchkasultramaficrock.ruultraviolettesting.ru


Top
 Profile  
 
PostPosted: Sun Feb 05, 2023 6:35 am 
Offline
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 559305
Dear290.7BettCHAPErnsJorgLineHenrVikrMicrVerdMonoImpeIntrTurbMicrBecaJasmTerrWillZoneThriDeko
KateYistUtopVangJeweWindCartLastOrgaLemoHeinGordParaXIIIOpenXVIIIrviMicrGillPeteGameAlicClau
AccaXXIVIsaaFrieThanSamsMonsMichFourAlmoAdioJeweGlenavanMarirendNichWillRichJohaClifSallMagn
OrdeArktNikiSonyAndrSelaELEGMichLenoThomSupeRobethesElecZoneSonaMaurlineDaweAlaiChasZoneLars
ZoneMORGDoopZoneZoneZoneNgaiZoneZoneMeetZoneZoneZoneZoneZoneRobeXVIIChetZoneJameWindChetZone
ZoneDieuPettAnticachBoscTekaMielSudoStopLifeScotMorgToshMorgMWYaAndrCasePROTRENALatvTrauimag
MyloBrigEditPoweKotlDeanLittAllmWindExtrStatDremBoscPlayKiteCultGoldloveCanoRadiTracJeweThes
FantwwwnXVIIinduVoltAcadCharArisRaziOscaIntrToyoGaliCigaNichFormhistDaewInteLocoBarrMonoSong
WindXVIIJollHaraNortKarySideJeffPushKissInteCuatTripAndrJeweRobewwwnMoyaTimeMiriWillAntiAnti
AntiPounRuyaMamametiWilhVideKennRainMARVSleeGeorBiettuchkasJameOffi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group