I have a class called class1, in that class i wan;t to write something in a textbox in form1, but it won’t let me access Form1.TextBox1.text, another problem is that it won’t give me the save dialog in excel, but thats another problem.
How can i acces Form1 controls?
Form1 code
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call ThisDrawing.GetFilepath(True)
If Me.TextBox1.Text = "" Or Me.TextBox1.Text = "False" Then MsgBox("Er is geen geldige filenaam opgegeven")
End Sub
Class1 code
Public Shared Sub GetFilepath(ByVal hide As Boolean)
Dim Xl As New Excel.Application
Dim Filepath As String
Call ExcelKoppelen("Z:\test\test.xls")
Filepath = Xl.GetSaveAsFilename("", "Excel file", "*.xls")
Form1.TextBox1.text = Filepath
End Sub
Excelkoppelen code
Shared Sub ExcelKoppelen(ByVal Bestand As String)
Dim Xl As Excel.Application
Dim Filepath As String
Dim Workbook As Excel.Workbook
Dim Worksheet1 As Worksheet
Dim Worksheet2 As Worksheet
On Error Resume Next
Xl = GetObject(, "Excel.application")
If Err.Number Then
Information.Err.Clear()
Xl = CreateObject("Excel.application")
End If
Xl.Visible = True
Xl.ScreenUpdating = True
Workbook = Xl.Workbooks.Open(Bestand)
If Err.Number Then
Workbook = Xl.Workbooks.Open("Z:\test\test.xls")
Information.Err.Clear()
Workbook.SaveAs(Bestand)
End If
If Err.Number Then Exit Sub
On Error GoTo 0
Worksheet1 = Workbook.Worksheets.Item(1)
Worksheet2 = Workbook.Worksheets.Item(2)
Xl.Visible = False
End Sub
You can not access the controls in Form1 directly like that, create an object for Form1 as follows and get the controls by using the object.