Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. To display in a label

To display in a label

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Softtips2004
    wrote on last edited by
    #1

    I have used the following code to display # in a label.But it is getting displayed only once.Why? Private Sub Command1_Click() Dim n, i As Integer n = Val(Text1.Text) Label2.Caption = "" For i = 1 To n Label2.Caption = "#" Next End Sub

    D L 2 Replies Last reply
    0
    • S Softtips2004

      I have used the following code to display # in a label.But it is getting displayed only once.Why? Private Sub Command1_Click() Dim n, i As Integer n = Val(Text1.Text) Label2.Caption = "" For i = 1 To n Label2.Caption = "#" Next End Sub

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Softtips2004 wrote: I have used the following code to display # in a label.But it is getting displayed only once.Why? Private Sub Command1_Click() Dim n, i As Integer n = Val(Text1.Text) Label2.Caption = "" For i = 1 To n Label2.Caption = "#" Next End Sub Your only getting one '#' because your overwritting the value in Label2.Caption 'n' times, your not appending to it. If you want to append to it then you have to do something like this:

      Label2.Caption = ""
      For i = 1 To n
      Label2.Caption = Label2.Caption & "#"
      Next

      Or you could simplify it even further and do it this way:

      Private Sub Command1_Click()
      Dim n as Integer = Val(Text1.Text)
      Label2.Caption = new String("#", n)
      End Sub

      RageInTheMachine9532

      1 Reply Last reply
      0
      • S Softtips2004

        I have used the following code to display # in a label.But it is getting displayed only once.Why? Private Sub Command1_Click() Dim n, i As Integer n = Val(Text1.Text) Label2.Caption = "" For i = 1 To n Label2.Caption = "#" Next End Sub

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        :cool: hey it is so simple the code is given here Private Sub Command1_Click() Dim n, i As Integer n = Val(Text1.Text) Label2.Caption = "" For i = 1 To n Label2.Caption = Label2.Caption + "#" Next End Sub Any Problem Contact me :cool: VickyMD a Specialist in Message Digest Security i think so i m posting it 2 seconds late sorry for that

        M 1 Reply Last reply
        0
        • L Lost User

          :cool: hey it is so simple the code is given here Private Sub Command1_Click() Dim n, i As Integer n = Val(Text1.Text) Label2.Caption = "" For i = 1 To n Label2.Caption = Label2.Caption + "#" Next End Sub Any Problem Contact me :cool: VickyMD a Specialist in Message Digest Security i think so i m posting it 2 seconds late sorry for that

          M Offline
          M Offline
          mikasa
          wrote on last edited by
          #4

          You can simplify the "Concatenation" like this...

          For i = 1 To n
          Label2.Caption &= "#"
          Next

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups