Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:29:51+00:00 2026-05-16T02:29:51+00:00

I have the following code : Dim L as Integer Dim R as Integer

  • 0

I have the following code :

Dim L as Integer
Dim R as Integer
Dim a as Integer

a=((L+R)/2)

Now (L+R) exceeds limit of Integer.
In order to handle this case:
I have following three options:

  1. Define L (or R) as Long
  2. Write a= ((CLng(L)+R)/2)
  3. Declare new variable as Long :

Like this

Dim S as Long
S=S+L+R

I am confused which one is the best to implement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:29:52+00:00Added an answer on May 16, 2026 at 2:29 am

    I’d pick #2. I think (not sure) that this uses a little less memory than #1 because there’s only one Long -value in the equation where as changing L or R to Long would require space for 2 Long values.

    I’m thinking #2 and #3 might end up looking the same (or pretty damn close) after compile and I personally think that in this case an extra variable wouldn’t make it more readable. The difference of course is that in #2 the result of the L+R might not need to be saved anywhere, but only moved between registers for the calculation.

    I’m thinking alot here, but I’m posting this partly because I hope that if I’m wrong, someone would correct me. Anyway, with the reasoning above, I’d go with #2. Edit: at least I’m quite certain that if one of the options uses less memory than the others, it’s #2, but they might all be the same in that regard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in vb6 - dim iFreeFile as integer iFreeFile =
I have the following code: Dim i As Integer = dtResult.Rows.Count For i =
I have the following code to get the object type of a collection: Dim
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have the following code: Private Sub SortWorksheet(ByVal sheet As Worksheet) Dim sStartColumn Dim
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have the following code: Dim dbHousing As New dcHousingDataContext Dim pullresidents = From
I have following code that is generating random no. between 1 to 10. This
I have the following code in VB.net Dim bytIV() As Byte = {121, 241,
i have the following code which walks through an Excel file and this works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.