Three easy functions.

Posted on 1999-12-07
Medium Priority
Last Modified: 2010-05-02
Im a beginner. I need to know how to create three funtions that will do this:
First Function:
Tells you if the number inputed is odd
Second Function:
Tells you the positoin of the alpahbet that the letter is inputed (i.e if the letter D is inputed then itll return 4)
Third Function:
Swap two variables using BelVal (what ever that is) Return boolean

Thanks for help!!!
Question by:cdc_sickle
  • 2

Accepted Solution

trillo earned 200 total points
ID: 2263496
Option Explicit

Private Sub Form_Click()
    Dim a As Integer, b As Integer
    a = 3
    b = 4
    Me.Print IsOdd(3)
    Me.Print AlfaPos("a")
    Me.Print "A="; a; "B="; b;
    Call Swap(a, b)
    Me.Print "Swapped: "; "A="; a; "B="; b;
End Sub

Private Function IsOdd(inum As Integer) As Boolean
    IsOdd = Not (inum Mod 2)
End Function

Private Function AlfaPos(iLetter As String) As Integer
    Dim alfa As String
    alfa = "abcdefghijklmnopqrstuvwxyz"
    AlfaPos = InStr(alfa, iLetter)
End Function

Private Function Swap(ByRef a As Integer, ByRef b As Integer) As Boolean
    Dim tmp As Integer
    tmp = a
    a = b
    b = tmp
    Swap = True
End Function

Is this what you want?

Expert Comment

ID: 2263499
Actually, in my answer.... the swap function does not use ByVal, because it's impossible to swap two numbers, when passing them as ByVal arguments and returning a Boolean variable. They should be passes ByRef.

Author Comment

ID: 2263520
Thank you so much!!!

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question