VBA to VB.net

stianj

Member
Joined
Aug 29, 2011
Messages
6
Programming Experience
Beginner
I have a code that works perfectly in VBA, but when I try to use it for VB.net purpose, I get this error message: "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))".

This is the code I'm working with (for Autodesk Inventor application) Anyone knows what the problem might be?


Structure udtPartInfo 
   Public Number As Integer 
   Public ReferencedFile As String 
End Structure 

Sub Main RenumberBalloonsToFirstSheet() 

   If ThisApplication.ActiveDocumentType <> _ 
                                         kDrawingDocumentObject Then 
      MsgBox ("A drawing must be active.")
      Exit Sub 
   End If 
  
   Dim drawDoc As DrawingDocument 
   drawDoc = ThisApplication.ActiveDocument 

   Dim baseSheet As Sheet 
   baseSheet = drawDoc.Sheets.Item(1) 

   Dim valSet As BalloonValueSet 
   valSet = baseSheet.Balloons.Item(1).BalloonValueSets.Item(1) 
   Dim drawBOM As DrawingBOM 
   drawBOM = valSet.ReferencedRow.Parent 
   Dim partInfo() As udtPartInfo 
   ReDim partInfo(drawBOM.DrawingBOMRows.Count - 1) 
   
   Dim itemColumn As Integer 
   Dim i As Integer 
   For i = 1 To drawBOM.DrawingBOMColumns.Count 
      If drawBOM.DrawingBOMColumns.Item(i).PropertyType = _ 
                                        kItemPartsListProperty Then 
         itemColumn = i 
         Exit For 
      End If 
   Next 
   
   For i = 1 To drawBOM.DrawingBOMRows.Count 
      Dim drawBOMRow As DrawingBOMRow 
      drawBOMRow = drawBOM.DrawingBOMRows.Item(i) 

      Dim partDef As PartComponentDefinition 
      partDef = drawBOMRow.BOMRow.ComponentDefinitions.Item(1) 
      partInfo(i - 1).ReferencedFile = partDef.Document.FullFileName 
      
      partInfo(i - 1).Number = drawBOMRow.Item(itemColumn).Value 
   Next 
    
   For i = 2 To drawDoc.Sheets.Count 
      Dim currentSheet As Sheet 
      currentSheet = drawDoc.Sheets.Item(i) 

      Dim checkBalloon As Balloon 
      For Each checkBalloon In currentSheet.Balloons 

         Dim matchFound As Boolean 
         matchFound = False 
         Dim valueSet As BalloonValueSet 
         valueSet = checkBalloon.BalloonValueSets.Item(1) 
         Dim checkFilename As String 
         checkFilename = _ 
                      valueSet.ReferencedFiles.Item(1).FullFileName  

         Dim j As Integer 
         For j = 0 To UBound(partInfo) 
            If checkFilename = partInfo(j).ReferencedFile Then 

               matchFound = True 
               If valueSet.ItemNumber <> partInfo(j).Number Then 
                  valueSet.OverrideValue = partInfo(j).Number 
               End If 
               Exit For 
            End If 
         Next 
      Next 
   Next 
End Sub
 
Last edited by a moderator:
Your code is quite hard to read. Please just post plain text inside
 tags.
 
It was barely better because you had removed the colouring but you hadn't added the formatting tags that I asked for. I have added them myself so it's now much more readable. Please always format your code snippets in future.

Apart from that, it might help to know where in the code the error occurs.
 
Sorry about that, and thanks for the help. Well, I really don't know where the error occurs. None of the lines get highlighted, I only receive the error message when I'm running the code. I suspect it has something to do with the udtPartInfo paramter defined at top. The code runs great in VBA if I use "Private Type udtPartInfo", but I can't get it to work with VB.net. Should I use anything other than structure maybe?
 
That's part of the problem, it doesn't break in the debugger. Everything seems OK. Then I try to save it and exit, and then it gives me the error message regarding an incorrect paramter.
 
I've got some additional information on the error message, maybe someone can understand where the error is?

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DrawingBOMRow.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
 
Hmm, I thought so. It's defined in line 27. And it workss perfectly in VBA. So I can't understand why it doesn't work.
 
Back
Top