직업이 프로그래머가 아니라 해당 지식이 전무한 상황입니다
사용중인 SW 의 API 기능을 활용해 보고자 일단 SW 에 있는 예제 파일을 VBS 파일로 만들어서 작동 시켜보니 잘 됩니다
이제 이 파일을 엑셀 메크로로 만들어서 써보려는데 당연히?? 작동이 안됩니다....
앞서서 간단한 예제들은 엑셀로 변환시켜 작동 시켜봤는데 이번거는 길어서 잘 모르는거도 있고
엑셀에서 디버그로 올라오는거 보면 저게 왜 문제인지도 잘 모르겠고 하는 상황입니다
아래는 VBS 파일의 내용입니다
Option Explicit
SetLocale("en-us")
Dim Synergy
Dim SynergyGetter
On Error Resume Next
Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%"))
On Error GoTo 0
If (Not IsEmpty(SynergyGetter)) Then
Set Synergy = SynergyGetter.GetSASynergy
Else
Set Synergy = CreateObject("Synergy.Synergy")
End If
Dim StudyDoc
Set StudyDoc = Synergy.StudyDoc()
' Get the name of the .out file associated with the flow results.
' NOTE: This assumes a Flow analysis sequence was run.
Dim lName
lName = StudyDoc.GetResultPrefix("Flow")
Dim lOutName
lOutName = lName & ".out"
' Create and Populate the ScreenOutput Class for the lOutName
Dim lMessages
Set lMessages = New ScreenOutput
lMessages.LoadOutputFile(lOutName)
Dim MM, lStr
' Find the Total Projected Area
' return the array of numerical values associated with the first instance of Message ID (MSCD) 39410
' MSCD 39410 1 0 0 0 0 0 5
' Total projected area = %11.4G
' m^2,1,1
' Note: Please see .../data/dat/shared/cmmesage.dat for format details
Set MM = lMessages.GetMessage(39410,1)
lStr = " Total Proejcted Area = " & CStr(MM.GetFloat(0))
MsgBox CStr(lStr)
' Read Maximum Injection pressure and the time it occurred
' return the array of numerical values associated with the last instance of Message ID (MSCD) 39410
' MSCD 41400 1 0 0 0 0 0 5
' Maximum injection pressure (at %11.4G) = %11.4G
' s,1,2
' Pa,1,1
' Note: Please see .../data/dat/shared/cmmesage.dat for format details
Set MM = lMessages.GetMessage(41400,0)
lStr = "Maximum injection pressure occured at " & CStr(MM.GetFloat(1)) & " Pressure = " & CStr(MM.GetFloat(0))
MsgBox CStr(lStr)
MsgBox "Script Complete"
' ---- Message class
Class Message
Private mMSCD ' MSCD Message ID
Private mNumString ' Number of Strings associated with the Message
Private mNumFloat ' Number of Floats Associated with the Message
Private mStrings() ' The Strings Associated with the Message
Private mFloats() ' The Numerical Values Associated with the Message
Public Sub SetMSCD(aMSCD)
mMSCD = aMSCD
End Sub
Public Sub SetNumString(aNumString)
mNumString = aNumString
End Sub
Public Sub SetNumFloat(aNumFloat)
mNumFloat = aNumFloat
End Sub
Public Sub AddFloat(aFloat)
mNumFloat = mNumFloat + 1
ReDim Preserve mFloats(mNumFloat)
mFloats(mNumFloat-1) = aFloat
End Sub
Public Sub AddString(aString)
mNumString = mNumString + 1
ReDim Preserve mStrings(mNumString)
mStrings(mNumString-1) = aString
End Sub
Public Function GetMSCD()
GetMSCD = mMSCD
End Function
Public Function GetString(aIndex)
GetString = ""
If aIndex >= 0 And aIndex < mNumString Then
GetString = mStrings(aIndex)
End if
End Function
Public Function GetFloat(aIndex)
GetFloat = ""
If aIndex >= 0 And aIndex < mNumFloat Then
GetFloat = mFloats(aIndex)
End if
End Function
Public Function GetNumString()
GetNumString = mNumString
End Function
Public Function GetNumFloat()
GetNumFloat = mNumFloat
End Function
Private Sub Class_Initialize
mMSCD = -1
mNumString = 0
mNumFloat = 0
End Sub
End Class
Class ScreenOutput
Private mMessages() ' Array of Messages associate with the screen output File
Private mNumMessages ' Number of messages in the screen output file
Public Function LoadOutputFile(aFile)
Const ForReading = 1
Dim FS
Set FS = CreateObject("Scripting.FileSystemObject")
Dim File
Set File = FS.OpenTextFile(aFile, ForReading)
While Not File.AtEndOfStream
Dim ID
ID = -1
' Read the MSCD
Dim Line,lenLine
Line = File.ReadLine
lenLine = len(Line)
If Not File.AtEndOfStream or lenLine >= 1 Then
ID = Line
Dim curMessage
Set curMessage = New Message
curMessage.SetMSCD(ID)
' Read the number of strings
Line = File.ReadLine
lenLine = len(Line)
If Not File.AtEndOfStream or lenLine >= 1 Then
Dim numString
numString = Line
' Read Strings
Dim i
For i = 1 To numString
Line = File.ReadLine
lenLine = len(Line)
If Not File.AtEndOfStream or lenLine >= 1 Then
CurMessage.AddString(Line)
End if
Next
End if
' Read the number of floats
Line = File.ReadLine
lenLine = len(Line)
If Not File.AtEndOfStream or lenLine >= 1 Then
Dim numFloat
numFloat = Line
' Read Floats
For i = 1 To numFloat
Line = File.ReadLine
lenLine = len(Line)
If Not File.AtEndOfStream or lenLine >= 1 Then
CurMessage.AddFloat(Line)
End if
Next
End If
' Add current message to the list
AddMessage(CurMessage)
End If
Wend
File.Close
End Function
Public Sub AddMessage(aMessage)
mNumMessages = mNumMessages + 1
ReDim Preserve mMessages(mNumMessages)
Set mMessages(mNumMessages-1) = aMessage
End Sub
Public Function GetNumMessages()
GetNumMessages = mNumMessages
End Function
Public Function GetMessage(aMSCD,aOccur)
Set GetMessage = Nothing
Dim j
Dim lFindInstance
lFindInstance = aOccur
If aOccur < 0 Then
lFindInstance = 0
End if
Dim Count
Count = 0
For j = 0 To mNumMessages-1
'MsgBox mMessages(j).GetMSCD &"|"& aMSCD
If CStr(mMessages(j).GetMSCD) = CStr(aMSCD) Then
Count = Count + 1
If Count >= lFindInstance Then
Set GetMessage = mMessages(j)
Exit Function
End if
End if
Next
End Function
Private Sub Class_Initialize
mNumMessages = 0
End Sub
End Class
이걸 엑셀 메크로에 넣어서 첫줄에 sub 메크로명 넣고 중간에 Message Class 위에 End Sub 넣고 살행시켜보면
컴파일 오류 입니다
사용자 형식이 지정되지 않았습니다 라고 뜨면서
아래의 New screenoutput 을 하이라이트 시킵니다
Dim lMessages
Set lMessages = New ScreenOutput
lMessages.LoadOutputFile (lOutName)
검색상으로는 무슨 라이브러리를 추가해야된다고 하면서 설명해주는 것들을 해봤지만
신통치가 않았습니다
제가 프로그래머가 아닌지라 아주 기초적인 뭔가를 모르고 있는건지 혹시 윗내용만 보고 알수 있는게 있을지 질문 남깁니다..