Please Reply about coding vs designer/wizard practise

Status
Not open for further replies.

AnjaliArora

New member
Joined
Jun 23, 2006
Messages
3
Programming Experience
Beginner
Hi Friends

I m new in this field.Could you please clear some of my doubts.

1. I heard it is better to use coing mode rather than design mode to create or insert some contoles LIKE:

a) creating connection string, data adapter , dataset through coding instead of wizard.

b)creating insatance of tool tip

like ttp1 as tooltip

n then use it on every control, on which tooltip to provide rather than draging tool tip controle from toolbox n setting tooltip at design time.

Same with error provider, status bar etc.???

Hope I were able to make myself clear.

Please someone reply me why coing should be prefered, if so. When such a easy way to use these functionalities has been provided
does it makes any effect over speed of application??

2.how we can clear all the controles' value by smallest coding LIKE ()

one common way: textbox1.text=""
textbox2.text="" .......... same for all

any other way

( and if u could please provide the best coing approch for al this, as I am new I wanna start with right thing.)

Thanks of lot if someone would help.
 
for question 2:

VB.NET:
For Each Ctrl as Control in Me.Controls
If TypeOf Ctrl is Textbox Then
Ctrl.Text = ""
End If
Next
Loops through every control on the form, checks if its a textbox, if so it will clear it

There are many ways to code, so there isnt one "right way"
 
There's one flaw in that code craig..... if the text boxes are on a panel or some other container.... they will get missed.... but there is a way to get around that:

VB.NET:
        Private Sub ClearTextBoxes(ByVal ControlList As ControlCollection)
            For Each Ctrl As Control In ControlList
                If TypeOf Ctrl Is TextBox Then
                    Ctrl.Text = ""
                ElseIf Ctrl.HasChildren Then
                    ClearTextBoxes(Ctrl.Controls)
                End If
            Next
        End Sub
This will iterate through any child controls.

-tg
 
Code vs Designers..... it depends.... I don't use canned designers or components for any database work. I find they either do too much for me, or not enough. Plus I like to be in control of my data. Other than that, If it makes my life easier, then I go for it.

There's also another belief that one should learn how to do things through code, then when you do you a designer, you can appreciate the work it is doing for you, as well as understanding what is going on under the hood.

-tg
 
to answer question 1:
using the form designer or doing it yourself in code doesnt affect the speed of the program by very much, i personally find it easier to use the form designer as much as possible because i can set properties and move things around much easier than doing it myself in the code window

also managing dataadapters and tooltips in my opinion are much easier to use through the designer
 
Clearing TextBoxs

Thanks guys

To Craig

I tried that too but faced the problem which "TechGnome" Identified.
Thanks buddy,be in touch for my other problems.


To TechGnome

Thanks a lot but I dt know what is controlelist/controlecollection here(please explain), I mean What to pass as argument to this procedure. Basically I am using group boxes as container.

I tried calling this procedure like: ClearTextBoxes(Ctrl.Controls) , but does nt work I am doing some R&D over it on my end , if u could still modify it someway??? ()

N Thanks buddy, ur point "one shhould know how to do these things by coding" then only we can troubleshoot if we will get some problem in future right??? It was reallt convincing.


To JuggaloBrotha

Thanks to u too Sir, As I am at learning stage yet I guess TechGn*'s Point is more appropriate for me. Still thanks for enlihtning me that it does not make any difference of actual speed!!!

Even I would prefer small things like tooltip n error provider at design time!!!


So friends My next little problem is to display dynamic Time on statusbar ( by dynamic time here my mean is "It should set n chage with system or server's time")

Is theer's any other way apart from using Timer ) and please If anyone could provide coding of setting time by timer too???

Thanks for ur kind cooperation.
 
Even the system clock relies on a separate thread. That is all a timer is, a component that gives us access to a separate thread and also provides us with a convenient tick event. Since a clock 'ticks' and so does a timer then i would use a timer.
I think to get the system time you could do something like this...

VB.NET:
<StructLayout(LayoutKind.Sequential)> _
Private Strcture SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

<DllImport("Kernal32")> _
Private Shared Sub GetSystemTime Lib "kernel32" (byref lpSystemTime As SYSTEMTIME)

to use....
 
Dim Systime as systemtime
GetSystemTime(systime)
There may well be a native .net way to do this. If there is i would go down that road.
 
