简体   繁体   English

视觉基本形式的标识符

[英]identifiers in visual basic form

I have a form, user logs in and another form is generated. 我有一个表单,用户登录并生成另一个表单。

User submits a query. 用户提交查询。 My problem is that I cannot keep a record of who is making the query. 我的问题是我无法记录谁在进行查询。

The user has a uid and usernamae but once the new form is generated where the user submits the query both these identifiers are gone. 用户具有uid和usernamae,但是一旦生成新表单,用户提交查询,这两个标识符都将消失。

Is there a way in which I can overcome this? 有没有办法可以克服这个问题? Thanks 谢谢

If you're storing your UIDs only in the initial form, you'll need to pass in these values to the new form. 如果您仅以初始形式存储UID,则需要将这些值传递给新表单。

In essence, you could adjust your fields scopes and store your value in a place accessible by both forms, pass them into a constructor (and store accordingly), or provide an accessor in your new form to pass through the values you need. 实质上,您可以调整字段范围并将值存储在两个表单都可访问的位置,将它们传递给构造函数(并相应地存储),或者在新表单中提供访问器以传递所需的值。

To answer your question on the constructor: 要回答关于构造函数的问题:

Your code currently probably looks like the following: 您的代码目前可能如下所示:

Dim form2 as New Form2()
form2.Show()

You'll need to modify the constructor of the second form such as: 您需要修改第二种形式的构造函数,例如:

Public Sub New() ...

...should become... ......应该成为......

Public Sub New(ByVal userId As String, ByVal userName As String) ...

And then pass in your values from the first form (where userId and userName are fields storing form1's values): 然后从第一个表单传递您的值(其中userId和userName是存储form1值的字段):

Dim form2 as New Form2(userId, userName)
form2.Show()

Then you could store them in your second form's global scope. 然后,您可以将它们存储在第二种形式的全局范围内。

This is how I brought across the value into a new form. 这就是我将价值带入新形式的方式。 Seems like an easy fix, didnt realise it was so straightforward! 看起来像一个简单的修复,没有意识到它是如此简单!

Dim val As String = CStr(Form1.ComboBox1.SelectedValue) Dim val As String = CStr(Form1.ComboBox1.SelectedValue)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM