在VB.net中传递结构 [英] Passing Structures in VB.net

查看:94
本文介绍了在VB.net中传递结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iam already using a structure with 25,000 records from a database, and when populating another DB I need to display info for a record on another form. I have to have the 25,000 records in memory and simply need to display the info from one record from that database on a second form for use in populating another user db.

I am lost on how I will pass the 'ith' record from my structure to the second page. The second page simply will display the information for the person to 'mine' data for the other db.

I have the program working displaying the info in a textbox on the first form, but using a second form on the other screen will be a far more elegent approach and facilitate display formating, etc.

I appreciate your responses
Thanks
Jack .


Structure User
    Dim First As String
    Dim Middle As String
    Dim Last As String
    Dim Addr1 As String
    Dim Addr2 As String
    Dim City As String
    Dim State As String
End Structure


昏暗的My_Users(25000)作为用户


Dim My_Users(25000) As User

Private Sub System_User_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles System_User.Click
    'Dim ThirdForm As New Sys_Screen
    'ThirdForm.Show()
    Dim form As New Sys_Screen()
    Dim screen As Screen
    ' I want to display a form on screen 1
    screen = screen.AllScreens(1)
    ' Set the StartPosition to Manual otherwise the system will assign an automatic start
    form.StartPosition = FormStartPosition.Manual
    ' *** the following doesn't work and is commented out ***
    form.Location = screen.Bounds.Location '+ New Point(100, 100)
    form.ShowDialog(Me)
End Sub



从我的主表单,我想将My_Users(record)发送到其他表单.我将一次从结构中发送记录,以便在第二个表单上显示.

我发现"了如何在第二个显示器上显示第二个表单(这类作品).因此,现在需要查找如何将信息转换为其他形式.

第二个问题是第二个表单仅在原始位置显示.
谢谢
杰克

响应形式OP [/EDIT]



From my main form I want to send My_Users(record) to the other form. I will be sending just on record from the structure at a time for display on the second form.

I ''found'' how to display the second form on the second display (kind of works). So now need to find how to get information to the other form.

The second problem is the second form is only displaying in the home position.
Thanks
Jack

Response form OP[/EDIT]

推荐答案

最简单的方法是创建一个接受对象作为参数的重载构造函数.
您为什么不这样做:

The easiest way is to create an overloaded constructor that accepts the object as a parameter.

Why don''t you do it this way:

Public Class User
    ' correction to your code - unless the variables are public, you won't 
    ' be able to access them outside the class
    Public Dim First As String
    Public Dim Middle As String
    Public Dim Last As String
    Public Dim Addr1 As String
    Public Dim Addr2 As String
    Public Dim City As String
    Public Dim State As String
End Class

' added benefit of using a list - you can have as many or as few 
' users in the collection without committing memory for a static 
' number of items.
Public Class UserCollection _
    Inherits List(Of User)
End Class



现在,您可以执行以下操作:



Now, you can do this:

Private Dim m_users As New UserCollection()
' add your users in a method in form1


之后,为Form2创建一个新的构造函数


After that, you create a new constructor for your Form2

public Sub New(ByRef users As UserCollection)
    ' do something with the users collection
End Sub


我想要简单的内容:

模块Module1
两个系统的用户结构均为25,000
公共Legacy_User(25000)作为用户
Public User_Count为整数
公开记录为整数
终端模块


根据需要,使信息跨表格可用.由于表单读取多个数据库,因此很有效,这使解决方案变得如此简单.

谢谢
I wanted something simple therefore:

Module Module1
User Structures 25,000 for Both Systems
Public Legacy_User(25000) As User
Public User_Count As Integer
Public Record As Integer
End Module


Works making the information available across forms as I need. Effective since the forms are reading multiple dbs amazing how simple the solution is.

Thanks


这篇关于在VB.net中传递结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