Results 1 to 5 of 5

Thread: VBA NooB Question

  1. #1
    Member
    Join Date
    2007-02
    Location
    Paramount, California
    Posts
    35
    Login to Give a bone
    0

    Question VBA NooB Question

    I am new to this forum and to VBA. I am trying to write an if statement which would check to see if number is decimal or not. I tried looking on MSDN but really could not understand what was going on. Thanks you.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: VBA NooB Question

    What code have you got so far? When you say "decimal", do you mean base system (e.g. binary, hex, octal, decimal) or data type of double as opposed to an integer?
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2007-02
    Location
    Paramount, California
    Posts
    35
    Login to Give a bone
    0

    Default Re: VBA NooB Question

    Code:
    Public Sub CalculateNorthLambert200(strMapNumXAdj, strMapNumYAdj, strNorthMap200)
    strMapNumXAdj = ""
    strMapNumYAdj = ""
    strNorthMap200 = ""
        
    sngMapNumXAdj = intMapNumX / 4             'Trying to check if this answer is a decimal
    sngMapNumYAdj = intMapNumY / 6            'Trying to check if this answer is a decmal
        
    strMapNumXAdj = sngMapNumXAdj            'Trying to transfer decimal number to string to check for "."
    strMapNumYAdj = sngMapNumYAdj           'Trying to transfer decimal number to string to check for "."
    
        
        
    strNorthMap200 = strMapNumXAdj & "-" & strMapNumYAdj & "-" & "2"     'Concatinate my string
        
    
    End Sub
    Last edited by Opie; 2008-01-15 at 11:02 PM. Reason: [CODE] tags added, see Moderator Note

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: VBA NooB Question

    See my inline comments. You should be declaring the type of your variables. If you don't, they are automatically typed as Variant.

    BTW, Please use the code tags available in the advanced editor.
    Code:
    Public Sub CalculateNorthLambert200(strMapNumXAdj As String, strMapNumYAdj As String, strNorthMap200 As String)
    strMapNumXAdj = "" If you clear the arg's here, why have arg's?
    strMapNumYAdj = ""
    strNorthMap200 = ""
        Where do you declare the other var's prefixed with sng and int? They should be dimmed as follows:
    iMapNumXAdj As Integer 'Use Integer, there is no Single data type
    dMapNumX As Double 'Double data type will give you "decimal"
    
    sngMapNumXAdj = intMapNumX / 4             'Trying to check if this answer is a decimal
    sngMapNumYAdj = intMapNumY / 6            'Trying to check if this answer is a decmal
        
    strMapNumXAdj = sngMapNumXAdj            'Trying to transfer decimal number to string to check for "."
    strMapNumYAdj = sngMapNumYAdj           'Trying to transfer decimal number to string to check for "."
    
        
        
    strNorthMap200 = strMapNumXAdj & "-" & strMapNumYAdj & "-" & "2"     'Concatinate my string    
    
    End Sub
    C:> ED WORKING....

  5. #5
    Active Member
    Join Date
    2007-12
    Posts
    68
    Login to Give a bone
    0

    Default Re: VBA NooB Question

    Haa haa, I remember MY first app!

    You are passing your "numbers" as strings, then wanting to convert to numeric, then back again to strings for some sort of output. It might be easier if you stick with numbers, which are smaller, quicker, and a whole lot cleaner to deal with, than strings.

    Contrary to what was said, there IS a "Single' data type, although there isnt much benefit nowadays to using it - so use doubles.

    Im assuming that by 'decimal', you want to check to see if the numbers are WHOLE numbers or not. First, you may want to see if your strings are even NUMBERS ... you are passing them as strings. So use the "Isnumeric' function to make sure there arent any letters inside those strings. Once you know you have a genuine number there, convert to double. Then check to see if its a whole number by comparing it to an integer version of the number.

    Something like this: *** warning** code typed on the fly ...

    Code:
    Dim tmpDouble as Double
    
    if IsNumeric(strNorthMap200) then               ' its a number
       tmpDouble =Cdbl(strNorthMap200)           ' convert to Double precision
       if Int(tmpDouble)=tmpDouble  then            '  its a whole number!
         msgbox "This number is a Whole Number"
       else                                                        ' Nope - has digits to the right of the decimal
         msgbox "This Number is NOT a whole number"
      end if
    end if

    ' if you dont get a message box at ALL, then your string isnt even convertible
    to a number....
    Last edited by Opie; 2008-01-28 at 07:33 PM. Reason: [CODE] tags added

Similar Threads

  1. 2013: noob levels & grid question
    By deafred in forum Revit - Platform
    Replies: 0
    Last Post: 2013-03-02, 11:11 AM
  2. noob question about Families
    By kevin681396 in forum Revit MEP - Families
    Replies: 1
    Last Post: 2011-02-28, 01:36 PM
  3. Noob Question on setting elevations
    By jamesm in forum AutoCAD General
    Replies: 15
    Last Post: 2009-04-01, 11:39 AM
  4. Warning! Retreaded Noob question...
    By crbateman in forum AutoLISP
    Replies: 2
    Last Post: 2009-03-18, 02:54 PM
  5. Super Noob Wall Question
    By kimudang in forum Revit Architecture - General
    Replies: 10
    Last Post: 2006-01-27, 10:08 PM

Posting Permissions

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