2017-01-30 13 views
2

나는 VB 새로운 그리고 난 현재 VB6 애플 리케이션은 내가 그물에 작성하지 않은 마이그레이션 그리고 난이 변수에 액세스하는 방법은 무엇입니까?

If TypeOf Application.OpenForms.Item(i) Is frmAddChangeDelete Then 
      'UPGRADE_ISSUE: Control ctrlAddChangeDelete1 could not be resolved because it was within the generic namespace Form. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"' 

      If **Application.OpenForms.Item(i).ctrlAddChangeDelete1.ParentFormNumber = intFormNumber** Then 

       If Application.OpenForms.Item(i).Text = "Add Proofed Expense Items" Then 
        boolAddProofed = True 
        Exit For 

ctrlAddChangeDelete1는 기발한에서 친구 클래스 ctrlAddChangeDelete를 호출이 오류와 사투를 벌인거야 이

"'ctrlAddChangeDelete1' is not a member of 'System.Windows.Forms.Form'."

어떤 도움에 감사드립니다 말하는 왜 별도의 VB 파일, 그래서 잘 모르겠어요, 감사합니다!

답변

2

Application.OpenForms은 강력한 형식이 아닌 모음입니다.
여기에서 요소를 참조하면 일반 형식이 반환됩니다. 일반적인 형태로
ctrlAddChangeDelete1라는 이름의 통제가없는

당신은 클래스의 이름 frmAddChangeDelete 파생 된 형태를 가지고 있고,이 클래스는 다음 당신은 OpenForms에 저장된 참조를 캐스팅 할 필요가 ctrlAddChangeDelete1라는 이름의 컨트롤이있는 경우 컬렉션을 특정 폼 클래스로 복사 한 다음 해당 컨트롤을 참조하려고합니다.

또한 외부 코드에서 해당 컨트롤에 액세스하려면 Modifiers 속성을 기본 Internal 대신 Public으로 설정해야합니다. 그렇지 않으면 클래스 외부의 코드에서 컨트롤에 액세스 할 수 없습니다.

이 양식은 당신이

Dim delForm = Application.OpenForms. 
         OfType(Of frmAddChangeDelete) 
         FirstOrDefault() 
If delForm Is Nothing Then 
    ' No form of type frmAddChangeDelete is present in the collection 
    ' write here your message and exit ? 
Else 
    ' Now you can use delForm without searching again in the collection 
    ...... 

코드는 위의 IEnumerable.OfType 확장자를 사용하며, 이것은 Imports System.Linq을 필요로 쓸 수 있습니다 정확하게 검색 할 수 있습니다. 올바른 클래스

' Still you need a for loop up ^^^^ before these lines 
Dim delForm = TryCast(Application.OpenForms(i), frmAddChangeDelete) 
if delForm Is Nothing then 
    .... 
else 
    .... 
+0

에 대한 참조를 얻기 위해 항상 TryCast 연산자를 사용할 수 있습니다 다음이를 사용하지 않을 경우
내가 지금 훨씬 더 오류를 알아 보았, 감사합니다! 명백히 OfType이 OpenForms 내에 존재하지 않기 때문에 지금 내 네임 스페이스/참조에 문제가 있습니다. – Sam

+0

[IEnumerable.OfType] (https://msdn.microsoft.com/en-us/library) /bb360913(v=vs.110).aspx) 확장에는 System.Linq 네임 스페이스가 필요합니다 (이미 참조가 있어야하지만 여전히 System.Linq가 필요합니다) – Steve