Solved

Can not run code on 64 byte

Posted on 2014-04-08
5
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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 how to use longer labels with horizontal bar charts instead of the vertical column chart.

626 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