Solved

Can not run code on 64 byte

Posted on 2014-04-08
5
200 Views
Last Modified: 2014-04-08
The following code will not run on Excel 2013 64 byte,  I would like to be able to run on 32 byte and 64 byte


Private Declare Function GetPrivateProfileStringA Lib _
                                                  "kernel32" (ByVal strSection As Any, _
                                                              ByVal strKey As String, ByVal strDefault As Any, _
                                                              ByVal strReturnedString As Any, _
                                                              ByVal lngSize As Any, ByVal strFileNameName As Any) As Long

Open in new window


Function GetPrivateProfileString32(ByVal strFileName As String, _
                                   ByVal strSection As String, ByVal strKey As String, _
                                   Optional strDefault) As String
    Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = ""
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, _
                                        strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
End Function
0
Comment
Question by:montrof
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39987229
Try this:
#If Win64 Then
    Private Declare PtrSafe Function GetPrivateProfileStringA Lib _
                                                      "kernel32" (ByVal strSection As Any, _
                                                                  ByVal strKey As String, ByVal strDefault As Any, _
                                                                  ByVal strReturnedString As Any, _
                                                                  ByVal lngSize As Any, ByVal strFileNameName As Any) As Long
#Else
    Private Declare Function GetPrivateProfileStringA Lib _
                                                      "kernel32" (ByVal strSection As Any, _
                                                                  ByVal strKey As String, ByVal strDefault As Any, _
                                                                  ByVal strReturnedString As Any, _
                                                                  ByVal lngSize As Any, ByVal strFileNameName As Any) As Long
#End If

Function GetPrivateProfileString32(ByVal strFileName As String, _
                                   ByVal strSection As String, ByVal strKey As String, _
                                   Optional strDefault) As String
    Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = ""
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, _
                                        strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
End Function

Open in new window

0
 
LVL 1

Author Comment

by:montrof
ID: 39987243
Thank you MacroShadow

When running on 32 byte I get error type mismatch for strDefault.

Montrof
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39987256
I don't know. That is a problem with your original code (I only added 64bit support). Please ask new question.
0
 
LVL 12

Expert Comment

by:tel2
ID: 39987356
BTW, Montrof, it's "32 bit" and "64 bit", not "32 byte" and "64 byte".  Only a factor of 8 out, though.
0
 
LVL 1

Author Comment

by:montrof
ID: 39987358
Good point typo
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now