scrollPosition = 0

Heloooo.

I’m having a rather odd problem with textarea scrolling. Due to the fact that I’m loading the textarea from a database, the scroll position always ends up at the bottom unless I do this:

me.ScrollPosition = 0

That works great for sending the scroller to the top, except it doesn’t REALLY go to the top…it goes to 4 lines down from the top.

Does anybody have any idea what I can do about this? Any/all help would be greatly appreciated.

For clarity, here’s the whole chunk of code:

[code] Dim rs As RecordSet
rs = db.SQLSelect(“SELECT numcds,appname,descrip FROM appiso ORDER BY ID DESC”)

if rs <> Nil then
  While rs.EOF = False
    me.ScrollPosition = 0
    me.appendtext("Number of CDs:   " + rs.Field("numcds").StringValue + EndOfLine + "Title:   " + rs.Field("appname").StringValue + EndOfLine + "Description/Info:" + EndOfLine + rs.Field("descrip").StringValue + EndOfLine  + EndOfLine )
    rs.MoveNext
  Wend
  db.close
  
end if[/code]

What happens if you move the
me.ScrollPosition = 0
call to AFTER the end of the loop.

Inside the loop, build your string and right after the loop, move the built string in all at once.

[code]Dim s As String
Dim rs As RecordSet
rs = db.SQLSelect(“SELECT numcds,appname,descrip FROM appiso ORDER BY ID DESC”)

if rs <> Nil then
  While rs.EOF = False
    s = s + "Number of CDs:   " + rs.Field("numcds").StringValue + EndOfLine + "Title:   " + rs.Field("appname").StringValue + EndOfLine + "Description/Info:" + EndOfLine + rs.Field("descrip").StringValue + EndOfLine  + EndOfLine 
    rs.MoveNext
  Wend
  db.close
  me.text = s
end if[/code]

It’s not exactly the way I would build the string, but you get the idea. Build the string and move it all at once. That should keep the cursor at the top. Also, notice that I removed the setting of scrollposition because it isn’t needed if you do it this way.

I haven’t tested the code so it may not be a cut & paste solution. :slight_smile:

Roger: if I do that, then the scroller is at the bottom. That was how I originally did it…seemed logical to me, too.

Randy: YAY!!! That works! I needed to add a dim statement for s, but your solution worked, copy & paste. I can’t thank you enough for your help. I’ve only been at this programming stuff for about 2 months, so I still get hung up on the simple things sometimes.

BTW: You said “It’s not exactly the way I would build the string”. Can I ask how you would do it?

Thank you both for your replies. Very much appreciated. :slight_smile:

In programming, there are usually numerous ways to get to the same result. Given that you have only been at this “programming stuff” for about 2 months, I would suggest that you continue to do what makes the most logical sense to you. There will be plenty of time to learn more optimized ways of doing things. Just keep in mind that the “right” is the way that produces the desired result. It may not necessarily best the most optimized or efficient way, but optimization and efficiency are not always the most important things to strive for – especially when you are first starting out.

Without going into too much detail on how the concatenation of string is a costly operation, inside the loop, I would probably use an array to hold my lines of text. And at the end, I would join those lines of text together in a single operation like so.

Dim s() As String
Dim rs As RecordSet

rs = db.SQLSelect("SELECT numcds,appname,descrip FROM appiso ORDER BY ID DESC")
    
if rs <> Nil then
    While rs.EOF = False
        'append each line of text to the array
        s.append( "Number of CDs:   " + rs.Field("numcds").StringValue )
        s.append( "Title:   " + rs.Field("appname").StringValue )
        s.append( "Description/Info:" )
        s.append( rs.Field("descrip").StringValue )
        s.append( "" ) 'necessary if you want the additional EndOfLine
        
        'get next row in recordset
        rs.MoveNext
    Wend
    db.close

    'join the array entries together separating each entry with EndOfLine
    me.text = join( s, EndOfLine )
end if

There are many other ways, including using memoryblocks to do the concatenation. But like I said, I would continue to do what makes the most logical sense to you. Over time you will learn more efficient techniques when it becomes necessary.

Again, I haven’t tested this code. So it may not be cut & paste ready. :slight_smile:

Have fun!

I think I should have added one more append. You can tweak it as necessary.

[code]Dim s() As String
Dim rs As RecordSet

rs = db.SQLSelect(“SELECT numcds,appname,descrip FROM appiso ORDER BY ID DESC”)

if rs <> Nil then
While rs.EOF = False
'append each line of text to the array
s.append( "Number of CDs: " + rs.Field(“numcds”).StringValue )
s.append( "Title: " + rs.Field(“appname”).StringValue )
s.append( “Description/Info:” )
s.append( rs.Field(“descrip”).StringValue )
s.append( “” ) 'necessary if you want the additional EndOfLine
s.append( “” ) 'necessary if you want the additional EndOfLine

    'get next row in recordset
    rs.MoveNext
Wend
db.close

'join the array entries together separating each entry with EndOfLine
me.text = join( s, EndOfLine )

end if[/code]

Well, color me shocked…I actually understand what you presented.
That does seem like a more efficient way of doing this, as well as being a whole lot easier to read. I think I’ll be using this method from here on.

Great stuff. Thank you so much for taking the time to explain this to me. I really appreciate it! :slight_smile: