473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help me clean up this code

'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
Nov 20 '05 #1
13 1268
CMG
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

Nov 20 '05 #2

"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
Nov 20 '05 #3
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
Nov 20 '05 #4
"Bob Graham" <rv*****@pacbell.net> schrieb

Is there a syntax for Ctype(???) that works to convert as array of
integers to objects?


I think you need to create a new object array and a loop to fill it from the
integer array.

--
Armin

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

Nov 20 '05 #5
Bob,

This is probably obvious but why would you fill a combo box with 1000 items,
this does not seem to be user friendly nor efficient?

Why not make a text box where the user can enter a partial job number and
then make your search on the partial number entered. You could even do the
search while they are entering each individual number.

Dan
"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
Nov 20 '05 #6
Cor
Hi Bob,

Try this and be suprised

:-)

Cor

\\\
Dim a(1000) As Integer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim a(1000) As Integer
For i As Integer = 0 To a.Length - 1
a(i) = i
Next
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
Dim dc As New DataColumn("num")
dt.Columns.Add(dc)
For i As Integer = 0 To a.Length - 1
dt.Rows.Add(dt.NewRow)
dt.Rows(i)("num") = a(i)
Next
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = ("num")
End Sub
//
Nov 20 '05 #7
Solex,
This is probably obvious but why would you fill a combo box with 1000 items, this does not seem to be user friendly nor efficient?
I use a derived combobox that has AutoComplete well sorted out. It performs
quite well and allows users to cursor up or down a job, or to accept partly
typed entry as soon as AutoComplete is showing the job number they want.
Why not make a text box where the user can enter a partial job number and
then make your search on the partial number entered. You could even do the search while they are entering each individual number.

Dan
"Bob Graham" <rv*****@pacbell.net> wrote in message
news:go*****************@newssvr29.news.prodigy.co m...
'create object array
Dim jobnums(1000)

.......
Nov 20 '05 #8
hmmmm, interesting reply, I didn't know you could declare your "For" variable on the fly.

"Cor" <no*@non.com> wrote in message news:ux**************@TK2MSFTNGP10.phx.gbl...
Hi Bob,

Try this and be suprised

:-)

Cor

\\\
Dim a(1000) As Integer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim a(1000) As Integer
For i As Integer = 0 To a.Length - 1
a(i) = i
Next
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As New DataTable
Dim dc As New DataColumn("num")
dt.Columns.Add(dc)
For i As Integer = 0 To a.Length - 1
dt.Rows.Add(dt.NewRow)
dt.Rows(i)("num") = a(i)
Next
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = ("num")
End Sub


I thought of binding the Combo to a datatable, but I'm really only using the combo to pick a job for the purpose of filtering a datagrid by re-wording its select command.

This is now working quite well, with Option Strict enabled:

Dim jobnums(1000) As Object '<== I dont' like using Object Variables

Dim i As Integer
Dim cmdJobJums As New SqlCommand("Select JobName from Jobs where JobName " & _
"is not null and salesVol > '1/1/2003'", SqlConnection1)
SqlConnection1.Open()
drJobNums = cmdJobJums.ExecuteReader
Do While drJobNums.Read
jobnums(i) = drJobNums("JobName")
i += 1
If i Mod 1000 = 0 Then ReDim Preserve jobnums(i + 1000)
Loop
ReDim Preserve jobnums(i - 1)
drJobNums.Close()
SqlConnection1.Close()
cbJob.Items.AddRange(jobnums) '<== this is virtually instantaneous

I just feel sloppy using object variables, although it seems that that's what the combo wants passed to its AddRange method anyway.

I also have to look at my redim statement when the count reaches a thousand, I think I'm creating an "off by one" scenario.

Believe it or not, on a fast 2.4 Ghz p4, adding 1600 numbers to a combobox from a datareader took 7 seconds! With this method it's less than 1 second.

Bob
Nov 20 '05 #9
Cor
Hi Bob,

I changed it here in this message direct in the datatable I did not test it.
Dim dt As New DataTable
Dim dc As New DataColumn("JobName")
Dim cmdJobJums As New SqlCommand("Select JobName from Jobs where JobName " & _
"is not null and salesVol > '1/1/2003'", SqlConnection1)
SqlConnection1.Open()
drJobNums = cmdJobJums.ExecuteReader
Do While drJobNums.Read
dim dr as datarow = dt.newrow
dr("Jobname"") = drJobNums("JobName")
dt.Rows.Add(dr)
Loop
drJobNums.Close()
SqlConnection1.Close()
Me.ComboBox1.DataSource = dt
Me.ComboBox1.DisplayMember = ("JobName")

I think this goes faster than that it was.
Cor
Nov 20 '05 #10
* "Bob Graham" <rv*****@pacbell.net> scripsit:
[...]

Your message is "unreadable" for me. Please do not post in rich text format.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #11
* "CMG" <vb****@divx-warez.nl> scripsit:
Seems easy, but wouldn't a plain
Dim jobnums(1000) As Integer
Dim blah As Object = CObj(jobnums(1000))
work?


This will only convert the element with index 1000...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #12
"Bob Graham" <rv*****@pacbell.net> wrote in message news:<xW****************@newssvr29.news.prodigy.co m>...
hmmmm, interesting reply, I didn't know you could declare your "For"
variable on the fly.


Bob,

I hope someone else will correct me if this is wrong, but I believe
that only works in Visual Studio 2003.

Charlie
Nov 20 '05 #13
Sorry about that, I wasn't sure if many used newsgroups in plain text only.

I find that if I paste code into a plain text message, it displays with
double line spacing, what am I doing wrong?

Bob
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:u0**************@tk2msftngp13.phx.gbl...
* "Bob Graham" <rv*****@pacbell.net> scripsit:
[...]

Your message is "unreadable" for me. Please do not post in rich text format.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
15
by: lallous | last post by:
Hello, I have a function like: void fnc() { char *mem1, *mem2, *mem3, *mem4; // lots of code... // mem1, 2, 3, 4 got allocated // lots of code and condition checks if (condition_failed)
17
by: Christopher Benson-Manica | last post by:
Yesterday I changed some code to use std::vectors and std::strings instead of character arrays. My boss asked me today why I did it, and I said that the code looks cleaner this way. He countered...
1
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h...
4
by: Mike | last post by:
Please help this is driving me nuts. I have 2 forms, 1 user class and I am trying to implement a singleton class. Form 1 should create a user object and populate some properties in user. Form2...
16
by: expertware | last post by:
Dear friends, My name is Pamela, I do not know anything about javascript, but I would like to ask if it offers a solution to this problem of mine. I have an image on a web page within a css...
1
by: audiopro | last post by:
I am having some trouble here, and my brain is running on empty. I am not an expert ASP coder, so forgive me for what is probably sloppy code, and not the best... At any rate, I have created the...
1
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard...
1
by: theflyingminstrel | last post by:
Hi, I’m having some trouble with a Javascript code, and I was wondering if anyone can help: I am trying to build a price estimator that has multiple fields. I would like the first two fields to...
4
by: rsaharia | last post by:
Hello All, I need help with this particular .pl file I picked up from http://www.veritools-usa.com/xnf2vhdl.htm What it's supposed to do is really convert an xnf file to a vhdl file. I need it for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.