Displaying lines of information in labels

  • I'm afraid I've got another question so soon after my last! :oops:


    Ideally I'd like to be able to program a label to show information when a button is clicked on a userform. I don't have a problem doing this, but I'd like to spread this info over several lines.


    Is it possible to put line breaks in labels?


    Being new to VBA, if this is not the best method for displaying information to users, can people advise me on alternatives to labels? I'm aware of message boxes, but again I don't know how to split the message into different lines.


    Thanks yet again for any help. If you need any more info let me know.

  • I'm also an amateur in VBA... but try this..


    use &vbcrlf& to force the text to go to another line....


    If you are typing your code in another line...don't forget also to put _ (underscore) before going to another line. The underscore means that the next line is a continuation of the previous line.


    hope this would help...

  • hi jezzialli,


    Welcome to Ozgrid.com


    to add a new line in yr msgboxes:

    Code
    msgbox"This is my msg " & vbnewline & "do you like it?"

    Cheers
    ___________
    Xlite :sheep:
    [st]All you need to learn VBA is an internet connection and Ozgrid.com[/st]

  • another way of displaying messages is by using labels


    in yr userform, insert a label.
    double click yr commandbutton, select the mousemove option in the right up corner and type:

    Code
    Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Label1.Caption = "My Command Button" & vbNewLine & "Please do as I say!"
    End Sub


    to return the label to be blank when the mouse is away from the command button,
    double click the userform, choose the mouse move option and type:

    Code
    Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Label1.Caption = ""
    End Sub


    HTH

    Cheers
    ___________
    Xlite :sheep:
    [st]All you need to learn VBA is an internet connection and Ozgrid.com[/st]

  • Continuing this topic, within labels, is there a way of programming them so that they display a set number of lines?


    An example would be for the label to show "Hello" a set number of times on different lines. The number of times it is repeated would depend on the value of a variable. For example, if the variable has value '3', the label shows "Hello" three times on separate lines.


    Is this possible, other than by using loads of IF statements (ie. IF variable = 3 then caption = "Hello" & vbnewline & "Hello" & vbnewline & "Hello", IF variable = 4 ... etc.)?


    Thanks for any help.

  • jezzialli,


    Code
    For intCount = 1 to intLines
         strMsg = strMsg & strSelMsg & chr(10)
    next intCount


    obviously the "intLines" variable controls the number of lines and the variables "strSelMsg" is the string you want repeated on the multiple lines.



    Regards,
    Barry

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!