Function procedure

On this one , I want to do 2 things
1) write a function procedure that receives the value stored in an integer variable named intNumber. The procedure, named DivideNumber, should divide the integer by 2, and then return the result (which may contain a decimal place)
2)write an appropriate statement to call the Dividenumber function created above.

Any help would be greatly appreciated... thx.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here you have one solution:

Private Function DivideNumber(ByVal Number As Integer) As Double
     Dim result As Double
     result = (Number / 2)

     Return result
End Function

to call the functio you must do the following:

Dim number As Double
Dim intNumber As Integer

intNumber = 2
number = DivideNumber(intNumber)

That's it.
Fahad MukhtarDistinguished EngineerCommented:
This sounds like homework and experts answering those questions can get suspended..  you better give it a try at least, as it wont be too difficult for you.... have some problem ask us...
skathariAuthor Commented:
its not homework.... these are just practice for us. What I am trying to get, is an example simple just like this, and then try to remember it and see how they do it.
In other words, its optional for me to practice... practice gets you better.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

FYI .....

Here is where I found good examples for working in VB.Net


Link for ASP programs... 

in VB.NET this can be wriiten as:

Private Function DivideNumber(ByVal Number As Integer) As Double
     return Number / 2

End Function

then to use this function:

Private Sub UseFunction()

    Dim intTest as Integer = 100
    Dim dblAnswer as Double = DivideNumber(intTest)

    MessageBox.Show("DivideNumber(" & intTest & ") = " dblAnswer)

End Sub

Private Function DivideNumber(ByVal Number As Integer) As Double
     return Number / 2

End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oops, minor type:

should read:

MessageBox.Show("DivideNumber(" & intTest & ") = " & dblAnswer)
skathariAuthor Commented:
but, dont we have to add a button?
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hi skathari,

You didn't ask for a GUI on top of the function.  You simply asked for a function to do X.  The button code is not part of the function.

At any rate, it sounds like you need to see some complete working code...

Mike TomlinsonMiddle School Assistant TeacherCommented:
(hit the submit button on accident)

Here is a very simple app that uses the function provided by Arthur_Wood:

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox1.Location = New System.Drawing.Point(8, 8)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(128, 20)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = "Enter an Integer Here"
        Me.Button1.Location = New System.Drawing.Point(144, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(96, 24)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "DivideNumber()"
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label1.Location = New System.Drawing.Point(248, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(144, 24)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Result"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(400, 38)
        Me.Name = "Form1"
        Me.Text = "Example of Divide by 2 Function"

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim value As Integer
            value = Integer.Parse(TextBox1.Text)
            Label1.Text = DivideNumber(value).ToString
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Function DivideNumber(ByVal Number As Integer) As Double
        Return Number / 2
    End Function

End Class
skathariAuthor Commented:
thank you guys... it is working perfect!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.