If you want something to happen at an interval then, as vis said, you use a Timer. You get the current time by Date.Now. If you want to display the current time without the date in a Label you would do something like this:
VB.NET:
myLabel.Text = Date.Now.ToLongTimeString()
If you want a clock then you'd add a Timer to your form, set its interval to 1000 (milliseconds), double-click it to create a Tick event handler and put that code in it. Now your Timer will Tick once every second and the current time will be displayed in your Label.
 
Craig said:
for question 2:

VB.NET:
For Each Ctrl as Control in Me.Controls
If TypeOf Ctrl is Textbox Then
Ctrl.Text = ""
End If
Next
Loops through every control on the form, checks if its a textbox, if so it will clear it

There are many ways to code, so there isnt one "right way"

Guys, I would just like to add my two pennies worth ... instead TypeOf use the GetType method ... it is better for the performance (it is recommended by MS too).
I.e.

If ctrl.GetType is GetType(TextBox) then
{...}


Regards ;)
 
Craig said:
for question 2:

VB.NET:
For Each Ctrl as Control in Me.Controls
If TypeOf Ctrl is Textbox Then
Ctrl.Text = ""
End If
Next
Loops through every control on the form, checks if its a textbox, if so it will clear it

There are many ways to code, so there isnt one "right way"


Not quite.. you need to make the routine recursive:

VB.NET:
Sub ClearAllTextBox(toSearch as Window.Forms.Control.ControlCollection)
  For Each x as Control in toSearch
    if TypeOf x is GroupBox then ClearAllTextBox(DirectCast(x, GroupBox).Controls)
    if TypeOf x Is TextBoxBase then DirectCast(x, TextBoxBase).Text = Nothing
  Next x
End Sub

and you say:
ClearAllTextBox(Me.Controls)

your routine will only clear textboxes that are not in any kind of group container, im afraid..
 
kulrom said:
Guys, I would just like to add my two pennies worth ... instead TypeOf use the GetType method ... it is better for the performance (it is recommended by MS too).
I.e.

If ctrl.GetType is GetType(TextBox) then
{...}


Regards ;)


To qualify this, there are situations where you might choose one or the other.. its not simply a "use this instead"


GetType will tell you if an object is of a certain type, whereas TypeOf will tell you if an object is type compatible with what you specified..


In my example, i use TypeOf because im looking for TextBoxBase - the parent control of serveral types of textbox. GetType would not work in this situation because it returns that x is a "TextBox". I cannot compare this with the GetType for TextBoxBase - a textbox is not a textbox base, but descended from it

Dim tbx as New TextBox
If TypeOf tbx is Object then MessageBox.Show("tbx is type compatible with/descended from object")
If TypeOf tbx is TextBoxBase then MessageBox.Show("tbx is type compatible with/descended from TextBoxBase")
If tbx.GetType is GetType(Object) then MessageBox.Show("tbx's type is Object")
If tbx.GetType is GetType(TextBoxBase) then MessageBox.Show("tbx's type is TextBoxBase")


The first two will show, the last two will not

Use GetType when youre sure what youre looking for (i should have done it wiht groupbox).. use typeof when you want to check an object is descended from another
 
kulrom said:
Wow what a nonsense statement ... althrough all in .NET is considered as object declared var as textBox cannot be an object . lol

I'm confused.. are you responding to me? I'm the only person to have posted since you last posted, yet your post seems to mean that you think the following is a nonsense statement:

"althrough all in .NET is considered as object declared var as textBox cannot be an object"


..to which I agree. It IS a nonsense statement - but not one I have made in any one of my posts?

So, in accordance with the "Feel free to ask more if your thread isn't properly answered by my reply" element of your signature.. Would you mind explaining your post a little more clearly for the benefit of the readers of this thread?
 
Hello,
1st off i must say that you are approving your statement giving not adequate examples that are not related with the current question and that is not correct cuz it is confusing the people.
If TypeOf tbx is Object then MessageBox.Show(///}
This will work just cuz VB6 TypeOf function is created to accept a parameter of Type OBJECT. That's why you will get the expected result that doesn't prove anything.
In my opinion: you will want to use TypeOf if you want to also match controls that are inherited from the base control. while, you will want to use GetType when you want to know that it was specifically that type of control that is case here (we are looking for control's type) ..right?
But also notice that there is VB.NET way to accomplish the same. Next time i will explain to you.
Regards and don't be that serious (no offense too ... i have no reason to do that)
Cheers ;)
 
Status
Not open for further replies.
Back
Top