How to use left function in VB2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emsik1001
    New Member
    • Dec 2007
    • 93

    How to use left function in VB2005

    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
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by emsik1001
    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

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      What, they've removed the Left() function in VB2005? That's a little disappointing.

      Comment

      • mafaisal
        New Member
        • Sep 2007
        • 142

        #4
        hello

        I think
        this is working by importing microsoft.visua lbasic

        Microsoft.Visua lBasic.Strings. left(x.name,3)



        Originally posted by emsik1001
        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

        Comment

        • emsik1001
          New Member
          • Dec 2007
          • 93

          #5
          Thanks for that, I think I will just use mid instead :)

          Just wondering does VB8 have right function?

          Comment

          • emsik1001
            New Member
            • Dec 2007
            • 93

            #6
            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??????? ???????????

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              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?

              Comment

              • QVeen72
                Recognized Expert Top Contributor
                • Oct 2006
                • 1445

                #8
                Originally posted by emsik1001
                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 :

                [code=vbnet]
                Dim ctl As System.Windows. Forms.Control
                Dim ctl1 As System.Windows. Forms.Control
                '
                For Each ctl In Me.Controls
                If VB.Left(ctl.Nam e, 5) = "Label" Then
                ctl.ForeColor = Me.ForeColor
                ElseIf VB.Left(ctl.Nam e, 5) = "Frame" Then
                For Each ctl1 In ctl.Controls
                ctl1.ForeColor = Me.ForeColor
                Next
                End If
                Next ctl
                [/code]

                Note I have Imported Visual Basic:

                Imports VB = Microsoft.Visua lBasic

                Regards
                Veena

                Comment

                Working...