|
-
Jul 28th, 2004, 03:56 AM
#1
Thread Starter
Frenzied Member
cleanning all textboxes on a form with a single code block (Resolved)
hi all,
I used to use this segment in VB6 to clear all textboxes on a form, but it seems to have difficulties running on VB.Net
VB Code:
dim ctl as control
for each ctl in controls
if typeof ctl is textbox then ctl.text = ""
next
Can anyone advise me, what is the equivelant code in VB.Net
\THX in Advance
BST RGDS
Last edited by maged; Jul 28th, 2004 at 05:19 AM.
-
Jul 28th, 2004, 04:17 AM
#2
VB Code:
Dim x As TextBox
For Each x In Me.Controls
x.Text = ""
Next
-
Jul 28th, 2004, 04:23 AM
#3
VB Code:
dim c as control
for each c in me.controls
if typeof c is textbox then
'do the trick
end if
next
-
Jul 28th, 2004, 04:25 AM
#4
Fanatic Member
Re: cleanning all textboxes on a form with a single code block
Originally posted by maged
hi all,
I used to use this segment in VB6 to clear all textboxes on a form, but it seems to have difficulties running on VB.Net
VB Code:
dim ctl as control
for each ctl in controls
if typeof ctl is textbox then ctl.text = ""
next
Can anyone advise me, what is the equivelant code in VB.Net
\THX in Advance
BST RGDS
ya code runs on my time machine mate
-
Jul 28th, 2004, 04:27 AM
#5
Fanatic Member
Originally posted by mendhak
VB Code:
Dim x As TextBox
For Each x In Me.Controls
x.Text = ""
Next
does this varry from 1.0 to 1.1? got a specified cast error. i'm using 2k2.
-
Jul 28th, 2004, 04:30 AM
#6
PowerPoster
Sorry mendhak, that is not like you
The correct code is
VB Code:
Dim x As Control
For Each x In Me.Controls
If TypeOf x Is TextBox Then
CType(x, TextBox).Text = ""
End If
Next
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 28th, 2004, 04:32 AM
#7
PowerPoster
Hi,
Loks like we are all posting as the other is typing
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 28th, 2004, 04:34 AM
#8
Thread Starter
Frenzied Member
well, thx for your reply
regarding the first solution, it is not working .
An exception of ( invalid cast exception is raised).
but regarding the second solution, it doesn't raise exception but also , it doesn't clear the textboxes
i am going thermally crazy
Any Sugesstions
THX for your precious time
BST RGDS
-
Jul 28th, 2004, 04:41 AM
#9
Strange, it worked the first time.(Yes, really!!!) 
Now why wouldn't the second one work? It's perfectly alright.
Try stepping through?
-
Jul 28th, 2004, 04:44 AM
#10
PowerPoster
HI,
You are not reading your posts fast enough, 'cos you obviously have not tried my suggestion which was
VB Code:
--------------------------------------------------------------------------------
Dim x As Control
For Each x In Me.Controls
If TypeOf x Is TextBox Then
CType(x, TextBox).Text = ""
End If
Next
Sorry you have been slightly mislead by a couple of guys, but they are not normally like that. They must hav had a late night
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 28th, 2004, 04:46 AM
#11
PowerPoster
Originally posted by mendhak
Strange, it worked the first time.(Yes, really!!!) 
Now why wouldn't the second one work? It's perfectly alright.
Try stepping through?
Any minute now mendhak, you are going to wake up from your VB6 harkback dream
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 28th, 2004, 04:49 AM
#12
-
Jul 28th, 2004, 05:18 AM
#13
Thread Starter
Frenzied Member
hallllo alll
well i figured out what was the problem
the problem is that my textboxes is grouped into panels, panels works as a form inside the form, so when it scans the controls on the main form. it doesn't find a thing except panels.
Anyway your code is right but i have modified it to a more powerfull and generic sub that will solve this problem even if there is a frame inside a frame inside a panel inside a group box . Etc.
it works fine for me, but you deserve to share it with me as your helped in it a lot
VB Code:
Public Sub ClearAll(ByVal frm As Control)
Dim OutCtl As Control
For Each OutCtl In frm.Controls
If OutCtl.Controls.Count > 0 Then
ClearAll(OutCtl)
Else
If OutCtl.GetType.IsAssignableFrom(GetType(TextBox)) Then
OutCtl.Text = ""
End If
End If
Next
End Sub
THX ALL FOR Your Time
It is resolved now
BST RGDS
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|