I am currently writing an application that writes to a text file. Depending on what the user does within the application the text file can vary in size. I have created a result screen (FORM), so the user can see the results of his actions within the application easily and I'm importing the text file into a label in the form using a file scripting object:
Set fso = CreateObject("Scripting.FileSystemObject"
Set txtfile = fspenTextFile(myfile, 1, 0)
RESULTFORM.label = txtfile.readall
txtfile.close
This works great unless the text file gets larger than the label size's height or width. This is where scrolling would be necessary, to see the rest of the file (both horizontally and vertically).
When I want to scroll a form I use the following code:
Private Sub Form_Load()
Dim VPos As Integer
Dim Hpos As Integer
'Change the following numbers to the Full height and width of your Form
intFullHeight = 9000 'Maximized the Form and note the Figures
intFullWidth = 12000
'This is the how much of your Form is displayed
intDisplayHeight = Me.Height
intDisplayWidth = Me.Width
With VScroll1
'.Height = Me.ScaleHeight
.Min = 0
.Max = intFullHeight - intDisplayHeight
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
With HScroll1
'.Width = Me.ScaleWidth
.Min = 0
.Max = intFullWidth - intDisplayWidth
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
End Sub
Sub ScrollForm(Direction As Byte, NewVal As Integer)
Dim CTL As Control
Static hOldVal As Integer
Static vOldVal As Integer
Dim hMoveDiff As Integer 'Diff in the horizontal controls movements
Dim vMoveDiff As Integer 'Diff in the vertical controls Movements
Select Case Direction
Case 0 'Scroll Vertically
'Check The Direction of the Vertical Scroll & Extract Value Diff
If NewVal > vOldVal Then 'Scrolled From Top to Bottom
'Controls MUST move to the TOP, therefore TOP value Decreases
vMoveDiff = -(NewVal - vOldVal)
Else 'Scrolled From Bottom to Top
'Controls MUST move to the Bottom, therefore TOP value Increases
vMoveDiff = (vOldVal - NewVal)
End If
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not _
(TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.Y1 = CTL.Y1 + vMoveDiff '+ VPos - VScroll1.Value
CTL.Y2 = CTL.Y2 + vMoveDiff '+ VPos - VScroll1.Value
Else
CTL.Top = CTL.Top + vMoveDiff '+ VPos - VScroll1.Value
End If
End If
Next
vOldVal = NewVal 'Reset vOldVal to reflect New Pos of ScrollBar
Case 1 'Scroll Horizontally
'Check The Direction of the Horizontal Scroll & Extract Value Diff
If NewVal > hOldVal Then 'Scrolled From Left to Right
'Controls MUST move to the LEFT, therefore LEFT value Decreases
hMoveDiff = -(NewVal - hOldVal)
Else 'Scrolled From Right to Left
'Controls MUST move to the RIGHT, therefore LEFT value Increases
hMoveDiff = (hOldVal - NewVal)
End If
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not _
(TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.X1 = CTL.X1 + hMoveDiff
CTL.X2 = CTL.X2 + hMoveDiff
Else
CTL.Left = CTL.Left + hMoveDiff
End If
End If
Next
hOldVal = NewVal 'Reset hOldVal to reflect New Pos of ScrollBar
End Select
End Sub
Private Sub HScroll1_Change()
ScrollForm 1, HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
ScrollForm 1, HScroll1.Value
End Sub
Private Sub VScroll1_Change()
ScrollForm 0, VScroll1.Value
End Sub
Private Sub VScroll1_Scroll()
ScrollForm 0, VScroll1.Value
End Sub
Can this code be used to scroll a label instead of a form?? Anyone know of another way to scroll a label??
Set fso = CreateObject("Scripting.FileSystemObject"
Set txtfile = fspenTextFile(myfile, 1, 0)
RESULTFORM.label = txtfile.readall
txtfile.close
This works great unless the text file gets larger than the label size's height or width. This is where scrolling would be necessary, to see the rest of the file (both horizontally and vertically).
When I want to scroll a form I use the following code:
Private Sub Form_Load()
Dim VPos As Integer
Dim Hpos As Integer
'Change the following numbers to the Full height and width of your Form
intFullHeight = 9000 'Maximized the Form and note the Figures
intFullWidth = 12000
'This is the how much of your Form is displayed
intDisplayHeight = Me.Height
intDisplayWidth = Me.Width
With VScroll1
'.Height = Me.ScaleHeight
.Min = 0
.Max = intFullHeight - intDisplayHeight
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
With HScroll1
'.Width = Me.ScaleWidth
.Min = 0
.Max = intFullWidth - intDisplayWidth
.SmallChange = Screen.TwipsPerPixelX * 10
.LargeChange = .SmallChange
End With
End Sub
Sub ScrollForm(Direction As Byte, NewVal As Integer)
Dim CTL As Control
Static hOldVal As Integer
Static vOldVal As Integer
Dim hMoveDiff As Integer 'Diff in the horizontal controls movements
Dim vMoveDiff As Integer 'Diff in the vertical controls Movements
Select Case Direction
Case 0 'Scroll Vertically
'Check The Direction of the Vertical Scroll & Extract Value Diff
If NewVal > vOldVal Then 'Scrolled From Top to Bottom
'Controls MUST move to the TOP, therefore TOP value Decreases
vMoveDiff = -(NewVal - vOldVal)
Else 'Scrolled From Bottom to Top
'Controls MUST move to the Bottom, therefore TOP value Increases
vMoveDiff = (vOldVal - NewVal)
End If
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not _
(TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.Y1 = CTL.Y1 + vMoveDiff '+ VPos - VScroll1.Value
CTL.Y2 = CTL.Y2 + vMoveDiff '+ VPos - VScroll1.Value
Else
CTL.Top = CTL.Top + vMoveDiff '+ VPos - VScroll1.Value
End If
End If
Next
vOldVal = NewVal 'Reset vOldVal to reflect New Pos of ScrollBar
Case 1 'Scroll Horizontally
'Check The Direction of the Horizontal Scroll & Extract Value Diff
If NewVal > hOldVal Then 'Scrolled From Left to Right
'Controls MUST move to the LEFT, therefore LEFT value Decreases
hMoveDiff = -(NewVal - hOldVal)
Else 'Scrolled From Right to Left
'Controls MUST move to the RIGHT, therefore LEFT value Increases
hMoveDiff = (hOldVal - NewVal)
End If
For Each CTL In Me.Controls
'Make sure it's not a ScrollBar
If Not (TypeOf CTL Is VScrollBar) And Not _
(TypeOf CTL Is HScrollBar) Then
'If it's a Line then
If TypeOf CTL Is Line Then
CTL.X1 = CTL.X1 + hMoveDiff
CTL.X2 = CTL.X2 + hMoveDiff
Else
CTL.Left = CTL.Left + hMoveDiff
End If
End If
Next
hOldVal = NewVal 'Reset hOldVal to reflect New Pos of ScrollBar
End Select
End Sub
Private Sub HScroll1_Change()
ScrollForm 1, HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
ScrollForm 1, HScroll1.Value
End Sub
Private Sub VScroll1_Change()
ScrollForm 0, VScroll1.Value
End Sub
Private Sub VScroll1_Scroll()
ScrollForm 0, VScroll1.Value
End Sub
Can this code be used to scroll a label instead of a form?? Anyone know of another way to scroll a label??