Data not being written
-
Monday, March 05, 2012 7:12 PM
I am (very) new to the C++ / .NET interoperability world so if I use incorrect terminology please accept my apologies. I have a Sub
Public Sub CacheAssignments()
' check that we have a named scenario
If m_scenario Is Nothing Then
Return
End IfDim msg As String
Dim ModelData As VSIOSFEDLib.CVSModelDataX
ModelData = New VSIOSFEDLib.CVSModelDataX()
Dim CacheDirectory As String
CacheDirectory = ModelData.ModelItem("PREFERENCES", "cache_directory")
If CacheDirectory = "" Then
MsgBox("Cache Directory " & CacheDirectory & " does not exist", MsgBoxStyle.Information)
Return
End IfDim FileName As String
FileName = (CacheDirectory & "\" & m_scenario.Name & ".sta")Dim StationData As VSIOSFEDLib.CVSModelStation = Nothing
Dim xmlWrite As XmlConfig.ConfigFile
xmlWrite = New XmlConfig.ConfigFile()'Dim xmlList As XmlConfig.ConfigList
'xmlList = New XmlConfig.ConfigList()'code here to load up items for writing to FileName
For Each config As VSIOSFEDLib.CVSModelStation In ModelData.ModelStationList
xmlWrite.addValue("StationName", config.Name)
StationData = ModelData.getStationInfo(config.Name)xmlWrite.addValue("someName", StationData.Name)
xmlWrite.addValue("DisplayName", StationData.DisplayName)For Each sta As VSIOSFEDLib.CVSModelFederateAssignment In StationData.FederateAssignmentTable
xmlWrite.addValue("Federate", sta.Federate.Name)
xmlWrite.addValue("Assignment", sta.Assignment)xmlWrite.writeToFile(FileName)
Next
Next'xmlWrite.writeToFile(FileName)
ConsoleForm.AddMessage("Station Assignments cached to """ & FileName & """")
End Sub
The problem that I don't understand is that the values getting passed to the unmanaged layer with each iteration are correct but after all is said and done the file that is written has the same data written multiple times. My guess is there is more explanation needed but I'm not sure how to amplify the information at this time.
Thanks in advance for whatever help might be provided.
Midgel, Penguin Space Pilot
All Replies
-
Wednesday, March 07, 2012 10:13 AMModerator
Hi Midgel,
Welcome to the MSDN Forum.
Is iteration you have mentioned this one?
For Each sta As VSIOSFEDLib.CVSModelFederateAssignment In StationData.FederateAssignmentTable xmlWrite.addValue("Federate", sta.Federate.Name) xmlWrite.addValue("Assignment", sta.Assignment) xmlWrite.writeToFile(FileName) NextDid you check the source data? Is it the same?
After a quick review about your code, I would suggest you put the xmlWriter instance in the first For Each clause, and I have made a few other changes:
Public Sub CacheAssignments() ' check that we have a named scenario If m_scenario Is Nothing Then Return End If Dim msg As String Dim ModelData As VSIOSFEDLib.CVSModelDataX ModelData = New VSIOSFEDLib.CVSModelDataX() Dim CacheDirectory As String CacheDirectory = ModelData.ModelItem("PREFERENCES", "cache_directory") If CacheDirectory = "" Then MsgBox("Cache Directory " & CacheDirectory & " does not exist", MsgBoxStyle.Information) Return End If Dim FileName As String FileName = (CacheDirectory & "\" & m_scenario.Name & ".sta") Dim StationData As VSIOSFEDLib.CVSModelStation = Nothing Dim xmlWrite As XmlConfig.ConfigFile 'Dim xmlList As XmlConfig.ConfigList 'xmlList = New XmlConfig.ConfigList() 'code here to load up items for writing to FileName For Each config As VSIOSFEDLib.CVSModelStation In ModelData.ModelStationList xmlWrite = New XmlConfig.ConfigFile() xmlWrite.addValue("StationName", config.Name) StationData = ModelData.getStationInfo(config.Name) xmlWrite.addValue("someName", StationData.Name) xmlWrite.addValue("DisplayName", StationData.DisplayName) For Each sta As VSIOSFEDLib.CVSModelFederateAssignment In StationData.FederateAssignmentTable xmlWrite.addValue("Federate", sta.Federate.Name) xmlWrite.addValue("Assignment", sta.Assignment) Next xmlWrite.writeToFile(FileName) Next 'xmlWrite.writeToFile(FileName) ConsoleForm.AddMessage("Station Assignments cached to """ & FileName & """") End Sub
I hope this will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Marked As Answer by Mike FengMicrosoft Contingent Staff, Moderator Wednesday, March 14, 2012 1:21 PM

