473,399 Members | 4,254 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,399 software developers and data experts.

optimize code

Hi,

I have a ComboBox which is filled with 66 items on form_load event:

Private Sub Form_Load()
Combo1.AddItem "Tekvin" 'item number: 1
Combo1.AddItem "Cikis" 'item number: 2
Combo1.AddItem "Levililer" '....
Combo1.AddItem "Sayilar"
...
Combo1.AddItem "Vahiy" 'item number:66
End sub

When user selects one of them, beside this control in 4 diff. Label
(InfoLbl) controls the app
shows the description of the item selected:

Private Sub Combo1_Click()
If Combo1.Text = "Tekvin" Then
InfoLbl1.Caption = "Musa"
InfoLbl2.Caption = "Col"
InfoLbl3.Caption = "M.O. 1513"
InfoLbl4.Caption = "Yaradilistan M.O. 1657'ye kadar"
End If
...
...
'this means for 66 items = 66 conditions..
End sub

As I'm a beginner, I do not know whether this code is good. Is there another
way of doing the same thing, more advanced, or much faster? (For ex.: Select
Case, is it better?) If yes what is the optimized way?

Thanks in advance!
--
Cengiz Ulku
ce*****@bluewin.ch

Jul 17 '05 #1
8 2709
Yes, there is an easier way

- actually I would be hard pressed to find a more difficult way

Put all the data in a file
- the solution will then become obvious

On Thu, 28 Aug 2003 17:32:53 +0200, "Cengiz Ulku" <ce*****@bluewin.ch>
wrote:
Hi,

I have a ComboBox which is filled with 66 items on form_load event:

Private Sub Form_Load()
Combo1.AddItem "Tekvin" 'item number: 1
Combo1.AddItem "Cikis" 'item number: 2
Combo1.AddItem "Levililer" '....
Combo1.AddItem "Sayilar"
...
Combo1.AddItem "Vahiy" 'item number:66
End sub

When user selects one of them, beside this control in 4 diff. Label
(InfoLbl) controls the app
shows the description of the item selected:

Private Sub Combo1_Click()
If Combo1.Text = "Tekvin" Then
InfoLbl1.Caption = "Musa"
InfoLbl2.Caption = "Col"
InfoLbl3.Caption = "M.O. 1513"
InfoLbl4.Caption = "Yaradilistan M.O. 1657'ye kadar"
End If
...
...
'this means for 66 items = 66 conditions..
End sub

As I'm a beginner, I do not know whether this code is good. Is there another
way of doing the same thing, more advanced, or much faster? (For ex.: Select
Case, is it better?) If yes what is the optimized way?

Thanks in advance!
--
Cengiz Ulku
ce*****@bluewin.ch


Jul 17 '05 #2
"J French" <er*****@nowhere.com> wrote in message
news:3f***************@news.btclick.com...
Yes, there is an easier way

- actually I would be hard pressed to find a more difficult way

Put all the data in a file
- the solution will then become obvious

On Thu, 28 Aug 2003 17:32:53 +0200, "Cengiz Ulku" <ce*****@bluewin.ch>
wrote:
Hi,

I have a ComboBox which is filled with 66 items on form_load event: <snipped />


I foresee another question from Cengiz, so i will elaborate a little
bit on our close-mouthed friend Jerry's idea:

If you put your 66 items into a textfile (Create it with notepad),
one item on each line, with a separator character that isn't used
elsewhere in your text between each field (Here I've used the "Bar" "|"):

Tekvin|Musa|Col|M.O. 1513|Yaradilistan M.O. 1657'ye kadar
....
....

Now, open the file and read the lines into ie. a string-array
(You can ReDim on your way, or hard-code it to 66)

(I would have created an UDT array, and split each line as I read it)

Fill your combobox with the first field in each line in the array
In the combo's click event, use combo.listindex to select the
corresponding line from the array.

Split that line in to it's respective fields and show them.
(Mid$() and instr(), or Split() are your friends here)

I am vague on purpose here, since you will learn *a lot* from this.

When you hit the wall, post, and thou shall be enlightened...

--
Dag.
Jul 17 '05 #3
Dag Sunde wrote:
"J French" <er*****@nowhere.com> wrote in message
news:3f***************@news.btclick.com...
Yes, there is an easier way

- actually I would be hard pressed to find a more difficult way

Put all the data in a file
- the solution will then become obvious

On Thu, 28 Aug 2003 17:32:53 +0200, "Cengiz Ulku" <ce*****@bluewin.ch>
wrote:

Hi,

I have a ComboBox which is filled with 66 items on form_load event:

<snipped />
I foresee another question from Cengiz, so i will elaborate a little
bit on our close-mouthed friend Jerry's idea:

If you put your 66 items into a textfile (Create it with notepad),
one item on each line, with a separator character that isn't used
elsewhere in your text between each field (Here I've used the "Bar" "|"):

Tekvin|Musa|Col|M.O. 1513|Yaradilistan M.O. 1657'ye kadar
....
....

Now, open the file and read the lines into ie. a string-array
(You can ReDim on your way, or hard-code it to 66)

(I would have created an UDT array, and split each line as I read it)

Fill your combobox with the first field in each line in the array
In the combo's click event, use combo.listindex to select the
corresponding line from the array.

Split that line in to it's respective fields and show them.
(Mid$() and instr(), or Split() are your friends here)

I am vague on purpose here, since you will learn *a lot* from this.

When you hit the wall, post, and thou shall be enlightened...

--
Dag.


If you don't want to use an external file...
Put those lines ("Tekvin|Musa|Col|blablablablablabla")
in a DATA statement and READ them out...
(Also something to learn ;-))

--
\|||/
(. .)
*--------ooO-(_)-Ooo--------*
| |
| co****@yucom.be |
| |
*---------------------------*

Jul 17 '05 #4
"Cookie" <co****@yucom.be> wrote in message
news:3F**************@yucom.be
<cut>
If you don't want to use an external file...
Put those lines ("Tekvin|Musa|Col|blablablablablabla")
in a DATA statement and READ them out...
(Also something to learn ;-))


