+ Reply to Thread
Results 1 to 5 of 5

CLng apparently not working

  1. #1
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    218

    CLng apparently not working

    I have a userform where values in TextBoxes are used in calculations for other textboxes.
    I use the following code to do this.
    Please Login or Register  to view this content.
    End Sub
    My problem is that TextBox2 has a value of ".46" but GM1 has a value of 0 and the other G values are either 0 or 1 The calculated values are all zeros
    What can be going wrong?
    Last edited by Osprey2; 01-03-2024 at 10:54 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291

    Re: CLng apparently not working

    CLng means convert to Long Integer. For decimals, you can use CDbl instead.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    218

    Re: CLng apparently not working

    I had left CLng in by mistake the original code used the correct CDbl . This version behaves exactly the same way. The variables are all valued as 0 or 1 even though the textboxes they refer to all have text formatted numbers.
    In case it helps GM1 and GLLY are 0, GALY and GTLY are 1. The calculated TextBoxes have values of 0
    John

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,291

    Re: CLng apparently not working

    I missed the fact you have also declared the variables as Long. Make them Double.

  5. #5
    Forum Contributor
    Join Date
    02-01-2021
    Location
    Manchester
    MS-Off Ver
    365
    Posts
    218

    Re: CLng apparently not working

    I have not sent an example of the problem because when I provided a sheet to provide the value in Textboxes 1,4,5 and a copy of the userform all worked as it should.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Preventing An Error using CLng When Expression Contains Alpha
    By Jenn68 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2019, 08:41 AM
  2. [SOLVED] CLng strange behaviour
    By ziomocci in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-08-2017, 04:16 AM
  3. [SOLVED] CLng help please
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2016, 05:46 PM
  4. [SOLVED] Error message of CLng
    By gordonf35 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-11-2012, 05:21 PM
  5. [SOLVED] Prevent Clng from dropping Time off returned Serial value
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2012, 04:44 PM
  6. VB Error in CLng
    By SMILE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2011, 03:48 AM
  7. Error using Clng function in vba to convert string to long data type
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2011, 06:12 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1