473,396 Members | 2,009 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,396 software developers and data experts.

better way to program than this?

Hi,

I was wondering whether there is a better way to program code than this:
assume i need to create a lot of TabelCell with the same characterists
(HorizontalAlign, BackColor etc ...).

I can't use a loop (for/next) because the 'Text' is always different. What i
did was:

Dim c as TableCell
Dim r as TableRow
....
'first cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=a
r.Cells.Add(c) ' add to row

'next cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=b
r.Cells.Add(c) ' add to row
etc ...
Is it not possible to define once all the characteristics of c instead of
repeating them for each cell?

Thanks
André
Nov 27 '06 #1
4 940
Andre:

Don't fail to take advantage of simple structured solutions. While you
could create a subclass (I wouldn't in this case) the easy solution is to
add a private function that returns a New TableCell that is pre-filled in.
Pass that function the text you want and it will be assigned as well. This
can be placed in a loop with a bit more tweaking (creating an array of text
values) but you probably don't have to go that far. So you end up with:

r.CellsAdd( MyNewTableCell(a))
r.CellsAdd( MyNewTableCell(b))
etc.

Tom
"André" <hjhhb@ddwrote in message
news:ec**************@TK2MSFTNGP06.phx.gbl...
Hi,

I was wondering whether there is a better way to program code than this:
assume i need to create a lot of TabelCell with the same characterists
(HorizontalAlign, BackColor etc ...).

I can't use a loop (for/next) because the 'Text' is always different. What
i did was:

Dim c as TableCell
Dim r as TableRow
...
'first cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=a
r.Cells.Add(c) ' add to row

'next cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=b
r.Cells.Add(c) ' add to row
etc ...
Is it not possible to define once all the characteristics of c instead of
repeating them for each cell?

Thanks
André

Nov 27 '06 #2
of course. You can place them in the class constructor.
Or make a sub that assigns them.

-t :)

André ha scritto:
Hi,

I was wondering whether there is a better way to program code than this:
assume i need to create a lot of TabelCell with the same characterists
(HorizontalAlign, BackColor etc ...).

I can't use a loop (for/next) because the 'Text' is always different. What i
did was:

Dim c as TableCell
Dim r as TableRow
...
'first cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=a
r.Cells.Add(c) ' add to row

'next cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=b
r.Cells.Add(c) ' add to row
etc ...
Is it not possible to define once all the characteristics of c instead of
repeating them for each cell?

Thanks
André
Nov 27 '06 #3
Thanks both

<to**************@uniroma1.itschreef in bericht
news:11*********************@f16g2000cwb.googlegro ups.com...
of course. You can place them in the class constructor.
Or make a sub that assigns them.

-t :)

André ha scritto:
Hi,

I was wondering whether there is a better way to program code than this:
assume i need to create a lot of TabelCell with the same characterists
(HorizontalAlign, BackColor etc ...).

I can't use a loop (for/next) because the 'Text' is always different. What
i
did was:

Dim c as TableCell
Dim r as TableRow
...
'first cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=a
r.Cells.Add(c) ' add to row

'next cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=b
r.Cells.Add(c) ' add to row
etc ...
Is it not possible to define once all the characteristics of c instead of
repeating them for each cell?

Thanks
André

Nov 28 '06 #4
André wrote:
I was wondering whether there is a better way to program code than this:
assume i need to create a lot of TabelCell with the same characterists
(HorizontalAlign, BackColor etc ...).

I can't use a loop (for/next) because the 'Text' is always different.
<snip>

If the only thing that makes a cell appart from the others is the text,
you can pull the text from an array in a For Each /Next loop:

<aircode>
Dim CellText() AS String = { _
"Text1", "Text2", "Text3", ..., "TextN" _
}

For Each Text As String In CellText

Dim C as New TableCell
C.HorizontalAlign = HorizontalAlign.Center
C.BackColor = Drawing.Color.LightSteelBlue
C.Text= Text
...
... Add the cell to the row
...
Next
</aircode>

HTH.

Regards,

Branco.

Nov 28 '06 #5

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

Similar topics

5
by: Abby Lee | last post by:
My code does what I want (works unless there is a lot of volume...works for this month cause not a lot of items marked paid yet...) but the page times out for last month because there is just so...
4
by: Nobody | last post by:
Lets say I have a class that is only available if a specific DLL (a.dll) is present. I can't link to that DLL through lib files or my app will fail on any machine that doesn't have a.dll. So I...
36
by: Ben Justice | last post by:
For a program in c, I need some random numbers for a system were people are placing bets. This is not a commerical project btw. Generally, I tend to rely on things from the standard library,...
3
by: darklight | last post by:
Q: write a program so that it excepts six even numbers or until the number 99 is entered please explain why one is better than the other, if that is the case. A1: /*EX6-1.C TO COUNT AND...
85
by: masood.iqbal | last post by:
I know that this topic may inflame the "C language Taleban", but is there any prospect of some of the neat features of C++ getting incorporated in C? No I am not talking out the OO stuff. I am...
23
by: JoeC | last post by:
I am a self taught programmer and I have figured out most syntax but desigining my programs is a challenge. I realize that there are many ways to design a program but what are some good rules to...
22
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
10
by: weidongtom | last post by:
Hi, I was working on the following problem and I managed to get a solution, but it's too slow. And I am still in search for a better algorithm. Please enlighten me. ...
23
by: mike3 | last post by:
Hi. (posted to both newsgroups since I was not sure of which would be appropriate for this question or how specific to the given language it is. If one of them is inappropriate, just don't send...
5
by: Tony WONG | last post by:
i have a "for next" program to detect workstations ON/OFF status by ping. i wish the program restart after 60 seconds after completion of for next loop. at present, i use...
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
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?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.