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
Solved

vscroll

Posted on 1998-05-25
5
460 Views
Last Modified: 2011-10-03
I need a complete and detailed  working example of code for verticle scrolling of a text box. I am using vb4-16bit
0
Comment
Question by:hjaycox
  • 3
  • 2
5 Comments
 

Author Comment

by:hjaycox
ID: 1461589
Edited text of question
0
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 600 total points
ID: 1461590
hjaycox,

[1] To scroll a text box automatically:
Set the MultiLine property to True and the ScrollBars property to Vertical (2).

[2] To scroll text box programmatically, check the following example:

1. From the File menu, choose New Project (press ALT, F, N).
2. Double-click Form1 to bring up the code window.
3. Add the following API declaration to the General Declarations
section of Form1:
 
Declare Function PutFocus% Lib "user" Alias "SetFocus" (ByVal
                                                           hWd%)
Declare Function SendMessage& Lib "user" (ByVal hWd%,
                                          ByVal wMsg%,
                                          ByVal wParam%,
                                          ByVal lParam&)
 
4. Create a text box called Text1 on Form1. Set the MultiLine property to True and the ScrollBars property to Horizontal (1).
5. Create a command button called Command1 and change the Caption to "Vertical".
6. Create another command button called Command2 and change the Caption to "Horizontal".
7. From the General Declarations section of Form1, create a procedure to initialize some text in the text box as follows:
 
Sub InitializeTextBox ()
Text1.Text = ""
For i% = 1 To 50
 Text1.Text = Text1.Text + "This is line " + Str$(i%)
 For j% = 1 to 10
  Text1.Text = Text1.Text + " Word "+ Str$(j%)
 Next j%
    Text1.Text = Text1.Text + Chr$(13) + Chr$(10)
   x% = DoEvents()
Next i%
End Sub
 
8. Add the following code to the load event procedure of Form1:
 
Sub Form_Load ()
 Call InitializeTextBox
End Sub
 
9. Create the actual scroll procedure within the General Declarations section of Form1 as follows:
 
Function ScrollText& (TextBox As Control, vLines As Integer, hLines As Integer)

Const EM_LINESCROLL = &H406
Lines& = Clng(&H10000 * hLines) + vLines
SavedWnd%  = Screen.ActiveControl.Hwnd
TextBox.SetFocus
Success& = SendMessage(TextBox.HWnd, EM_LINESCROLL, 0, Lines&)
r% = PutFocus% (SavedWnd%)
ScrollText& = Success&
 
End Function

10. Add the following code to the click event procedure of Command1 labeled "Vertical":
 
Sub Command1_Click ()
 Num& = ScrollText&(Text1, 5, 0)
End Sub
 
11.  Add the following code to the click event procedure of Command2 labeled "Horizontal":
 
Sub Command2_Click ()
 Num& = ScrollText&(Text1, 0, 5)
End Sub


Best regards
Bin Huwairib
0
 

Author Comment

by:hjaycox
ID: 1461591
hjaycox,

1- Add Private keyword before the declaration:

 Private Declare Function PutFocus% Lib...
 Private Declare Function SendMessage& Lib...

2- You mess type the function, its not CHNG its CLNG (clng) and its a function in VB.

3- The loop in InitializeTEXTBOX() sub is for testing perpose, so you can remove it and put your code there. Example:

Sub InitializeTextBox()
 Dim MyParag as String
 
 MyParag = "Line No.1" & Chr(13) & Chr(10)
 MyParag = MyParag + "Line No.2" + Chr(13) + Chr(10)
 ..
 ..
 MyParag = MyParag + "Line No.30"
 Text1.Text = MyParag
End Sub

Bin Huwairib
0
 
LVL 5

Expert Comment

by:bin_huwairib
ID: 1461592
thanks have another 100 on me
0
 

Author Comment

by:hjaycox
ID: 1461593
excellent ...thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 59
Using "ScreenUpdating" 6 73
Access query that references subform 5 47
clicking a shape in a frame array vb6 3 46
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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