home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / adding1a / longline.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-28  |  4.6 KB  |  135 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Long Lines"
  4.    ClientHeight    =   7845
  5.    ClientLeft      =   1575
  6.    ClientTop       =   1935
  7.    ClientWidth     =   6585
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   7845
  10.    ScaleWidth      =   6585
  11.    Begin VB.TextBox Text1 
  12.       Height          =   315
  13.       Left            =   1875
  14.       TabIndex        =   4
  15.       Text            =   "1034"
  16.       Top             =   900
  17.       Width           =   1215
  18.    End
  19.    Begin VB.ComboBox Combo1 
  20.       Height          =   315
  21.       Left            =   375
  22.       TabIndex        =   3
  23.       Text            =   "Combo1"
  24.       Top             =   900
  25.       Width           =   1215
  26.    End
  27.    Begin VB.CheckBox Check1 
  28.       Caption         =   "&Split"
  29.       Height          =   315
  30.       Left            =   3375
  31.       TabIndex        =   2
  32.       Top             =   900
  33.       Width           =   1215
  34.    End
  35.    Begin VB.CommandButton Command1 
  36.       Caption         =   "&Add Line"
  37.       Height          =   465
  38.       Left            =   5025
  39.       TabIndex        =   1
  40.       Top             =   750
  41.       Width           =   1215
  42.    End
  43.    Begin VB.ListBox List1 
  44.       Height          =   4545
  45.       Left            =   450
  46.       TabIndex        =   0
  47.       Top             =   1500
  48.       Width           =   5640
  49.    End
  50.    Begin VB.Label Label3 
  51.       Caption         =   "0"
  52.       Height          =   315
  53.       Left            =   450
  54.       TabIndex        =   7
  55.       Top             =   6150
  56.       Width           =   5565
  57.    End
  58.    Begin VB.Label Label2 
  59.       Caption         =   "Length"
  60.       Height          =   165
  61.       Left            =   1875
  62.       TabIndex        =   6
  63.       Top             =   675
  64.       Width           =   1215
  65.    End
  66.    Begin VB.Label Label1 
  67.       Caption         =   "Character"
  68.       Height          =   165
  69.       Left            =   375
  70.       TabIndex        =   5
  71.       Top             =   675
  72.       Width           =   1215
  73.    End
  74. Attribute VB_Name = "Form1"
  75. Attribute VB_GlobalNameSpace = False
  76. Attribute VB_Creatable = False
  77. Attribute VB_PredeclaredId = True
  78. Attribute VB_Exposed = False
  79. Option Explicit
  80. 'Written by Steve Henning
  81. ' http://home.pix.za/sh/sh00001/
  82. ' VB list boxes maximum line length is 1024 characters, (I haven't seen this raised in the documentation).
  83. ' The AddToListbox function adds a line with the option of splitting it if it is too long.
  84. ' You may use this code anywhere, anyhow, though realize it is at your own risk.
  85. ' I cannot be held responsible for any errors, omissions or stupid mistakes on my part, Microsofts or any one elses.
  86. ' These 1 lines below can be added to a .bas file, remember to replace the Private with Global
  87. Private Const LB_SETHORIZONTALEXTENT = &H194
  88. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
  89. Private Sub Command1_Click()
  90.   AddToListbox List1, String$(Val("0" & Text1.Text), Combo1.Text), (Check1.Value = vbChecked)
  91.   List1.ListIndex = List1.NewIndex
  92. End Sub
  93. 'Adds a line to a listboxe and sets a horizontal scrollbar so we should be able to view the longest line.
  94. ' If bSplitOverMultipleLines is TRUE, lines > 1024 will be split
  95. Function AddToListbox(lb As ListBox, sData$, Optional bSplitOverMultipleLines As Boolean = False)
  96.   Dim sCopy$, sListboxString$
  97.   Dim lWidth&
  98.   Static lLongest&
  99.   If lb.ListCount = 0 Then lLongest = -1
  100.   sCopy = Trim$(sData$)
  101.   Do While sCopy <> ""
  102.     sListboxString = Left(sCopy, 1024)
  103.     lb.AddItem sListboxString
  104.     lWidth = Len(sListboxString)
  105.     If lWidth > lLongest Then
  106.       lLongest = lWidth
  107.       ' This line of code will add horizontal scroll-bar to the listbox.
  108.       Call SendMessageLong(lb.hwnd, LB_SETHORIZONTALEXTENT, Me.TextWidth(String$(lLongest + 1, "W")), 0&)
  109.     End If
  110.     If Not bSplitOverMultipleLines Then Exit Do
  111.     ' Get rid of leading 1024 characters that we have just added to the listbox.
  112.     sCopy = Mid$(sCopy, 1025)
  113.   Loop
  114. End Function
  115. Private Sub Form_Load()
  116.   Dim i%
  117.   Check1.Value = vbChecked
  118.   ' Needed for call to LB_SETHORIZONTALEXTENT
  119.   Me.ScaleMode = vbPixels
  120.   List1.FontName = "Courier New"
  121.   Me.FontName = List1.FontName
  122.   Me.FontSize = List1.FontSize
  123.   ' Add some data
  124.   For i = 0 To 9
  125.     Combo1.AddItem Chr$(48 + i)
  126.   Next
  127.   For i = 0 To 26
  128.     Combo1.AddItem Chr$(65 + i)
  129.   Next
  130.   Combo1.ListIndex = 0
  131. End Sub
  132. Private Sub List1_Click()
  133.   Label3.Caption = Len(List1.Text)
  134. End Sub
  135.