VB6与VB .NET [英] VB6 vs VB .NET

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

问题描述

在过去的好日子......我过去常常将我的大部分代码放在不同的模块中,为了保持整洁,那么在模块中写入是没有问题的:


Form1.textbox1.text ="一些文字


或来自表格


Form2.textbox1.text = me.textbox2.text


现在,在vb.net中我收到错误提示引用非共享成员

需要一个对象引用。好的,所以我读到我需要


Dim FormSomething aAS新Form1


然后我可以


FormSomething.TextBox1.Text ="有些文字


但是,FormSomething与Form1的格式不同,我看不到文字.....


有没有办法绕过它或者我被卡住了?


表格上的程序相同,我想从一个表格中运行它们

不同的表格或模块,我可以这样做,但如果我使用表格中的值,那么我会得到错误的结果。


如果我在Form1上有这样的代码


sub get_Customer_Info()

....

qeryString = SELECT * FROM Cust WHERE KID =''" Me.txtKID.text"''"

...

end sub


然后我尝试运行这个来自Form2,带有以下代码:

将newForm作为新表单1

Form1.get_Cstomer_Info


get_Cstomer_Info procdure将运行,但txtKID.text的值将是

您在设计时设置的文本。


请在这里帮助我,我很沮丧VS.NET新手

Ronny

In the "good old days"... I used to put most of my code in different
modules, to keep it tidy, then it was no problem writing in a module like:

Form1.textbox1.text = "Some text"

or from a form

Form2.textbox1.text = me.textbox2.text

Now, in vb.net iI get an error saying "Reference to a non-shared member
requires an object reference". OK, so I read that I need to

Dim FormSomething aAS New Form1

then I can

FormSomething.TextBox1.Text = "Some text"

But, FormSomething is not the same form as Form1, I can''t see the text.....

Is there a way around it or am I stuck?

Same thing about procedures on a form and I want to run them from a
different form or module, this I can, but if I use values from the form in
te proceure I get the wrong result.

If I on Form1 has code like this

sub get_Customer_Info ()
....
qeryString="SELECT * FROM Cust WHERE KID=''" Me.txtKID.text "''"
...
end sub

And then I try to run this from Form2 with this code:
Dim newForm As New Form1
Form1.get_Cstomer_Info

The get_Cstomer_Info procdure wil run, but the value of txtKID.text will be
the text you set at design time.

Please help me here, I''m a frustrated VS.NET newbie
Ronny

推荐答案



" R" < r@u.com>在消息新闻中写道:Tl **************** @ news4.e.nsc.no ...

"R" <r@u.com> wrote in message news:Tl****************@news4.e.nsc.no...

FormSomething.TextBox1.Text =有些文字

但是,FormSomething与Form1的格式不同,我看不到文字.....

有没有办法在它附近还是我被困?

FormSomething.TextBox1.Text = "Some text"

But, FormSomething is not the same form as Form1, I can''t see the text.....

Is there a way around it or am I stuck?




我认为Form1是你的创业形式?也许使用子Main作为你的创业公司。问题是

您看到的表单与FormSomething不同。它们都是Form1类型,

但是不同的实例。如果您调用FormSomething.Show,那么您将看到FormSomething

将弹出,文本将是正确的。



I assume that Form1 is your startup form? Perhaps use a sub Main as your startup. The problem is
that The form you see is a different instance than FormSomething. They are both of type Form1,
but different instances. If you call the FormSomething.Show then you will see that FormSomething
will pop up, and the text will be correct.


" R" ; < r@u.com> schrieb
"R" <r@u.com> schrieb
有没有办法绕过它或者我被卡住了?
Is there a way around it or am I stuck?




如果你想访问一个对象,你需要一个参考。如果你没有

参考,你必须提供它。这在VB6中是相同的。


.NET Framework包含数百(或数千)个类。

没有理由从System派生类.Windows.Forms.Form有一个

全局,自动创建,自动实例化和隐形变量

与表格同名,而其他数百不要有这样一个

变量。


如果你想拥有与VB6相同的行为,你可以写一个模块:


私人m_Form1作为Form1


公共财产Form1()作为Form1

获取

如果m_Form1没什么然后

