?
Solved

Scroll bar

Posted on 2003-02-26
7
Medium Priority
?
473 Views
Last Modified: 2008-02-26
Using VB6, could someone please help me with the basic code for a scroll bar. I have a label with a list of information within it. "I like the way it works for my project". Any ways, I've never messed around with scroll bars, so how do I code the bar? My label has information that's more than the label and I just want to be able to scroll down the label.

Thanks
0
Comment
Question by:vharrig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 200 total points
ID: 8027403
Use a textbox instead if a label, i don't think you can scroll a label. With a textbox you can set the property to multiline and scrollbars ( vertical, horizontal or both )
0
 

Author Comment

by:vharrig
ID: 8027527
aelatik,

Thanks that works, have any idea's why the scroll bar won't show up until I click on the text box. Then it show's up fine and works correctly.
0
 
LVL 3

Expert Comment

by:SirNick
ID: 8027542
Hello vharrig

Yes aelatik is right, just use a textbox and change the properties such as the background color, Appearance and border so that if looks the same as a label.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:SirNick
ID: 8027550
It will probably only show up if you have enough text inside it for the need of a scroll bar.
0
 

Author Comment

by:vharrig
ID: 8027583
Thanks
0
 
LVL 3

Expert Comment

by:Egore
ID: 8027746
Argh!  And I just finished this code to...  This gives you a scrolling label.  Try this out and see if you like it.  Create a text file called Form1.frm and paste the following code into it via NotePad or WordPad, then add it to a new VB project and run it:

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   4230
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6210
   LinkTopic       =   "Form1"
   ScaleHeight     =   4230
   ScaleWidth      =   6210
   StartUpPosition =   3  'Windows Default
   Begin VB.VScrollBar vScroll
      Height          =   975
      Left            =   3120
      TabIndex        =   1
      Top             =   360
      Width           =   255
   End
   Begin VB.Label lblText
      Caption         =   "lblText"
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   2895
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Lines() As String
Private LineCount As String
Private LinesToShow As Integer

Private Sub SplitText(OrigText As String)

    Dim CurrPos As Long
    Dim PreviousPos As Long
    Dim Text As String
    Dim NewLine As String
   
    ' Init
    LineCount = 0
    CurrPos = 0
    Text = OrigText
   
    If Text = "" Then Exit Sub
   
    ' Loop until we have analyzed the entire string
    Do
        ' Store this position
        PreviousPos = CurrPos
        CurrPos = CurrPos + 1
       
        NewLine = ""
       
        ' Move to the next space in the string
        ' NOTE: You may want to modify this to look for any type of white space
        CurrPos = InStr(CurrPos, Text, " ")
        If CurrPos = 0 Then
            ' Out of text, use it all
            NewLine = Text
        Else
            ' Determine if this is more than one full line
            NewLine = Left(Text, CurrPos)
        End If
       
        If Me.TextWidth(NewLine) < lblText.Width Then
            If CurrPos > 0 Then
                ' Don't use this
                NewLine = ""
            End If
        ElseIf PreviousPos > 1 Then
            ' We went over, use the previous value for the line
            NewLine = Left(Text, PreviousPos - 1)
           
            ' Reset the current position
            CurrPos = 1
        End If
       
        If NewLine <> "" Then
            ' Store this line
            ReDim Preserve Lines(LineCount) As String
            Lines(LineCount) = NewLine
            LineCount = LineCount + 1
           
            ' Remove this text from the main string
            Text = LTrim(Mid(Text, Len(NewLine) + 1))
        End If
    Loop Until CurrPos = 0

End Sub

Private Sub Form_Load()

    Dim I As Integer
    LinesToShow = 4
   
    ' NOTE: You need to use the same font for the form as for the label for this to work
    Call SplitText("This is the text that is being displayed in the label.  It will be word-wrapped by the SplitText routine and split into it's individual lines so that the scroll bar can scroll the text with some logic...  I'm trying to write a whole lot here so that we will see quite a bit of word wrap and all will be good with the world.  You might want to set this up to read in a text file and display it.  This would definately require retooling the SplitText function though, since it would need to be able to properly handle [Enter] characters (chr(10) & chr(13)), but I wish you the best in your wrapping endeavors.")
   
    ' Set the size of the scroll bar so that the maxvalue will display the last line at the bottom
    vScroll.Max = LineCount - LinesToShow
    vScroll.Value = 0
    Call vScroll_Change

End Sub

Private Sub vScroll_Change()

    Dim I As Integer
    Dim Text As String
   
    For I = 0 To LinesToShow - 1
        ' Get this line from the array
        If Text <> "" Then Text = Text & vbCrLf
        Text = Text & Replace(Lines(vScroll.Value + I), "&", "&&")
    Next
   
    ' Display this text in the label
    lblText.Caption = Text

End Sub

Private Sub vScroll_Scroll()

    Call vScroll_Change

End Sub
0
 
LVL 3

Expert Comment

by:Egore
ID: 8027774
Oh, as a side note, you can calculate the "LinesToShow" variable using Me.TextHeight().  Also, any time that you resize the label you would need to pass the original string back through the "SplitText()" routine.

If you have any questions about this please feel free to ask as it's no longer about the points, just about helping you get the results you desire...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question