|
-
Sep 17th, 2004, 12:00 PM
#1
Thread Starter
Addicted Member
How to wrap to a text file? (RESOLVED)
How to wrap a 240 length textbox to a 80 length line and print it on a text file?
Thanks.
Last edited by AlvaroF1; Sep 22nd, 2004 at 10:20 AM.
-
Sep 17th, 2004, 12:58 PM
#2
Something like this to limit the lines in a multi-line textbox on a line
by line basis.
CodeBank
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 17th, 2004, 03:19 PM
#3
PowerPoster
Can't you just use multi-line?
I know the textbox's have a basic word-wrap built in if you have some certain properties enabled.
A wrapped box, may not save wrapped thought
It may put the NULL character at places where the linefeed is.
NULL character is that blank rectangle u see now and then.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Sep 17th, 2004, 03:32 PM
#4
No you cant use multi-line alone because the poster wants to
limit each lines length to 80 characters. The code allows the enter
key to make the line breaks. Then you can output to a text file
like so...(note: this ex. is limited to 10 chrs per line).
VB Code:
Option Explicit
'API Declarations:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
'Constant Delcarations
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Private Sub Command1_Click()
Dim i As Integer
Dim ar() As String
ar = Split(Text1.Text, vbKeyReturn)
Open "C:\Test.txt" For Output As #1
For i = 0 To UBound(ar)
Print #1, ar(i)
Next
Close #1
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim lLen As Long
'Get the length of the current line:
lLen = SendMessage(Text1.hwnd, EM_LINELENGTH, EM_LINEINDEX, 0&)
'If length is 10, don't allow more characters:
If lLen = 10 And KeyAscii <> vbKeyReturn And KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 17th, 2004, 03:33 PM
#5
Banned
not true. blank rects depend on the font
-
Sep 17th, 2004, 03:35 PM
#6
Actually the little squares represent an "Un-Supported" character.
Depending on either the font, encoding, or the actual character.
A backspace character of ASCII 8 is shown as a square because it
can't be displayed as a visual character.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 17th, 2004, 06:10 PM
#7
PowerPoster
Well so my assumtion of it being at least a null character is fairly true because it is techinally nothing..or error.
Thanks for the explanation though, I did not know that.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Sep 17th, 2004, 06:16 PM
#8
No prob.
I hate those little squares!
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 18th, 2004, 12:29 AM
#9
Hyperactive Member
What I would do is take the whole string, read 80 characters, back up to the nearest space so you don't split a word and replace that space witha vbCrLF (vb Carriage Return/Line Feed) character and repeat until you reach the end of the string. Then write the whole string to the text file.
If I have time I will update this post later with some code.
The Mav
-
Sep 20th, 2004, 10:06 AM
#10
Thread Starter
Addicted Member
Originally posted by Maverickz
What I would do is take the whole string, read 80 characters, back up to the nearest space so you don't split a word and replace that space witha vbCrLF (vb Carriage Return/Line Feed) character and repeat until you reach the end of the string. Then write the whole string to the text file.
If I have time I will update this post later with some code.
The Mav
I think you are right. I wrote a code but it isn't working correctly:
VB Code:
Dim i As Integer
Select Case Len(Text1)
Case Is <= 80
Print #1, Text1
Case Is <= 160
For i = 80 To 1 Step -1
If Mid$(Text1, i, 1) = " " Then
Print #1, Left$(Text1, i - 1)
Print #1, Mid$(Text1, i + 1, Len(Text1))
Exit For
End If
Next i
Case Else
Dim z As Integer
For i = 80 To 1 Step -1
If Mid$(Text1, i, 1) = " " Then
Print #1, Left$(Text1, i - 1)
z = i + 1
Exit For
End If
Next i
For i = 160 To 81 Step -1
If Mid$(Text1, i, 1) = " " Then
Print #1, Mid$(Text1, z, i - 81)
Print #1, Mid$(Text1, i + 1, 80)
Exit For
End If
Next i
End Select
-
Sep 20th, 2004, 10:11 AM
#11
Banned
you cant use a select case you need to use a loop and midstr.
-
Sep 20th, 2004, 10:14 AM
#12
Banned
VB Code:
Dim I As Long
For I = 0 to Len(Text1.Text) Step 80
Mid$(Text1.Text, I, I + 1) = vbCrLf
Next I
-
Sep 20th, 2004, 10:21 AM
#13
nareth, besides errorneus behavior, that wouldn't work: you can't do Mid$(Text1.Text, I, I + 1) = vbCrLf, because you can do like that only to a variable, not a property of a textbox.
-
Sep 20th, 2004, 10:23 AM
#14
Banned
i forgot :P
dont mind me im feeling sick
-
Sep 20th, 2004, 02:17 PM
#15
Hmm... I just remembered: you can use DrawTextW so that it won't draw the text, but instead looks for the size of it. You can also limit the width it draws to and I believe it might even be able to alter the string so that it adds the linechanges. Thus you could do it with one API call (if you use a fixed width font, such as FixedSys). It wouldn't work if there would be lines with too long continuous content, like 90 = characters one after another.
If someone wants to, I can take a look if it can do it.
-
Sep 22nd, 2004, 10:18 AM
#16
Thread Starter
Addicted Member
RESOLVED!
VB Code:
Private Function QuebrarTexto(ByVal Texto As String, ByVal Tamanho As Integer) As String
Tamanho = Tamanho + 1
Texto = Trim$(Texto)
Dim MeioEnter As String, Enter As String, NovaLinha As String, l As Integer, s As String, c As String, NovoTexto As String
MeioEnter = Chr$(13)
Enter = Chr$(13) & Chr$(10)
Do
l = Len(NovaLinha)
s = InStr(Texto, " ")
c = InStr(Texto, MeioEnter)
If c Then
If l + c <= Tamanho Then
NovoTexto = NovoTexto & NovaLinha & Left$(Texto, c)
NovaLinha = ""
Texto = Mid$(Texto, c + 1)
GoTo Loopar
End If
End If
If s Then
If l + s <= Tamanho Then
NovaLinha = NovaLinha & Left$(Texto, s)
Texto = Mid$(Texto, s + 1)
ElseIf s > Tamanho Then
NovoTexto = NovoTexto & Enter & Left$(Texto, Tamanho)
Texto = Mid$(Texto, Tamanho + 1)
Else
NovoTexto = NovoTexto & NovaLinha & Enter
NovaLinha = ""
End If
Else
If l Then
If l + Len(Texto) > Tamanho Then
NovoTexto = NovoTexto & NovaLinha & Enter & Texto & Enter
Else
NovoTexto = NovoTexto & NovaLinha & Texto & Enter
End If
Else
NovoTexto = NovoTexto & Texto & Enter
End If
Exit Do
End If
Loopar:
Loop
QuebrarTexto = NovoTexto
End Function
Private Sub Command1_Click()
Open "C:\MeuArquivo.txt" For Output As #1
Print #1, QuebrarTexto(Text1, 80)
Close #1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|