Switch between forms

Switch between forms

dialunau
Advocate Advocate
511 Views
6 Replies
Message 1 of 7

Switch between forms

dialunau
Advocate
Advocate

Hello,

I have a form with a button on it, when I click that button it calls a function that shows an InputListBox.
The problem is that I cannot switch between my main form and the InputListBox I created, so inventor freezes every time I try to run my InputlistBox.
How can I close the main form when I click the button, or switch between my main form to the InputListBox?

0 Likes
Accepted solutions (2)
512 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Is this an ilogic form? If it is it may be set as modal meaning you cannot interact with other elements of inventor while it is open. Here is a the API help that describes modal and non modal. If this isn't the issue can you explain further with some images etc. 

Edit:

The inputlist box always has focus. If your launching the rule from the local form you can use run rule and close form but this is not the case for an external form. Can you explain further the interaction you need between the inputlist box and the form with maybe a video or some images? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 7

dialunau
Advocate
Advocate

Hello, this is the code that runs when I click the button in my form:

 

'// BUTTON CLICK EVENT //
'oDrawDoc is the document file defined as ThisDoc.Document 
Public Sub oButton1_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
		myIinf.RunRule(oDrawDoc,"Rule5")
End Sub

'//// THIS IS THE RULE BEING CALLED BY THE BUTTON ////
Sub Main()
	Dim oOpts(10) As String
	Call Readexisting(oOpts)
	
	Dim oOptNames As New ArrayList
	Dim oSelDim As String
	
	'Populate the array with the information retrieved from the spreadsheet
	For i = 1 To oOpts.Length
		If oOpts(i) = "" Then
			Exit For
		Else
			oOptNames.Add(oOpts(i))
		End If
	Next i
	
	oSel = InputListBox("MYList", oOptNames, "", "SELECT THE OPTION", ListName := "Opts")
	MsgBox(oSel)
End Sub

Public Sub Readexisting(oOpts As Array)
	Dim oXL As String = CStr(ThisDoc.Path) & "\MyXL.xls"
	
	' Get values of the "A" Column in the spreadsheet to show them in the ListBox
	For i = 1 To 10
		If CStr(GoExcel.CellValue(oXL, "Sheet1", "A" & i)) = "" Then
			Exit For
		Else
			oOpts (i) = CStr(GoExcel.CellValue(oXL, "Sheet1", "A" & i))
		End If
	Next i
End Sub


 As you can see, I'm retrieving data from a spreadsheet.

After some test yesterday, I realized that the InputListBox shows correctly when I'm not calling for the excel file, but when I run the rule as it is above,  Inventor cannot switch from my form to the ListBox.

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

Are you able to find the excel sheet? It sounds like there is looping happening which is why the rule doesn't finish. Maybe a check if the excel file exists at that path before trying to use go excel. I have found that go excel will just loop and loop trying to find the file because it tends to check the whole project space. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 7

dialunau
Advocate
Advocate

I just tried the excel part of the code, it does find the file, the sheet and retrieves all the data I need from the cells (printed them in msgboxes). The problem comes when I call the InputListBox.

 

So now I know the ILB without the excel part works fine, and the excel part works fine without the ILB, the problem is that Inventor freezes in my main form when I combine both parts.

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor
Accepted solution

While the excel sheet is opening and results are seen in the read sub routine I could get no return list back. It was just looping. Killing excel was the only options. 

I made one change to the size of the array and then your original rule worked. When I changed it back to 10 the array size outside bounds message popped up. Not sure why that didn't happen from the beginning

Dim oOpts(11) As String

AAcheson_1-1657230099752.png

 

 

This rule also works good. 

Sub Main()
	Dim oOpts As New ArrayList
	
	Call Readexisting(oOpts)
	
	Dim oSel As String = InputListBox("MYList", oOpts, oSel, "SELECT THE OPTION", ListName := "Opts")
	MessageBox.Show(oSel, "Title")
End Sub

Public Sub Readexisting(oOpts As ArrayList)
	Dim oXL As String = CStr(ThisDoc.Path) & "\MyXL.xls"
' Get values of the "A" Column in the spreadsheet to show them in the ListBox For i = 1 To 10 If CStr(GoExcel.CellValue(oXL, "Sheet1", "A" & i))= "" Then Exit For Else oOpts.add (CStr(GoExcel.CellValue(oXL, "Sheet1", "A" & i))) End If Next i End Sub 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 7

dialunau
Advocate
Advocate
Accepted solution

This works good but I found that my problem was on the form rule itself.

Turns out that when defining my form I defined it as a topmost form:

 

With oForm
	.FormBorderStyle = FormBorderStyle.FixedToolWindow
	.StartPosition = FormStartPosition.CenterScreen
	.Width = 250
	.Height = 300
	.TopMost = True
	.Font = oMyFont
	.Text = "MyForm"
	.Name = "Form1"
	.ShowInTaskbar = False
End With

 

So either turning the topmost to false or commenting that line solved my problem.

0 Likes