帮我清理这段代码 [英] Help me clean up this code
问题描述
''创建对象数组
Dim jobnums(1000)
省略:从sql server检索作业号(整数)的代码combobox
我有一个组合框(cbJob),我想将这些值放入其中。如果我从SqlDataReader中读取它们,那么它将永久地花费
,大约需要7秒才能完成。但是如果我把它们读成一个数组,它就不会花费可测量的时间。
然后我使用组合框的..AddRange方法将数组项同时添加到组合框中:
cbJob.Items.AddRange(jobnums)
这也没有花费可测量的时间,而且工作正常。
我的问题是,我应该如何改变这一点,以便我可以重新选择Option Strict?
选项严格要求在声明数组时声明类型:
''所以:
Dim jobnums(1000)as Integer
然后你不能将数组分配给.Addrange方法,因为组合框需要对象,而不是整数。
是否有语法Ctype(???)用于将整数数组转换为对象?
谢谢,Bob Graham
看起来很简单,但不会很简单
昏暗的工作(1000)作为整数
Dim blah As Object = CObj(jobnums(1000))
工作?-----原始消息-----
''创建对象数组
昏暗的工作数(1000)
省略:从sql server检索作业号(整数)
的代码放入组合框我有一个组合框(cbJob),我想将这些
值放入。如果我从SqlDataReader中读取它们,那么
需要一个永恒,大约需要7秒才能完成。但如果我将
读入数组,则无需花费可测量的时间。然后我使用组合框的..AddRange方法将数组项目一次性添加到组合框
:
cbJob.Items.AddRange(jobnums)
这也需要没有可测量的时间,并且工作正常。
我的问题是,我应该如何改变这一点,以便我可以将
Option Strict重新打开?当
声明数组时,Option strict需要一个类型声明:''所以:
Dim jobnums(1000)作为整数
然后你不能将数组分配给.Addrange
方法,因为组合框需要对象而不是整数。
Ctype(???)的语法是否可以将
转换为整数数组到对象?>谢谢,Bob Graham
" CMG" < VB **** @ divx-warez.nl>在留言中写道
news:07 **************************** @ phx.gbl ... < blockquote class =post_quotes>看起来很简单,但不会很简单
昏暗的工作(1000)作为整数
Dim blah As Object = CObj(jobnums(1000))
实际上,
Dim jobnums(1000)As Object
cbJob.Items.Addrange(jobnums)
工作正常,我觉得使用对象变量直到你有
到。
Bob Graham
我认为这基本上就是你要找的:
Dim intO()As Object = New Object(){1,2,3,4 ,5,6,7}
Debug.Assert(不是intO什么都没有)
ComboBox1.Items.AddRange(intO)
" Bob Graham" < RV ***** @ pacbell.net>在消息新闻中写道:去***************** @ newssvr29.news.prodigy.co m ...
''创建对象数组
昏暗的工作区(1000)
省略:从sql server检索作业号(整数)以放入组合框的代码
我有一个组合框(cbJob),我想把这些值放入。如果我从SqlDataReader中读取它们,那么它将永久地花费
,大约需要7秒才能完成。但是如果我把它们读成一个数组,它就不会花费可测量的时间。
然后我使用组合框的..AddRange方法将数组项同时添加到组合框中:
cbJob.Items.AddRange(jobnums)
这也没有花费可测量的时间,而且工作正常。
我的问题是,我应该如何改变这一点,以便我可以重新选择Option Strict?
选项严格要求在声明数组时声明类型:
''所以:
Dim jobnums(1000)as Integer
然后你不能将数组分配给.Addrange方法,因为组合框需要对象,而不是整数。
是否有语法Ctype(???)是否可以作为整数转换为对象?
谢谢,Bob Graham
''create object array
Dim jobnums(1000)
Omitted: code that retrieves job numbers (integers) from sql server to put in a combobox
I have a combobox (cbJob) that I want to put these values into. If I read them in from a SqlDataReader it takes
an eternity, about 7 seconds to accomplish. But if I read them into an array, it takes no measurable time.
Then I add the array items to the combobox all at once with the ..AddRange method of the combobox thus:
cbJob.Items.AddRange(jobnums)
This also takes no measurable time, and works fine.
My question is, how should I alter this so I can turn Option Strict back on?
Option strict requires a type declaration when declaring the array:
''So:
Dim jobnums(1000) as Integer
And then you can''t assign the array to the .Addrange method, because the combobox wants objects, not integers.
Is there a syntax for Ctype(???) that works to convert as array of integers to objects?
Thanks, Bob Graham
Seems easy, but wouldn''t a plain
Dim jobnums(1000) As Integer
Dim blah As Object = CObj(jobnums(1000))
work?-----Original Message-----
''create object array
Dim jobnums(1000)
Omitted: code that retrieves job numbers (integers) from sql server to put in a combobox I have a combobox (cbJob) that I want to put these values into. If I read them in from a SqlDataReader it
takes an eternity, about 7 seconds to accomplish. But if I read them into an array, it takes no measurable time. Then I add the array items to the combobox all at once with the ..AddRange method of the combobox thus:
cbJob.Items.AddRange(jobnums)
This also takes no measurable time, and works fine.
My question is, how should I alter this so I can turn Option Strict back on? Option strict requires a type declaration when declaring the array: ''So:
Dim jobnums(1000) as Integer
And then you can''t assign the array to the .Addrange method, because the combobox wants objects, not integers.
Is there a syntax for Ctype(???) that works to convert as array of integers to objects?
Thanks, Bob Graham
"CMG" <vb****@divx-warez.nl> wrote in message
news:07****************************@phx.gbl...Seems easy, but wouldn''t a plain
Dim jobnums(1000) As Integer
Dim blah As Object = CObj(jobnums(1000))
Actually,
Dim jobnums(1000) As Object
cbJob.Items.Addrange(jobnums)
Works fine, just seems sloppy to me to use object variables until you have
to.
Bob Graham
I think this is essentially what you are looking for:
Dim intO() As Object = New Object() {1, 2, 3, 4, 5, 6, 7}
Debug.Assert(Not intO Is Nothing)
ComboBox1.Items.AddRange(intO)
"Bob Graham" <rv*****@pacbell.net> wrote in message news:go*****************@newssvr29.news.prodigy.co m...
''create object array
Dim jobnums(1000)
Omitted: code that retrieves job numbers (integers) from sql server to put in a combobox
I have a combobox (cbJob) that I want to put these values into. If I read them in from a SqlDataReader it takes
an eternity, about 7 seconds to accomplish. But if I read them into an array, it takes no measurable time.
Then I add the array items to the combobox all at once with the ..AddRange method of the combobox thus:
cbJob.Items.AddRange(jobnums)
This also takes no measurable time, and works fine.
My question is, how should I alter this so I can turn Option Strict back on?
Option strict requires a type declaration when declaring the array:
''So:
Dim jobnums(1000) as Integer
And then you can''t assign the array to the .Addrange method, because the combobox wants objects, not integers.
Is there a syntax for Ctype(???) that works to convert as array of integers to objects?
Thanks, Bob Graham
这篇关于帮我清理这段代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!