I am trying to programmatically access data from a RAM SS file by following this guide(VB in Excel).
The Excel file crashes when I try to call any method which fetches data from a file eg
Set IStories = IModel.GetStories lNumStories = IStories.GetCount
These methods do work in some cases which must be like 10% of the number of times I've tried across multiple computers.
The input file I am using is correct as it loads correctly in the GUI app.
Also initialization methods always work eg: Set RamDataAcc1 = New RAMDATAACCESSLib.RamDataAccess1 Set RAMDataAccIDBIO = RamDataAcc1.GetDispInterfacePointerByEnum(IDBIO1_INT) RAMDataAccIDBIO.GetDatabaseVersion OpenFile, dVersion dVersion = Round(dVersion, 1) SendToLogFile ("Version: " & dVersion) RAMDataAccIDBIO.LoadDataBase2 OpenFile, "work"
The full file I am using:
Public Sub MyTest() Dim OpenFile As String Dim RamDataAcc1 As RamDataAccess1 Dim RAMDataAccIDBIO As RAMDATAACCESSLib.IDBIO1 Dim dVersion As Double Dim IModel As RAMDATAACCESSLib.IModel Dim IStories As RAMDATAACCESSLib.IStories Dim IStory As RAMDATAACCESSLib.IStory Dim IFloorTypes As RAMDATAACCESSLib.IFloorTypes Dim IBeams As RAMDATAACCESSLib.IBeams Dim IBeam As RAMDATAACCESSLib.IBeam Dim lNumStories As Long Dim lStory As Long Dim strStoryID As String Dim lNumBeams As Long Dim lBeam As Long SendToLogFile ("-------------------------------") OpenFile = "D:\Projects\workDesk\RAM\project\r2.rss" 'Initialize DataAccess Set RamDataAcc1 = New RAMDATAACCESSLib.RamDataAccess1 'Initialize IO interface Set RAMDataAccIDBIO = RamDataAcc1.GetDispInterfacePointerByEnum(IDBIO1_INT) RAMDataAccIDBIO.GetDatabaseVersion OpenFile, dVersion dVersion = Round(dVersion, 1) SendToLogFile ("Version: " & dVersion) RAMDataAccIDBIO.LoadDataBase2 OpenFile, "work" Set IModel = RamDataAcc1.GetDispInterfacePointerByEnum(IModel_INT) Set IStories = IModel.GetStories lNumStories = IStories.GetCount For lStory = 0 To (lNumStories - 1) 'Getting story info Set IStory = IStories.GetAt(lStory) strStoryID = IStory.strLabel 'Get member ID lists on story Set IBeams = IStory.GetBeams IBeams.Filter eBeamFilter_Material, ESteelMat lNumBeams = IBeams.GetCount For lBeam = 0 To lNumBeams - 1 Set IBeam = IBeams.GetAt(lBeam) SendToLogFile ("IBeam: " & lBeam) Next Next SendToLogFile ("END")End Sub
SendToLog is correctly defined and definitely not a problem. Trusted locations, file paths etc are also correct.
Excel just crashes so not sure what more info I can provide.
Thanks for any help!
We are probably going to need to see the model and macro to try and reproduce. If it works on some machines but not others, then will be hard to explain. I recommend trying the Model Move Merge tool. If that always works, that points to a problem in your code.
The Model Move Merge tool works fine. So I guess the problem might be in my setup.
I have uploaded the files here.
Would appreciate your help to find the problem.
You don't appear to close the database in your macro. Review a DA example on Be Communities. It will close the database and release interfaces at the end of the main procedure. You probably have a .usr file in the same directory as where the model is saved and DA can't open the model the next time you try and run the macro.
Answer Verified By: Amit Nambiar