Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Additions with variables in VBA
#1
Description:

This code calculates the sum of two numbers and displays the result in a message box.

Example:

Sub SumNumbers()
    Dim num1 As Double
    Dim num2 As Double
    Dim sum As Double

    num1 = 5
    num2 = 3
    sum = num1 + num2

    MsgBox "The sum of " & num1 & " and " & num2 & " is " & sum & "."
End Sub

Explanation:

This code defines a subroutine named SumNumbers. 
It declares three variables num1, num2, and sum to hold the values of two numbers and their sum. 
It then sets the values of num1 and num2 to 5 and 3, respectively. 
The sum of the two numbers is calculated and displayed in a message box.

The Dim statement is used to declare variables. 
In this case, we use the Double data type to store numbers with decimal places. 
The & operator is used for string concatenation, combining text and variable values in the message box.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variables in VBA Qomplainerz 0 166 07-26-2023, 08:13 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)