Consulting

Results 1 to 7 of 7

Thread: Solved: Problem with declarations and Str function

  1. #1
    VBAX Regular
    Joined
    Jul 2011
    Posts
    33
    Location

    Solved: Problem with declarations and Str function

    Hello, the problem I have is that running a macro I made on Excel 2003 on the 2007 version it demands all variables declarations, so I did it, but now it shows an error on the Str function. Here is the code:
    [vba]Public Sub reporte(ByRef maquinas() As String, ByRef cantidad_maquinas() As Double)
    Dim n, fila, i, j, maqs_encontradas As Integer
    n = UBound(maquinas)
    fila = 1
    For i = 0 To n
    maqs_encontradas = 0
    With Sheets("REPORTE")
    .Cells(fila, 1) = Str(cantidad_maquinas(i)) & " " & maquinas(i)
    .Cells(fila + 1, 1) = "MÁQUINA"
    .Cells(fila + 1, 2) = "PLACA"
    .Cells(fila + 1, 3) = "UBICACIÓN"
    .Cells(fila + 1, 4) = "ESTADO"
    End With
    Next
    end sub
    [/vba]

    It marks "Str" and says that doesn't find the proyect or library.

    Thanks in advance

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Use CStr but a string conversion is explicit since you are using concatenation.

    Always use as the first line of code:
    [vba]Option Explicit[/vba]

  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    do you even have to convert to a string to concatenate?
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    When concatenating a double to a string, I would use CStr() for the double.

  5. #5
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    for good practice or out of necessity?
    ------------------------------------------------
    Happy Coding my friends

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,722
    Location
    To get that error (though Str is unnecessary as has been remarked) I would suspect you have a missing reference. In the VB Editor, select Tools -> References and see if any are prefixed with 'MISSING:'
    Be as you wish to seem

  7. #7
    VBAX Regular
    Joined
    Jul 2011
    Posts
    33
    Location
    The problem was solved using CStr. Thanks everyone

Posting Permissions

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