By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

How to use left function in VB2005

P: 93
Hi

I want to change ForeColor but only for control names starting with letters lbl


I've got something like this

Dim x as control

For each x in controls

' how can I use function left in here to check only the first three letters?see below

If left(x.name,3) = "lbl" then 'this of course doesn't work
x.forecolor = color.orange
End if
Next

Many thanks in advance
Jan 16 '08 #1
Share this Question
Share on Google+
7 Replies


kadghar
Expert 100+
P: 1,295
Hi
' how can I use function left in here to check only the first three letters?see below

If left(x.name,3) = "lbl" then 'this of course doesn't work
x.forecolor = color.orange
End if
Next

Many thanks in advance
yeah, some sintax changes =( so sad
use mid(x.name,1,3)
HTH
Jan 16 '08 #2

Expert 5K+
P: 8,434
What, they've removed the Left() function in VB2005? That's a little disappointing.
Jan 17 '08 #3

mafaisal
100+
P: 142
hello

I think
this is working by importing microsoft.visualbasic

Microsoft.VisualBasic.Strings.left(x.name,3)



Hi

I want to change ForeColor but only for control names starting with letters lbl


I've got something like this

Dim x as control

For each x in controls

' how can I use function left in here to check only the first three letters?see below

If left(x.name,3) = "lbl" then 'this of course doesn't work
x.forecolor = color.orange
End if
Next

Many thanks in advance
Jan 17 '08 #4

P: 93
Thanks for that, I think I will just use mid instead :)

Just wondering does VB8 have right function?
Jan 17 '08 #5

P: 93
Now I have also a different problem,

For some reason when I use For each x in controls (on everything) it is omitting some controls.

The only thing I found is that I have change the forecolor in them but there are still the same (controltext) only there are in bold in the properties pane for some reason.

So if I change a forecolor property (originally controltext (not in bold)) to different one and back to original it is bold and it stops working with the for each x in controls??????????????????
Jan 17 '08 #6

Expert 5K+
P: 8,434
I'm afraid I didn't follow you very well, there. But are you sure they're not just being processed in a different sequence to what you expect?
Jan 17 '08 #7

QVeen72
Expert 100+
P: 1,445
For some reason when I use For each x in controls (on everything) it is omitting some controls.
Controls that are placed on the Containers like (Frame, GroupBox or Picture Box) are Omitted, they are not Part of the Form's Controls Group.
In such cases, you have to first loop thru all the Frames, Change the properties of these child controls .. some thing like this :

Expand|Select|Wrap|Line Numbers
  1. Dim ctl As System.Windows.Forms.Control
  2. Dim ctl1 As System.Windows.Forms.Control
  3. '
  4. For Each ctl In Me.Controls
  5.     If VB.Left(ctl.Name, 5) = "Label" Then
  6.         ctl.ForeColor = Me.ForeColor
  7.     ElseIf VB.Left(ctl.Name, 5) = "Frame" Then
  8.         For Each ctl1 In ctl.Controls
  9.             ctl1.ForeColor = Me.ForeColor
  10.         Next
  11.     End If
  12. Next ctl
  13.  
Note I have Imported Visual Basic:

Imports VB = Microsoft.VisualBasic

Regards
Veena
Jan 18 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.