Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrolling Output That Exceeds Screen Size
#10
here is a scrolling demo for reading any text or bas file that uses crlf to end lines
Code: (Select All)
_Title "Scroll file" ' b+ 2024-04-08
Width 140, 41
_ScreenMove 100, 60
pfile$ = _OpenFileDialog$("Select file to read", _CWD$, "*.bas|*.txt", "text files", 0)
If pfile$ <> "" Then
    t$ = _ReadFile$(pfile$)
    ReDim f$(1 To 1)
    Split t$, Chr$(13) + Chr$(10), f$()
    inputcount = UBound(f$)
    For n = 1 To 40
        Print f$(n)
    Next
    Do
        Do While _MouseInput
            If row >= 0 Then row = row + _MouseWheel Else row = 0 'prevent under scrolling
            If row > inputcount - 40 Then row = inputcount - 40 'prevent over scrolling
            If prevrow <> row Then 'look for a change in row value
                If row > 0 And row <= inputcount - 40 Then
                    Cls: Locate 2, 1
                    For n = row To row + 40
                        Print f$(n)
                    Next
                End If
            End If
            prevrow = row 'store previous row value
        Loop
    Loop Until InKey$ > ""
End If

' note: I buggered this twice now, FOR base 1 array REDIM MyArray (1 to 1) AS ... the (1 to 1) is not same as (1) which was the Blunder!!!
'notes: REDIM the array(0) to be loaded before calling Split '<<<< IMPORTANT dynamic array and empty, can use any lbound though
'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given.  rev 2019-08-27
Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
    Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
    curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
    dpos = InStr(curpos, SplitMeString, delim)
    Do Until dpos = 0
        loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
        arrpos = arrpos + 1
        If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
        curpos = dpos + LD
        dpos = InStr(curpos, SplitMeString, delim)
    Loop
    loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
    ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
End Sub

edit to increase screen size and center it better on screen
edit2 forgot to change page size
dang still finding errors, it's a starter
b = b + ...
Reply


Messages In This Thread
RE: Scrolling Output That Exceeds Screen Size - by bplus - 04-09-2024, 12:34 AM



Users browsing this thread: 4 Guest(s)