Results 1 to 3 of 3

Thread: Help with functions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    I am making a program, and would like to have something like this in a BUTTON:

    Code:
    Game(Action)
    in a module i have
    Code:
    Function Game(Action As String) As Boolean
    Select Case Action
        Case "Activate"
        Case "DeActivate"
            Case Else
    End Select
    End Function
    stuff like that

    *BUT
    when i use this,
    the code in the button gets a SPACE between
    Game and (Action)

    Sooo.. i've tryed many things, and it doesn't work, OR it just keeps adding a space



    I want to use this method, because its just simple and if i have to change something, then i just change it in the module and not fool around with ALL The forms etc..

    Thanks..

  2. #2
    Guest
    why do you have it as Boolean if it has no return value??
    but, all you have to do to remove the space is

    Code:
    Call Game(Action)

  3. #3
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    If you change it so that it has no return value, you could just use:

    Code:
    Game Action
    You might find tha whole game a lot easier to program if you use enums instead of using strings, eg:

    Code:
    'Module
    Public Enum Actions
         Activate = 1
         DeActivate
         'OtherActions here
    End Enum
    
    Sub Game(Action As Actions)
    
    Select Case Action
         Case Activate
             '...
         Case DeActivate
             '...
         Case Else
             '...
    End Select
    
    End Sub
    
    'Code Elsewhere
    Call Game(Activate)
    Enumeration is a way to make your job easier. That's really all it does. It saves each word in the Enum...End Enum block as an integer. So Activate is actually equal to 1, DeActivate is actually equal to 2. You know how when you have a Boolean and you press equals and a little listbox appears saying True and False (this is called IntelliSense) the same happens, so when you enter:

    Code:
    Call Game(
    That little box will appear giving you all the possible values for Action (in this case Activate and DeActivate) so you can just click on one of them, meaning typos are nearly impossible.

    (BTW Enum is short for Enumeration which means (basically) Giving each value (like Activate) a number value (1 in this case)

    Also, you don't have to type in the value for each one, eg:

    Code:
    Public Enum MaritalStatus
         Single = 1
         Married = 2
         Divorced = 3
         Remarried = 4
         Widow = 5
         Widower = 6
    End Enum
    is that same as:

    Code:
    Public Enum MaritalStatus
         Single = 1
         Married
         Divorced
         Remarried
         Widow
         Widower
    End Enum
    (VB just counts up one from the previous entry)

    You could specify you own value for each one if necessar, though:

    Code:
    Enum Ages
         Baby = 3
         Child = 12
         Teen = 19
         GrownUp = 65
         Pensioner = 100
    End Enum
    But you must remember that 'Baby' is just another way of saying '3'. So if you think you are being smart by doing this:

    Code:
    Enum Ages
         Baby = 3
         Child = 12
         Teen = 19
         GrownUp = 65
         Pensioner = 100
    End Enum
    
    
    Sub ShowAgePeriod(Age As Ages)
    
    If Age < Baby Then
        Print Baby
    ElseIf Age < Child
        Print Child
    ElseIf Age < Teen
        Print Teen
    ElseIf Age < GrownUp
        Print GrownUp
    ElseIf Age < Pensioner
        Print Pensioner
    Else:
        MsgBox("Please enter a valid age"), , "Error"
    End If
    
    End Sub
    
    '....In code somewhere
    
    Call ShowAgePeriod(27)
    
    'This will not show 'GrownUp' is will show '65'
    I hope you understand Enums, how useful thay can be, and when to use them.

    Hope it helps,

    Moi
    Courgettes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width