How Do I Trim Line Feeds?
Is there a way to trim line feeds from the beginning and end of a string? I need to know as soon as possible.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Replacing Line Feeds
Hi,
I have a VB problem that is driving me nuts... I have some unix files that I have to process.
I read in some text and do a replace function...
strOutput = Replace(strOutput, "|", "", , , vbBinaryCompare)
This works fine...
I then do this:
strOutput = Replace(strOutput, "" & vbLf , " ", , , vbBinaryCompare)
and the result is the "" has been replaced but the Line feed has been converted in to a CRLF (hex OD OA).
If I convert the file to DOS first and do a replace for a "" & vbCrLf , the code works fine! - unfortunately I cant do this for all the files ( they are too big)
can anyone shed some light on this?
Cheers,
JAS
Carriage Returns And Line Feeds?
What does each do? What do they do that is different to each other, ie. what justifies their existence? Am I better to use vbCr or vbLf or vbCrLf?
Edited by - PhateNZ on 8/17/2005 12:00:54 AM
Prevent Textbox From Removing Trailing Line Feeds
I'm having some troubles in retrieving the original value from a Textbox. I have a textbox control with the EnterKeyBehavior set to true, so that a user can use the Enter key to create line feeds in the text box.
Now this works fine, but my problem is that if a user types some text in the textbox and ends the text with some empty lines by hitting the Enter key a few times, these final Enter keys (or linefeeds) are NOT stored in the Textbox value while the line feeds ARE stored inbetween 'normal' text. So it looks like that, at the time the text from the textbox is stored under its '.Value' property the trailing linefeed characters are trimmed? However, I really need these trailing linefeeds. Is there a solution for this? Or is it just impossible using VBA?
Carriage Returns And Line Feeds In Flat Text Files - Some Findings
Hi!. These two threads made me want to do this. Any comments/corrections will be greatly appreciated
http://209.120.143.185/showthread.ph...BLF+Print+Open
http://209.120.143.185/showthread.ph...BLF+Print+Open
As those threads point out, CRLFs are very common delimiters for us VB Programmers and messing them up creates huge problems.
Generate the text file from the code. Open the generated file using Different Text Editors. I have used the three I have; NotePad, WinWord (Office 2000), WordPad
Save the text file from each editor, using a different file name.
The text editors automaticaly choose the "Save As Text" format. Do not change this format!
Generate the comparison file.
What I think is happening is some app creates a flat text file with Line Feeds or Carriage Returns or Both
Since these flat files are named ".txt" files, when we open it, it opens, either in Notepad or Wordpad depending on the size of the file.
We edit it to our convenience and just do a "File-Save" or a "File-Save As".
All the Linebreaks therefore get messed up.
Solution(s)?. One way is what I did in the two threads I have posted.
Strip Carriage Returns, Split by Line Feeds, Reconstruct.
Any other ideas would be greatly appreciated
VB Code:
Const VB As String = "VBtext.txt"Const NP As String = "Np.txt" 'Plain Windows Notepad FormatConst Word As String = "Word.txt" 'Microsoft WinWord (Office 2000) "Save As Text" FormatConst WP As String = "WP.txt" 'Plain Windows WordPad Format Dim Path As String, CheckString As StringPrivate Sub evaluate_Click() Dim strNP As String, strVB As String, strWord As String, strWP As String Dim kByte As Byte Open Path & VB For Binary As #1 For i = 1 To LOF(1) Get 1, i, kByte strVB = strVB & " " & CStr(kByte) Next i Close #1 Open Path & NP For Binary As #1 For i = 1 To LOF(1) Get 1, i, kByte strNP = strNP & " " & CStr(kByte) Next i Close #1 Open Path & Word For Binary As #1 For i = 1 To LOF(1) Get 1, i, kByte strWord = strWord & " " & CStr(kByte) Next i Close #1 Open Path & WP For Binary As #1 For i = 1 To LOF(1) Get 1, i, kByte strWP = strWP & " " & CStr(kByte) Next i Close #1Open Path & "Compare.txt" For Output As #1 Print #1, "Original Text :->" & strVB Print #1, vbNewLine Print #1, "Saved From NPad:->" & strNP Print #1, vbNewLine Print #1, "Saved From Word:->" & strWord Print #1, vbNewLine Print #1, "Saved From WPad:->" & strWP Print #1, vbNewLineClose #1Shell "notepad " & Path & "compare.txt", vbMaximizedFocusEnd Sub Private Sub Form_Load() Path = App.Path & "Crlf"End Sub Private Sub GenVBtxt_Click()CheckString = "Hello World" & " " & "Hello VB Forums" & " " & "KayJay" & " " & "Kaushik Janardhanan" & " " & "End of Test Text File"Open Path & "VBTEXT.TXT" For Output As #1 Print #1, "Hello World"; ' 11 Bytes Print #1, vbCr; Print #1, "Hello VB Forums"; ' 15 Bytes Print #1, vbLf; Print #1, "KayJay"; ' 6 Bytes Print #1, vbCrLf; Print #1, "Kaushik Janardhanan"; ' 19 Bytes Print #1, vbNewLine; Print #1, "End of Test Text File" ' 21 Bytes 'VB adds a Chr(13) Chr(10) here automaticallyClose #1 MsgBox "VB Text File Created"End Sub
If you analyse the compared output you will find that
(1) MS-Word adds a Carriage Return when it encounters a Line Feed
(2) WordPad makes sure all LineBreaks are a CRLF. It sees a lonely Line Feed, it adds a Carriage Return. It sees a Carriage Return all by itself, it adds a Line Feed.
(3) Notepad simply does nothing. It just does not recognize a Carriage Return or a Line Feed as Line Breaks when they are by themselves. It just shows a black box. It displays a LineBreak only when Carriage Returns and Line Feeds come in pairs.
Should try with more text editors to see if something more crops up.
Attached is a zip file with the Text Files already saved from the different editors. Any comments/suggestions/solutions ?
Generating Directory List With Extended File Properties. Want To Remove Line Feeds That Break My Href
Pretty primitive down below, but it sort of gets the job done. Have had to use WRITE LINE command to generate a table
objNewFile.WriteLine objFolder.GetDetailsOf(strFileName, 10)
Would prefer to include GetDetails with text string output, but unsuccessful. Like this
objNewFile.WriteLine "<tr><td>"objFolder.GetDetailsOf(strFileName, 0)
Crap out all the time. Here's the full script.
'********************************************
'24 Oct 07 - script is used to write extended file properties into a new htm file
'to text file
'May be executed from RUN window command line, or, double click on script icon.
'********************************************
'Preprocessing Directives Library Calls
'********************************************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objStdOut = WScript.StdOut
Set objFS = CreateObject("Scripting.FileSystemObject")
'********************************************
'Variables called to generate unique log name
'********************************************
dtmThisYear = Year(Date)
dtmThisMonth = Month(Date)
dtmThisDay = Day(Date)
'********************************************
'Create text file name (year_month_day)
'********************************************
strFileName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay & "_daily_log.htm"
'********************************************
'Create text file target using
'********************************************
Set objNewFile = objFSO.CreateTextFile(strFileName)
'*******************************************
'Array set to return first 14 of 36 fields available on extended document properties
'Will only use five.
'0=file name, 4=date created, 10=title 11=subject 14=comments
'Microsoft reference @http://www.microsoft.com/technet/scriptcenter/gui de/sas_fil_lunl.mspx
'See remarked-out table at end of file for all file attributes
'******************************************
Dim arrHeaders(14)
'********************************************
'Target Directory - set this variable to directory name
'********************************************
objStartFolder = ""
'********************************************
'Write header data to file log
'********************************************
objNewFile.WriteLine "<html><body><h1>List and properties of make a remark to identify output generated</h1>" & Now()
objNewFile.WriteLine
objNewFile.WriteLine "Following entries provide links to the images available for use while building documents pertaining to model"
objNewFile.WriteLine
objNewFile.WriteLine "<table bgcolor=""white"" border=""5"" width=""100%""><tr><td width=""*"">Name</td><td width=""3*"">Title</td><td width=""3*"">Description</td><td width=""3*"">Comments</td>"
objNewFile.WriteLine
'********************************************
'Processes required for reading file properties
'********************************************
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("M:whatever directory/file path")
'********************************************
'Write out file property data with tabs
'0=file name, 10=title, 11=subject 14=comments
'********************************************
For Each strFileName in objFolder.Items
objNewFile.WriteLine "<tr><td>"
objNewFile.WriteLine objFolder.GetDetailsOf(strFileName, 0)
objNewFile.WriteLine """</a><td>"
objNewFile.WriteLine objFolder.GetDetailsOf(strFileName, 10)
objNewFile.WriteLine "<td>"
objNewFile.WriteLine objFolder.GetDetailsOf(strFileName, 11)
objNewFile.WriteLine "<td>"
objNewFile.WriteLine objFolder.GetDetailsOf(strFileName, 14)
Next
objNewFile.WriteLine "</table></body></html>"
'*****************************************
'trying to remove line breaks so i can write hyperlinks
'objNewFile.Replace(NewFile)'#chr(10)#','',ALL)
'objNewFile.Replace(NewFile,#chr(13)#,,ALL)
'************************************************* **********************
Trim Trailing Line Breaks
Hi,
What is the best way to trim trailing line breaks (vbCrLf) from a string? Similar to RTrim to remove spaces. Do I have to loop and remove one by one?
Thanks,
Glenn
Trim Numbers From First Line Of Address ****
How can i trim the numbers out of the first line of an address, as not all addresses have house numbers, some have names.
The addresses are stored in a database, and im trying to sort out an automatic look up to save the user retyping in the full address. ie user enters 34 Mayflower Drive, and I want to check to see if that Road name already exisits, so i need to trim the 34 off.
Yes post code/zip codes may be different for different parts of the street or two street names the same, but im going to look at that later.
Thanks in advance.
Ping
Trim The Next Line Off A Text File
Hello again!
I knew I would be back!
Right... The last problem is sorted but:
How do I trim the blank next line from a text file? Every time I write to a text file (using append function) it seems to add a blank line in below.
My program doesn't work with this added in... How can I remove it?
I have tried:
Dim AmendedAttachment
Open "C:Automatic E-MailJames BondAttachment.txt" _
For Input As #1
Text2.Text = Input$(LOF(1), #1)
AmendedAttachment = Trim(Text2.Text)
Text2.Text = AmendedAttachment
Close 1
Trim Line/file In A Word Document ?
How can I remove the space from the end of lines in a word document ?
I need to read the file and save it ..
I saw the RTrim , but I didn't know how to use it ?
Thanks
XML Feeds
Hello, I'm having qa bit of nightmare trying to get an xml feed to work -
I am using hte following code:
'-------------------------------------------------------------
Public oHttpReq As XMLHTTP40
Public oXMLDoc As DOMDocument40
Set oHttpReq = New XMLHTTP40
Dim xhrHandler As myHttpRequestHandlers
' Open a connection and set up a request to the server.
oHttpReq.open "GET", gstrReqURL, False
oHttpReq.send
Set oXMLDoc = oHttpReq.responseXML
Set oNode = oXMLDoc.selectSingleNode("//events")
If oNode Is Nothing Then
MsgBox ("Requested information not found.")
Else
MsgBox (oNode.Text)
End If
'------------------------------------------------------------
If I use a static XML file with the following XML in it its works fine:
<?xml version="1.0" encoding="iso-8859-1" ?>
<events>
<event ID="4">
<EVENTID>4</EVENTID>
<EVENTNAME>Some event</EVENTNAME>
</event>
<events>
<event ID="5">
<EVENTID>5</EVENTID>
<EVENTNAME>Some other event</EVENTNAME>
</event>
</events>
But if I use an active server page that just writes this XML code I can't seem to get the informaion across
Can anyone give me an help to get this working
Cheers
RSS Feeds
does anyone have some code to create an RSS feed from a UDT or perhaps from a series of text boxes?
Thanks!
VB 6 And RSS Feeds
I am working on a project where I want to read rss feeds (just the headers) and display it in a scrolling text. I have the scrolling and txt file working, but I can get the rss (or xml) feed to read. I was thinking about this flow of programming (read, combine into a string with " , " separating the headers, then displaying). Does anyone have any ideas?
Internet Feeds
Is there someone who could knidly point me to some code to access internet feeds? (atom prefferably) Or better yet, an example? Thx
RSS Feeds Sometimes It Works
Hi,
I am building an RSS reader in vb6 (I know there are plenty out there but I have to integrate it into TTS for blind people). So I got my program to work and can download the entire NY Times(RSS feeds). When I go to another source (CNN News online) the RSS feeds don't download anything. Am I missing something?
John
Form Feeds
I thought formfeed was chr(10)? Anyway, this may be a little messy but. it works
dim intFreeFile as integer,intI as integer, intJ as integer, strLine as string, intCount as integer
intfreefile = freefile
open "filename.txt" for input as #intfreefile
do until EOF(intfreefile)
Line Input #intFreeFile, strLine 'dumps first line from file into strline
for inti = 1 to len(strline)
intJ = InStr(strLine, chr(12))
if intJ <> 0 then
intCount = intCount + 1
strLine = Mid$(strLine, intJ + 1)
inti = intj
else
exit for
end if
next intI
loop
'that would go through each line looking for the chr(12). IF it finds it, drops off the first part, adds 1 to counter and continues through line at the new location. if it Doesn't find it, exits for that line. Then it load the next line and continues.
I haven't tried it yet but I know the basic structure works.
Form Feeds
I am developing a program that has a text box that displays a report. The user is supposed to see one page of the report at a time and has a "Next Page" and "Previous Page" command button to see additional pages. I have the code to display the whole report but I need to write the code to search for ASCII Chr$12 and display the text from one form feed to another. HELPPPPP!!!!
Live Data Feeds
Folks, Whats the best way to incorporate a live data feed (video camera) into an application and being able to capture the image and save to a database.
Where To Get Hardware News Feeds?
hi, i know this is not a right place to ask this but i would like to ask u guys if you know of any good place i could get hardware news feed (in XML format) so i can place it on my site...
any help would be appreciated...
wojo.
Live Data Feeds
Folks, What's the best way to incorporate a live data feed (digital camera) into an application and being able to capture the image and save to a database
Printer Just Feeds Out Paper Instead Of Printing
Hello to everyone viewing.
I have a printing problem.
My VB6 program has to print a list which comprises of a header, a few labels and the contents of a listview, the code I use is posted below.
Most of the time this code works perfectly fine and prints the list as required but every now and again when I try to print the list, the printer just feeds out blank sheets out paper continuously and prints nothing.
I have tried my program on 3 seperate computers with 3 different types of printer, they all print ok but all 3 just feed out paper occasionaly.
Here is my code.
Code:
Private Sub cmdPrint_Click() 'Print ListView command
Dim a As clsPrintLV
Set a = New clsPrintLV 'Call Print Class module
a.PrintListView ListView1
Printer.EndDoc
MsgBox "The current list has been sent to the Printer.", vbInformation, "Print Manager"
End Sub
Option Explicit
Public Event MaxYReached(ByVal CurrentY As Double, ByRef oPrinter As Object, ByRef bRePrintHeader As Boolean)
Public Event Progress(ByVal oNextListItem As ListItem, ByRef oPrinter As Object, ByRef bRePrintHeader As Boolean, ByVal lTotalLines As Long, ByRef bCancel As Boolean)
Dim Page As Integer
Private mlFromX As Long
Public Sub PrintListView(lvListview As ListView, Optional ByVal oPrinter As Object, Optional ByVal bLines As Boolean = False, Optional ByVal bBlackAndWhite As Boolean = True, Optional ByVal MaxY As Double, Optional ByVal lFromX As Long)
Dim oListItem As ListItem
Dim oSubItem As ListSubItem
Dim oColumnHeader As ColumnHeader
Dim iCounter As Integer
Dim lPrevY As Long
Dim sCorrectPrintText As String
Dim bRePrintHeader As Boolean
Dim bCancel As Boolean
MaxY = 15000
mlFromX = lFromX
Set oPrinter = Nothing
If oPrinter Is Nothing Then
Set oPrinter = Printer
End If
With oPrinter
.Font = lvListview.Font
.FontSize = 10
Call PrintHeader(lvListview, oPrinter)
.CurrentY = .CurrentY + .TextHeight(" ") + (.TextHeight(" ") / 2)
For Each oListItem In lvListview.ListItems
bRePrintHeader = False
RaiseEvent Progress(oListItem, oPrinter, bRePrintHeader, lvListview.ListItems.Count, bCancel)
If bCancel Then
Exit For
End If
If bRePrintHeader Then
Call PrintHeader(lvListview, oPrinter)
End If
Set oColumnHeader = lvListview.ColumnHeaders(1)
lPrevY = .CurrentY
.CurrentY = lPrevY
.CurrentX = .CurrentX - oListItem.Width
Select Case oColumnHeader.Alignment
Case lvwColumnLeft
.CurrentX = mlFromX + oListItem.Left + 550 'sets print distance from left for 1st column
Case lvwColumnRight
.CurrentX = mlFromX + oListItem.Left + oListItem.Width - .TextWidth(oColumnHeader.Text) - 120
Case lvwColumnCenter
.CurrentX = mlFromX + oListItem.Left + ((oListItem.Width - .TextWidth(oListItem.Text)) / 2)
End Select
.ForeColor = IIf(bBlackAndWhite, vbBlack, oListItem.ForeColor)
If oListItem.Width > 15 Then
sCorrectPrintText = Trim$(oListItem.Text)
If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 60 Then
Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120)
sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
Loop
sCorrectPrintText = sCorrectPrintText & "..."
End If
Debug.Assert sCorrectPrintText = Trim$(oListItem.Text)
oPrinter.Print sCorrectPrintText; 'Because of some weird bug there has to be oPrinter before this
' If i dont add the oPrinter i get a syntax error
End If
.CurrentY = lPrevY
For Each oSubItem In oListItem.ListSubItems
Set oColumnHeader = lvListview.ColumnHeaders(oSubItem.Index + 1)
Select Case oColumnHeader.Alignment
Case lvwColumnLeft
.CurrentX = mlFromX + oColumnHeader.Left + 550 'sets print distance from left for sub item columns
Case lvwColumnRight
.CurrentX = mlFromX + oColumnHeader.Left + oColumnHeader.Width - .TextWidth(oSubItem.Text) - 120
Case lvwColumnCenter
.CurrentX = mlFromX + oColumnHeader.Left + ((oColumnHeader.Width - .TextWidth(oSubItem.Text)) / 2)
End Select
.ForeColor = IIf(bBlackAndWhite, vbBlack, oSubItem.ForeColor)
If oColumnHeader.Width > 15 Then
sCorrectPrintText = Trim$(oSubItem.Text)
If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 120 Then
Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120) Or (sCorrectPrintText = "")
sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
Loop
sCorrectPrintText = sCorrectPrintText & "..."
End If
oPrinter.Print sCorrectPrintText;
End If
.CurrentY = lPrevY
Next
.CurrentY = .CurrentY + oListItem.Height
If .CurrentY > MaxY Then
oPrinter.NewPage
Call PrintHeader(lvListview, oPrinter)
.CurrentY = .CurrentY + .TextHeight(" ") + (.TextHeight(" ") / 2)
End If
Next
End With
oPrinter.Print ""
oPrinter.Print ""
oPrinter.Print ""
oPrinter.CurrentX = 8000
oPrinter.Print "Outstanding Balance : £" & " " & frmOtstngAcc!lblBal.Caption
oPrinter.EndDoc
End Sub
Public Sub PrintHeader(lvListview As ListView, oPrinter As Object)
Dim lPrevY As Long
Dim oColumnHeader As ColumnHeader
Dim sCorrectPrintText As String
Page = Page + 1
With oPrinter
'Print Date
.CurrentX = 490
.CurrentY = 2500
oPrinter.Print "Date : " & frmOtstngAcc!lblDate2.Caption
'Print Page number
.CurrentX = 10100
.CurrentY = 2500
oPrinter.Print "Page : " + Str(Page)
'Print Insurance Company
.CurrentX = 490
.CurrentY = 3000
oPrinter.Print "Company : " & frmOtstngAcc!cboInsCo.Text
'Print label Outstanding Accounts
.CurrentX = 4500
.CurrentY = 3500
.FontUnderline = True
oPrinter.Print "OUTSTANDING ACCOUNTS"
.FontUnderline = False
For Each oColumnHeader In lvListview.ColumnHeaders
If oColumnHeader.Width > 60 Then
lPrevY = 4000 'sets print distance from top
Select Case oColumnHeader.Alignment
Case lvwColumnLeft
.CurrentY = 4000 ''sets print distance from top for 1st column header
.CurrentX = mlFromX + oColumnHeader.Left + 550 'sets print distance from left for 1st column header
Case lvwColumnRight
.CurrentX = mlFromX + oColumnHeader.Left + oColumnHeader.Width - .TextWidth(oColumnHeader.Text) - 120
Case lvwColumnCenter
.CurrentX = mlFromX + oColumnHeader.Left + ((oColumnHeader.Width - .TextWidth(oColumnHeader.Text)) / 2) + 900
End Select 'sets print distance from left for Date column
If oColumnHeader.Width > 15 Then
sCorrectPrintText = Trim$(oColumnHeader.Text)
If sCorrectPrintText <> "" Then
If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 120 Then
Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120) Or (sCorrectPrintText = "")
sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
Loop
sCorrectPrintText = sCorrectPrintText & "..."
End If
oPrinter.Print sCorrectPrintText;
End If
End If
.CurrentY = lPrevY
End If
Next
'Print Line
Printer.DrawWidth = 8
oPrinter.Line (250, 4275)-(11200, 4275)
End With
End Sub
Please help me if you can.
I've got to go out to work now so I wont be able to reply to any posts untill tommorow 12.00 GMT
Thanks
Steve.
Printer Just Feeds Out Blank Paper
Hello to everyone viewing.
I have a printing problem.
My VB6 program has to print a list which comprises of a header, a few labels and the contents of a listview, the code I use is posted below.
Most of the time this code works perfectly fine and prints the list as required but every now and again when I try to print the list, the printer just feeds out blank sheets out paper continuously and prints nothing.
I have tried my program on 3 seperate computers with 3 different types of printer, they all print ok but all 3 just feed out paper occasionaly.
Here is my code.
Code:Private Sub cmdPrint_Click() 'Print ListView command
Dim a As clsPrintLV
Set a = New clsPrintLV 'Call Print Class module
a.PrintListView ListView1
Printer.EndDoc
MsgBox "The current list has been sent to the Printer.", vbInformation, "Print Manager"
End Sub
Option Explicit
Public Event MaxYReached(ByVal CurrentY As Double, ByRef oPrinter As Object, ByRef bRePrintHeader As Boolean)
Public Event Progress(ByVal oNextListItem As ListItem, ByRef oPrinter As Object, ByRef bRePrintHeader As Boolean, ByVal lTotalLines As Long, ByRef bCancel As Boolean)
Dim Page As Integer
Private mlFromX As Long
Public Sub PrintListView(lvListview As ListView, Optional ByVal oPrinter As Object, Optional ByVal bLines As Boolean = False, Optional ByVal bBlackAndWhite As Boolean = True, Optional ByVal MaxY As Double, Optional ByVal lFromX As Long)
Dim oListItem As ListItem
Dim oSubItem As ListSubItem
Dim oColumnHeader As ColumnHeader
Dim iCounter As Integer
Dim lPrevY As Long
Dim sCorrectPrintText As String
Dim bRePrintHeader As Boolean
Dim bCancel As Boolean
MaxY = 15000
mlFromX = lFromX
Set oPrinter = Nothing
If oPrinter Is Nothing Then
Set oPrinter = Printer
End If
With oPrinter
.Font = lvListview.Font
.FontSize = 10
Call PrintHeader(lvListview, oPrinter)
.CurrentY = .CurrentY + .TextHeight(" ") + (.TextHeight(" ") / 2)
For Each oListItem In lvListview.ListItems
bRePrintHeader = False
RaiseEvent Progress(oListItem, oPrinter, bRePrintHeader, lvListview.ListItems.Count, bCancel)
If bCancel Then
Exit For
End If
If bRePrintHeader Then
Call PrintHeader(lvListview, oPrinter)
End If
Set oColumnHeader = lvListview.ColumnHeaders(1)
lPrevY = .CurrentY
.CurrentY = lPrevY
.CurrentX = .CurrentX - oListItem.Width
Select Case oColumnHeader.Alignment
Case lvwColumnLeft
.CurrentX = mlFromX + oListItem.Left + 550 'sets print distance from left for 1st column
Case lvwColumnRight
.CurrentX = mlFromX + oListItem.Left + oListItem.Width - .TextWidth(oColumnHeader.Text) - 120
Case lvwColumnCenter
.CurrentX = mlFromX + oListItem.Left + ((oListItem.Width - .TextWidth(oListItem.Text)) / 2)
End Select
.ForeColor = IIf(bBlackAndWhite, vbBlack, oListItem.ForeColor)
If oListItem.Width > 15 Then
sCorrectPrintText = Trim$(oListItem.Text)
If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 60 Then
Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120)
sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
Loop
sCorrectPrintText = sCorrectPrintText & "..."
End If
Debug.Assert sCorrectPrintText = Trim$(oListItem.Text)
oPrinter.Print sCorrectPrintText; 'Because of some weird bug there has to be oPrinter before this
' If i dont add the oPrinter i get a syntax error
End If
.CurrentY = lPrevY
For Each oSubItem In oListItem.ListSubItems
Set oColumnHeader = lvListview.ColumnHeaders(oSubItem.Index + 1)
Select Case oColumnHeader.Alignment
Case lvwColumnLeft
.CurrentX = mlFromX + oColumnHeader.Left + 550 'sets print distance from left for sub item columns
Case lvwColumnRight
.CurrentX = mlFromX + oColumnHeader.Left + oColumnHeader.Width - .TextWidth(oSubItem.Text) - 120
Case lvwColumnCenter
.CurrentX = mlFromX + oColumnHeader.Left + ((oColumnHeader.Width - .TextWidth(oSubItem.Text)) / 2)
End Select
.ForeColor = IIf(bBlackAndWhite, vbBlack, oSubItem.ForeColor)
If oColumnHeader.Width > 15 Then
sCorrectPrintText = Trim$(oSubItem.Text)
If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 120 Then
Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120) Or (sCorrectPrintText = "")
sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
Loop
sCorrectPrintText = sCorrectPrintText & "..."
End If
oPrinter.Print sCorrectPrintText;
End If
.CurrentY = lPrevY
Next
.CurrentY = .CurrentY + oListItem.Height
If .CurrentY > MaxY Then
oPrinter.NewPage
Call PrintHeader(lvListview, oPrinter)
.CurrentY = .CurrentY + .TextHeight(" ") + (.TextHeight(" ") / 2)
End If
Next
End With
oPrinter.Print ""
oPrinter.Print ""
oPrinter.Print ""
oPrinter.CurrentX = 8000
oPrinter.Print "Outstanding Balance : £" & " " & frmOtstngAcc!lblBal.Caption
oPrinter.EndDoc
End Sub
Public Sub PrintHeader(lvListview As ListView, oPrinter As Object)
Dim lPrevY As Long
Dim oColumnHeader As ColumnHeader
Dim sCorrectPrintText As String
Page = Page + 1
With oPrinter
'Print Date
.CurrentX = 490
.CurrentY = 2500
oPrinter.Print "Date : " & frmOtstngAcc!lblDate2.Caption
'Print Page number
.CurrentX = 10100
.CurrentY = 2500
oPrinter.Print "Page : " + Str(Page)
'Print Insurance Company
.CurrentX = 490
.CurrentY = 3000
oPrinter.Print "Company : " & frmOtstngAcc!cboInsCo.Text
'Print label Outstanding Accounts
.CurrentX = 4500
.CurrentY = 3500
.FontUnderline = True
oPrinter.Print "OUTSTANDING ACCOUNTS"
.FontUnderline = False
For Each oColumnHeader In lvListview.ColumnHeaders
If oColumnHeader.Width > 60 Then
lPrevY = 4000 'sets print distance from top
Select Case oColumnHeader.Alignment
Case lvwColumnLeft
.CurrentY = 4000 ''sets print distance from top for 1st column header
.CurrentX = mlFromX + oColumnHeader.Left + 550 'sets print distance from left for 1st column header
Case lvwColumnRight
.CurrentX = mlFromX + oColumnHeader.Left + oColumnHeader.Width - .TextWidth(oColumnHeader.Text) - 120
Case lvwColumnCenter
.CurrentX = mlFromX + oColumnHeader.Left + ((oColumnHeader.Width - .TextWidth(oColumnHeader.Text)) / 2) + 900
End Select 'sets print distance from left for Date column
If oColumnHeader.Width > 15 Then
sCorrectPrintText = Trim$(oColumnHeader.Text)
If sCorrectPrintText <> "" Then
If .TextWidth(sCorrectPrintText) > oColumnHeader.Width - 120 Then
Do Until Not .TextWidth(sCorrectPrintText & "...") > (oColumnHeader.Width - 120) Or (sCorrectPrintText = "")
sCorrectPrintText = Mid$(sCorrectPrintText, 1, Len(sCorrectPrintText) - 1)
Loop
sCorrectPrintText = sCorrectPrintText & "..."
End If
oPrinter.Print sCorrectPrintText;
End If
End If
.CurrentY = lPrevY
End If
Next
'Print Line
Printer.DrawWidth = 8
oPrinter.Line (250, 4275)-(11200, 4275)
End With
End Sub
Please help me if you can.
I've got to go out to work now so I wont be able to reply to any posts untill tommorow 12.00 GMT
Thanks
Steve.
Form Feeds Not Working With Local Printer ?!?!
Hello.
I am creating a text file which I am then printing to a local laser printer.
There is a line count which runs a "Print Header" routine after every 60 lines.
The Print Header routine has CHR(12) (and also tried CHR$(12)) at the start, but the printer is refusing to acknowledge these as form feed characters, and just ignores them
Can anyone tell me why ?
Cheers
Steve
VB Script Reads From XML And Feeds To Access Database
Hi,
can anybody help me in writing a vb script which reads from an XML file and feeds to Microsoft Access database which is predefined.
I got the first part(reading from XML) and looking for help for second part(feeding to access database).
Help in this regard is greately appreciated.
Thanks.
Line Input #1, Line...how Do I Read Ahead One Line (or Back Up One Line)
I am loading a file line by line using the LIne Input but at one point i need to look ahead at the next line to decided what to do on the current line...how do i look ahead one line? or how do i use the line Input function and then back up? Any help would be greatly appreciated.
Shane Thomas
p.s. please email replys in addition to the reply of post too
shathoma@nmsu.edu
Line By Line Text File Read And Correct Each Line
Can anyone help me create a small program or have any pointers
on pieces of code that reads a text file from folder "unfixed" then
fix the contents and then store the corrected contents
in another folder "fixed" and then move the file in folder "unfixed" to folder "old"
Details of contents.
There is a space infront of each line that should be removed.
Between the first group of numbers and the second there should be a zero for every space.
Then after the second group of numbers there should be just one space and the rest trimed off.
011531015222360000500355 3350505212004 50122
011531015222360000500363 5336305212004 6255
011531015222360000503465 2404505212004 50022
011531015222360000503463 1345205212004 50025
02153101522236 13 1503256
The @ symbol represents where a space should be.
I would like to read the file and then correct it and then
place the fixed contents in another folder with the original name.
Below is how I would like it to look.
01153101522236000050035500000003350505212004@
01153101522236000050036300000005336305212004@
01153101522236000050346500000002404505212004@
01153101522236000050346300000001345205212004@
021531015222360000000013@
Replacing A Line Of Text With A Blank Line, Then Delete That Line
The code below works perfect, retrieving the string of text that the user selects from the listview. Then I do bla bla bla. What I want to do is convert this so that the the user selects a string from the listview which corresponse to a string in the file. then click remove. my problem is, how do i remove a line of text from a text file? if i open for reading i cant modify the contents, if i open for writing it erases the data. and i dont want to write the data into a string, parse out the string that i don't want then rewrite the file.... that could be....not so good...
---------------------------------------------------------------------------------
'the line that actually is in the file..
email=gmatteson@myemail.com
i want to remove this line...
---------------------------------------------------------------------------------
Dim strSelected As String
strSelected = lvwAccounts.ListItems(lvwAccounts.SelectedItem.Index)
Dim objFSO As New FileSystemObject
Dim objFile As File
Dim objTS As TextStream
Dim strReadline As String
Dim strFind As String
Dim strData As String
Dim strEmail As String
Dim blnFound As Boolean
Set objFile = objFSO.GetFile(App.Path & "pop3a.txt")
Set objTS = objFile.OpenAsTextStream(ForReading)
Do Until objTS.AtEndOfStream Or blnFound = True
'reads line in file
strReadline = objTS.ReadLine
strFind = "="
strData = (InStr(1, strReadline, strFind) + 1)
strEmail = Mid(strReadline, strData)
If strEmail = lvwAccounts.SelectedItem.Text Then
frmEdit.txtEmail = strEmail
blnFound = True
End If
Loop
---------------------------------------------------------------------------------
Thanks,
- Gabe
Trim
I have a MSFlexgrid that I add data to through user input boxes. One Col holds currency values. I add a dollar sign to this col along with the data. I add all the data in this col to a text box. Trouble is I cann't get the sum with the dollar sign in the cell. Can anyone tell me how to get the sum of these cells with the dollor sign in the same cell? This is my code to get the sum from all the currency cells of the flexgrid.
Code:
For j = 1 To PaymentGrid.Rows - 1
lRunningTotal = lRunningTotal + Val(PaymentGrid.TextMatrix(j, 2))
Next j
Total.Text = Str$(lRunningTotal)
Something Like Trim
is there a function something like trim which will trim a vbcrlf not just spaces.
thank you.
casey.
Trim Vs Trim$
I was told that performance would be better if I used the Trim function as Trim$ rather than Trim.
Is this hogwash?
diver
Trim
Hi.
Has anyone ever had problems with trim function not working correctly.
I have a string that on occasion has space (chr$(32) ) on the beginning.
if i use the trim or ltrim function it does not remove the leading space.
I'm using vb6. SP5.
Any Ideas ?
Degz.
What Is Trim?
what does trim mean in VB?
Keep asking question until the end of the world....
Trim()
OK I know trim(string) works for spaces. It doesn't however work with Carriage Returns. Does anyone know how to trim extra lines and not just spaces? Thanx in advance.
Trim And Trim$
I want to know the difference between Trim and Trim$.
Thanks
Bye
Trim
1) I am Inserting Data from table A into Table B. Table B (tmpWellMaster) is created at run-time with the following code:
cnnDB.Execute "CREATE TABLE tmpWellMaster " & _
"(LeaseNo char(8) not null, " & _
"WellNo char(4) not null, " & _
"DateEff varchar not null, " & _
==> "WellName char(50), " & _
"Flac char(11), " & _
"[Zone] char(50), " & _
"OGOR_LSE char(11), " & _
"MMS_LSE char(11), " & _
"RES char(3), " & _
"API char(5), " & _
"API_MMS char(5), " & _
"State char(2), " & _
"Cty char(3), " & _
"QQ char(4), " & _
"SEC char(4), " & _
"TWP char(4), " & _
"RGE char(4), " & _
"Type char(3), " & _
"FacO char(6), " & _
"FacG char(7), " & _
"WYFlag char(1), " & _
"Remarks char(255))"
2) the insert statement is: (i'am only showing Field "WellName" below to shorten to code)
Do Until rsDaily.EOF
SQL = "INSERT INTO [tmpWellMaster]([WellName]) " & _
"values('" & rsDaily.Fields(0) & "')"
cn.Execute (SQL)
rsDaily.MoveNext
Loop
3) Problem - when I view the SQL in the Immediate Window rsDaily.Fields(0) = 'NameofWell' has no blank spaces to the right of string. But after Table B is created I see blank spaces to the right rsDaily.Fields(0) = 'NameofWell________'. The blank spaces correlates to the character setting in Create Table statement. For example, WellName char(50) and in table B.WellName = 'NameofWell + 40 blank spaces'.
4) Question - where are the blanks coming from and how do I prevent it during run-time?
Using Trim And Mid
Hello there I need to know how I can take off the letters at the ends of these number
i am using Trim(Mid(Test,1,8)
Test
OP 1: CO
OP 1.1 C
OP 1.1.1
OP 1.1.2
OP 1.1.3
OP 1.2 C
What I need to do is only list:
OP 1
OP 1.1
OP 1.1.1
OP 1.1.2
OP 1.1.3
OP 1.2
Etc.....
Trim
I tried to search but could not find what I need.
I am useing SQL Server and aperently "Trim" is not used by SQL only in VB.
there for, how do I say this...
Code:
Set rsm = Conn.Execute("SELECT * FROM FAMILIES d Inner Join Members d1 ON (d.FamilyID=d1.FamilyIDFK) where d1.IsVisitor = 'Y' and ( trim(d1.FirstName) + ' ' + trim(d.LastName)) = '" & rs("Visitor") & "' ")]
Trim And Trim$
hi friends,
what is difference between the normal string functions and the fucntions preceeded with $
for ex: trim and trim$
thanks
Trim
I am reading In a date (EX: 19991027). But there are spaces at the beginning of the string. How can I trim ths?
PLEASE SOMEONE HELP ME!!!!
Thanks
Trim$ I Think
i have a text box with ten characters.
how do i split them and set each character to a variable?
i.e textboxess
variable1 = "t"
variable1 = "e"
variable1 = "x"
variable1 = "t"
variable1 = "b"
etc etc
spider
Trim
What is the difference between trim and trim$?
Need A Little Help With Trim
Figured out how to get a folder's path from Windows Explorer title bar, which was major compared to what I'm trying to do now!
I'm trying to strip the "Exploring - " from the resulting string.
Like this is how title bar normally displays open folder's path using Explorer:
Exploring - C:MyDirMyFolder
This in itself is easy enough to trim but thing is, it has to work even in situation where title bar displays:
Exploring - C:My - DirMy - Folder
or where "Exploring" might be in a different language!
Haven't used Trim , Left , Right often enough and just can't figure this one out... annoyed
Thnaks in advance
How To Trim
hi friends,
i have a multiline text box. in which i want to remove the blank lines at the start and end. trim function doesn't remove the blank lines.
can u help me achieve this.
thanx
Trim
cn.Execute "INSERT INTO register VALUES ('" & Trim(Text1.Text) & "','" & Trim(Text2.Text) & "','" & Trim(Text3.Text) & "', '" & Trim(Text4.Text) & "')"
MsgBox "Record successfully save!!!"
***
my question is , which library type does the above "trim" word reference to ??
Trim??
I am trying to add a series of numbers that are in an array of textboxes. The numbers vary but are always a dollar amount such as $90.99, $95.95 or something like that. And ocasionally the word "FREE" or "N/A". When I try to add the numbers it only gives me 0 for a total. I've tried several different ways but it always gives me 0 for a total. I need to have the words and $ signs visible on the screen. How do I add the numbers??
Using TRIM?
i want to know how to remove the first 2 digits of a number ONLY if if begins with 09, else keep it as it is
thx!
terry
|