Mirage Source

Free ORPG making software.
It is currently Thu Dec 02, 2021 4:49 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Mon Jun 29, 2009 1:11 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
If then, what?

If .. Then statements are very important.
Code:
If [Logic] Then
[Statements]
End If


Examples:
Code:
Dim i As Long
   
    If i > 0 Then
        Debug.Print "The answer is true"
    End If


An example of If .. Else
Code:
Dim b As Boolean
    b = False
   
    If b = True Then
        Debug.Print "The answer is true"
    Else
        Debug.Print "The answer is false"
    End If


An example of If .. ElseIf ..
Code:
Dim i As Long
   
    If i > 0 Then
        Debug.Print "The answer is true"
    ElseIf i < 0 Then
        Debug.Print "The answer is false"
    End If


There are some short hand with VB6. If you are testing a boolean value you do not need to have "IF value = true Then". you just need to have "If value Then". For false values you use "If Not b Then" instead of "If b = false then".
Code:
Dim b As Boolean
    b = False
   
    If b Then
        Debug.Print "The answer is true"
    ElseIf Not b Then
        Debug.Print "The answer is false"
    End If


Project
Use multiple versions of the If .. then statement to evaluate a number that the user inputs. Check if the number is above 0, above 100, and above 1000. Display the results.

Overview
  • Declare variables.
  • Use an If ... then statement to check the number the user inputs.

Notes
  • Make sure to comment your code.


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 1:54 am 
Offline
Pro
User avatar

Joined: Tue Apr 22, 2008 2:15 am
Posts: 597
Cheers. Sorry they already did the first one and well, it seemed a bit boring. This one required a few more lines of code :D

Attachment:
Basics 2.zip [4.87 KiB]
Downloaded 323 times


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 12:15 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Pbcrazy wrote:
Cheers. Sorry they already did the first one and well, it seemed a bit boring. This one required a few more lines of code :D

Attachment:
Basics 2.zip


Looks good. If you wanted, you should check to make sure the user actually entered a number so you don't get any errors.


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 3:10 pm 
Offline
Pro
User avatar

Joined: Tue Apr 22, 2008 2:15 am
Posts: 597
Ya... bout that... Wasn't exactly sure how? Use keycodes to determine if it is between 0-9 or, is there some other type of syntax that i could use? Sorry, one of my newb moments.


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 3:27 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
VB6 has a built in function:
Code:
IsNumeric(Expression)


You can do something like
Code:
If IsNumeric(Input.Text) Then
i = Clng(Input.text)
End If


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 3:45 pm 
Offline
Pro
User avatar

Joined: Tue Apr 22, 2008 2:15 am
Posts: 597
Ahh, see i thought there was something like that.

Gah VB6 has so many freaking built in functions. Wish there was an easy way to like look them up. (Watch, i bet someone will post with a way, just wait...)


Top
 Profile  
 
PostPosted: Tue Jun 30, 2009 9:02 pm 
Offline
Knowledgeable

Joined: Sat Jul 08, 2006 8:24 am
Posts: 339
Pbcrazy wrote:
Ya... bout that... Wasn't exactly sure how? Use keycodes to determine if it is between 0-9 or, is there some other type of syntax that i could use? Sorry, one of my newb moments.


If Len(La) = 1 and IsNumeric(La) = True Then MyPenisRocks


Top
 Profile  
 
PostPosted: Wed Jul 29, 2009 5:40 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
That's not an If.. Then statement. That is for another lesson.


Top
 Profile  
 
PostPosted: Tue Nov 02, 2021 10:09 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 54107
XIII280.1BettCHAPSoloMoonXVIIJacoPeruAstrvisuTescWelcwwwnTescSALOTescStouCathStriZoneHaylDeko
AtlaFiskHighwwwrLacaNaivLacaDolbBoutAntoKeviRabbMikeDesiLuciIsaaGiusNiveFranGreeViteMariDavi
GezaRoadMichGrimWoveCotoWindELEGSilvSilvMidwSelaHenrNormRapaMahlErnsVentFranDunaMobiStabPete
HoneSurvNotaCityDamiSileNeriZoneDaniDisnHappRobiGameThatZoneRighMarkHeavRondZoneJessEdwiZone
SwarXIIIBRCGLoviRHZNZoneFranAmerZoneBernZoneZoneProdZoneGellZoneFutuMataZoneJeanBellSingDolb
ZoneJasoDaleSoupSmarCandElecKurtBookBookDisnBookSwarInspJuliPlacFedESauvwwwbAlpiVHDLshouCelt
MagiWindNickHautHellotoowwwmwwwnWindAdobWindBorkClorIslaAdvaWindPhilPeteBlacErroBlueAriaLife
OwenDarkNicoThomKrieHerbXVIIXVIIPistJourFredAtarDaniGarbDickSporSonyXVIIAntoXIIIAnchNencFilm
DolbJohncaseSecrVietGeorFJuvCorpSupeHighCharXVIIOverOZONLewiArztHappLudwCambEverJohaSoupSoup
SoupVideDrivBookGoldAbraRockThorDougNimrAlexEnhainsituchkasFarhSony


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group