m_Form1 =新Form1

结束如果

返回m_Form1

结束获取

设置(ByVal值为Form1)

m_Form1 =价值

结束集

结束财产

相反,我仍然会将引用传递给需要它的对象。


-

Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html



If you want to access an object, you need a reference. If you don''t have a
reference you have to make it available. This was the same in VB6.

The .NET Framework contains several hundreds (or thousands) of classes.
There is no reason why classes derived from System.Windows.Forms.Form have a
global, automatically created, automatic instancing and invisible variable
with the same name of the Form, whereas the other hundreds don''t have such a
variable.

If you want to have the same behavior as in VB6, you can write in a Module:

Private m_Form1 As Form1

Public Property Form1() As Form1
Get
If m_Form1 Is Nothing Then
m_Form1 = New Form1
End If
Return m_Form1
End Get
Set(ByVal Value As Form1)
m_Form1 = Value
End Set
End Property
Instead, I still would pass the reference to the object that needs it.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


查看以下文章:
http://tinyurl.com/el1


在Visual Basic .NET中使用多个表单:升级到.NET


描述了如何使用以前的版本更改多个表单的工作原理

的Microsoft Visual Basic并说明了几种关键技术,包括显示第二种形式的
,更改外观另一种形式,并使用

a形式作为对话。


-

Greetz


Jan Tielens

________________________________

阅读我的博客: http://weblogs.asp.net/jan

" R" < r@u.com>在消息新闻中写道:Tl **************** @ news4.e.nsc.no ...
Check out following article:
http://tinyurl.com/el1

Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET

Describes how working with multiple forms has changed from previous editions
of Microsoft Visual Basic and illustrates several key techniques, including
displaying a second form, changing the appearance of another form, and using
a form as a dialog.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"R" <r@u.com> wrote in message news:Tl****************@news4.e.nsc.no...
在过去的好时光中。 ..我以前将大部分代码放在不同的模块中,以保持整洁,然后在类似的模块中编写是没有问题的:

Form1.textbox1.text ="一些文字

或来自一个表格

Form2.textbox1.text = me.textbox2.text
现在,在vb.net中,我得到了错误说引用非共享成员
需要对象引用。好的,所以我读到我需要

Dim FormSomething aAS新Form1

然后我可以

FormSomething.TextBox1.Text =" Some文字

但是,FormSomething与Form1的格式不同,我看不到
文本.....
有没有办法绕过它或者是我卡住了吗?

关于表单上的程序也是如此,我想从不同的表单或模块中运行它们,我可以这样做,但是如果我在
如果我在Form1上有这样的代码

sub get_Customer_Info()
....
qeryString =" SELECT * FROM Cust WHERE KID =''" Me.txtKID.text"''"
...
end sub

然后我尝试使用此代码从Form2运行它:
Dim newForm作为新Form1
Form1.get_Cstomer_Info


get_Cstomer_Info procdure将运行,但txtKID.text的值将
为您在设计时设置的文本。

请帮帮我这里,我很沮丧VS.NET新手
Ronny

In the "good old days"... I used to put most of my code in different
modules, to keep it tidy, then it was no problem writing in a module like:

Form1.textbox1.text = "Some text"

or from a form

Form2.textbox1.text = me.textbox2.text

Now, in vb.net iI get an error saying "Reference to a non-shared member
requires an object reference". OK, so I read that I need to

Dim FormSomething aAS New Form1

then I can

FormSomething.TextBox1.Text = "Some text"

But, FormSomething is not the same form as Form1, I can''t see the text.....
Is there a way around it or am I stuck?

Same thing about procedures on a form and I want to run them from a
different form or module, this I can, but if I use values from the form in
te proceure I get the wrong result.

If I on Form1 has code like this

sub get_Customer_Info ()
....
qeryString="SELECT * FROM Cust WHERE KID=''" Me.txtKID.text "''"
...
end sub

And then I try to run this from Form2 with this code:
Dim newForm As New Form1
Form1.get_Cstomer_Info

The get_Cstomer_Info procdure wil run, but the value of txtKID.text will be the text you set at design time.

Please help me here, I''m a frustrated VS.NET newbie
Ronny



这篇关于VB6与VB .NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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