In VB?

Jul 17 '05 #5

"Cookie" <co****@yucom.be> wrote in message
news:3F**************@yucom.be...
If you don't want to use an external file...
Put those lines ("Tekvin|Musa|Col|blablablablablabla")
in a DATA statement and READ them out...


This is VB, Cookie. The man's using VB.

Mike


Jul 17 '05 #6
Mike Williams wrote:
"Cookie" <co****@yucom.be> wrote in message
news:3F**************@yucom.be...

If you don't want to use an external file...
Put those lines ("Tekvin|Musa|Col|blablablablablabla")
in a DATA statement and READ them out...

This is VB, Cookie. The man's using VB.

Mike


Isn't DATA supported in VB? Never had to use it in VB though,
but that suprises me :)
--
\|||/
(. .)
*--------ooO-(_)-Ooo--------*
| |
| co****@yucom.be |
| |
*---------------------------*

Jul 17 '05 #7
Cookie wrote:
Mike Williams wrote:
"Cookie" <co****@yucom.be> wrote
If you don't want to use an external file...
Put those lines ("Tekvin|Musa|Col|blablablablablabla")
in a DATA statement and READ them out...


This is VB, Cookie. The man's using VB.

Mike


Isn't DATA supported in VB? Never had to use it in VB though,
but that suprises me :)


LOL, guess not... Well I'm learning still :-)

Jul 17 '05 #8
new NG reader here. (vb GUI fanaic)

but from what i see in this situation
the GUI is what it's all about

a form can double as a "data" entry page with the various fields written as strings to a file.
i would imagine the easiest way is to have fixed length fields that are written in sequence.
using
open <filename>
put <string>

ok that's a easy way of saying something that really isen't all that tricky
but the GUI would double as a viewer, where each field could be a drop down box (ordered/optional) and a selection would fill ni the
rest of the fields ...
the only problem with that is duplicate entries where the first instance would always be the one pulled up. so it sould include a
<next/previous> system..
what i'm still buzzed about is the actual lack od a search engine for the data
(data = file containg data not sql type - which would still be a viable option in BV)
there is even a "matrix" type grid control that is standard in comctl.oxc (sp?)
but i've never used it successfully yet)
ok that's my 2 cents
now i'll shut up

mike

"Cookie" <co****@yucom.be> wrote in message news:3F**************@yucom.be...
Cookie wrote:
Mike Williams wrote:
"Cookie" <co****@yucom.be> wrote
If you don't want to use an external file...
Put those lines ("Tekvin|Musa|Col|blablablablablabla")
in a DATA statement and READ them out...

This is VB, Cookie. The man's using VB.

Mike


Isn't DATA supported in VB? Never had to use it in VB though,
but that suprises me :)


LOL, guess not... Well I'm learning still :-)

Jul 17 '05 #9

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

Similar topics

0
by: Andreas Falck | last post by:
Hi, I ran the code below on two different versions, 4.0.14 and 4.0.16 respectively, both running RH 7.3 on intel. In version mysql server version 4.0.14 the SELECT privelege suffices for...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: xeqister | last post by:
Greetings all, We have a complicated statement in DB2 which takes long hour to complete and we have created most of the indexes. Does anybody knows how to tune the following statement to optimize...
0
by: Daniel | last post by:
Hi there, I recently came across an interesting option when right clicking on a project (Right click on the project -> properties -> Configuration Properties ->Build -> Optimize) There is an...
6
by: Silly | last post by:
byte Name = new byte; uint len = (uint)Name.Length; uint err = MyFunction(devID, out Name, out len); When this code is run in release build with optimize code set to true, len is evaluated to...
3
by: Reddy | last post by:
The sql query for my datagrid returns 100, 000 records. But the datagrid should display 20 records per page. I am using datagrid paging, but it is taking too much time for the page to load. Is...
15
by: kenneth | last post by:
I was trying to use multiple thread to optimize my following code, but met some problems, anyone can help me? k are initialized. int computePot() { int i, j; for( i=0; i<500; i++ ) { for(...
14
by: andreyvul | last post by:
I have this loop (all variables are pointers): for (foo = bar; foo baz; foo--) *(foo+1) = *foo; How do I optimize the pointer swap so that it uses -- and ++ or unary +- instead of +1 (if possible...
4
by: George2 | last post by:
Hello everyone, Why Visual Studio compiler can not optimize in this case? I think this case is almost the same as sample 1, why compiler can optimize sample 1 but can not optimze sample 2? ...
2
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.