Solved

Can not run code on 64 byte

Posted on 2014-04-08
5
198 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 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
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
Comment Utility
Thank you MacroShadow

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

Montrof
0
 
LVL 26

Expert Comment

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

Expert Comment

by:tel2
Comment Utility
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
Comment Utility
Good point typo
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

772 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

10 Experts available now in Live!

Get 1:1 Help Now