在classLibrary项目中调用另一个表单上的sub

时间:2017-11-24 07:07:29

标签: vb.net

我有一个多项目的解决方案,我有一个名为//database connation <?php $conn = new mysqli("localhost", "root", "","database_name"); ?> <!DOCTYPE html> <html>enter code here <head> <title>View Student Details</title> <h1 align="center"> Student Details </h1> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="bootstrap/bootstrap.min.js"></script> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"> </head> <body> <div class="row"> <div class="col-sm-2"></div> <div class="col-sm-8"> <form> <table class="table table-striped"> <tr> <th>Sr.No.</th> <th>Student ID</th> <th>Student Name</th> <th>Class</th> <th>Gender</th> <th>Birth of Date</th> <th>Contact No.</th> <th>Action</th> </tr> <?php $count=0; if(isset($_GET['page_count'])) { $count=1; $page_count=$_GET['page_count']-1; $count=$page_count*10; } $q="SELECT * from student_detail LIMIT $count,10"; $result=$conn->query($q); $j=0; while($data=$result->fetch_array()) { $j=$j+1; ?> <tr> <td><?php echo $j ?></td> <td><?php echo $data['std_id'] ?></td> <td><?php echo $data['std_name'] ?></td> <td><?php echo $data['std_class'] ?></td> <td><?php echo $data['gender'] ?></td> <td><?php echo $data['bod'] ?></td> <td><?php echo $data['contact'] ?></td> <td> <div class="row"> <div class="col-sm-12"> <a href="delete_master.php?std_id=<?php echo $data['std_id']; ?>" class="btn btn-danger">Delete</a> <a href="update.php?std_id=<?php echo $data['std_id']; ?>" class="btn btn-danger">Update</a> </div> </div> </td> </tr> <?php } ?> </table> <ul class="pagination"> <?php $q="SELECT count(std_id) from student_detail"; $result=$conn->query($q); $data=$result->fetch_array(); $total=$data[0]; $total_page=ceil($total/10); if($total_page>1) { for($i=1;$i<=$total_page;$i++) { ?> <li class="active"><a href="view.php?page_count=<?php echo $i;?>" name="page_count" id="page_count"><?php echo $i; ?></a></li> <?php } } ?> </ul> </form> <div class="col-sm-2"></div> </div> </div> </body> </html> 的主表单,保存数据后在master_ChartofAccount,我想调用一个名为{{{1}的coa_Create 1}}刷新Sub上的网格,这是我的代码:

showCoa

以及coa_Create上的Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click Dim frm As New coa_Create frm.ShowDialog(Me) End Sub 代码:

cmdSave

为什么会出现错误信息:

  

对非共享成员的引用需要对象引用

on coa_Create

如何解决这个问题? 还有其他方法可以从另一个Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click If Not allowSave() Then Exit Sub Dim str As String txtKode.Tag = IIf(IsNothing(txtKode.Tag), "", txtKode.Tag) If txtKode.Tag.ToString = "" Then str = "insert into t_chart_of_account (coa_code, coa_name, p_code, is_parent, db_cr, bs_is) " _ & "values ('" & objComp.clearSingleQuote(txtKode.Text) & "', '" & objComp.clearSingleQuote(txtNama.Text) & "', " _ & "'" & objComp.clearSingleQuote(txtParentCode.Text) & "', " & IIf(chkParent.Checked = True, 1, 0) & ", " _ & "'" & IIf(optDb.Checked = True, "DR", "CR") & "', '" & IIf(optBS.Checked = True, "BS", "IS") & "')" Else str = "update t_chart_of_account set coa_code = '" & txtKode.Text & "', " _ & "coa_name = '" & objComp.clearSingleQuote(txtNama.Text) & "', p_code = '" & txtParentCode.Text & "', " _ & "is_parent = " & IIf(chkParent.Checked = True, 1, 0) & ", db_cr = '" & IIf(optDb.Checked = True, "DR", "CR") & "', " _ & "bs_is = '" & IIf(optBS.Checked = True, "BS", "IS") & "' WHERE id = " & txtKode.Tag.ToString End If objComp.setExecute(str, False) master_ChartofAccount.showCoa() 'error on this line : Reference to a non-shared member requires an object reference objComp.msgShow(Me, "Data berhasil di simpan.", "Simpan Berhasil", MessageBoxButtons.OK, MessageBoxIcon.Information) cmdClose_Click(sender, e) End Sub 调用master_ChartofAccount.showCoa()吗?

我试过了:

Sub

Form上的网格无法刷新。 谢谢

1 个答案:

答案 0 :(得分:0)

在coa_Create中,声明master_ChartofAccount表单类型的属性。

Public Property Master_ChartofAccount As <class name for your master_chartofaccount form>

然后在cmdAdd_Click

Private Sub cmdAdd_Click(sender As Object, e As EventArgs) Handles cmdAdd.Click
    Dim frm As New coa_Create
    frm.Master_ChartofAccount = Me
    frm.ShowDialog(Me)
End Sub

在你的cmdSave_Click

Me.MasterChartofAccount.showCoa()

OR

在cmdSave_Click中,只需将父类型转换为类型为mast_chartofaccount

CType(Me.Parent, <class name of master chart of account>).showCoa()