Here is the way how I write file into txt
Dim FileName As String
FileName = "C:\Users\Coda\Desktop\Calendar\file\" & clickDate & ".txt"
Dim Str1 As String, Val1 As Long
Open FileName For Output As #1
Str1 = Text1.Text
MsgBox ("Save")
Write #1, Str1
Close #1
But it automatically add quote in the beginning and end.
Like this
"Test1
Test2
Test3"
Is there any way I can get rid of these quotes?
The short story - use Print instead of Write.
The Write # statement is used to write records with comma-delimited fields to a sequential file. The Write # statement will automatically enclose string fields in quotes and date fields in pound signs.
The Print # statement is used to write formatted strings of data to a sequential file.
To create records in the fixed-width format , you may use following code sample e.g.:
Print #intFooBar, strEmpName; Tab(21); Format$(intDeptNbr, "####"); _
Tab(30); strJobTitle; _
Tab(51); Format$(dtmHireDate, "m/d/yyyy"); _
Tab(61); Format$(Format$(sngHrlyRate, "#0.00"), "#####")
Related
I've never had anything like this in all the years I've used AWK.
I've tried both gawk and mawk.
I've cut my awk script down to
{ print }
Should just echo every line. But every other line is printed as if it is on a different code page.
Files are created by exporting from Access, thusly:
Dim oApplication
Set oApplication = CreateObject("Access.Application")
oApplication.OpenAccessProject sFileName
For Each myObj In oApplication.CurrentProject.AllForms
WScript.Echo "Exporting FORM " & myObj.FullName
oApplication.SaveAsText acForm, myObj.FullName, sExportpath & "\" & myObj.FullName & ".form"
oApplication.DoCmd.Close acForm, myObj.FullName
dctDelete.Add "FO" & myObj.FullName, acForm
Next
Resulting source files look like
Operation =1
Option =0
Begin InputTables
Name ="Fee Types"
End
Begin OutputColumns
Expression ="[Fee Types].ID"
Expression ="[Fee Types].Type"
Expression ="[Fee Types].Category"
End
Output looks like
Operation =1
伀瀀琀椀漀渀 㴀 ഀഀ
Begin InputTables
一愀洀攀 㴀∀䘀攀攀 吀礀瀀攀猀∀ഀഀ
End
䈀攀最椀渀 伀甀琀瀀甀琀䌀漀氀甀洀渀猀ഀഀ
Expression ="[Fee Types].ID"
䔀砀瀀爀攀猀猀椀漀渀 㴀∀嬀䘀攀攀 吀礀瀀攀猀崀⸀吀礀瀀攀∀ഀഀ
Expression ="[Fee Types].Category"
䔀渀搀ഀഀ
Executed with
gawk.exe -f "FilterBinary.awk" input.txt > output.txt
Hi I followed your steps and I got the same output and input:
Operation =1
Option =0
Begin InputTables
Name ="Fee Types"
End
Begin OutputColumns
Expression ="[Fee Types].ID"
Expression ="[Fee Types].Type"
Expression ="[Fee Types].Category"
End
This is still the weirdest thing I've ever seen.
Printing the ordinal value of every character showed that there was a literal null between every visible character and a couple with values of 254 and 255.
No idea why that only played havoc with every other line.
But it does explain why none of my matching was working.
Obviously, the solution was to filter it and only print characters with Ord values of 13, or above 31 and below 128.
I'm trying to export email from Outlook(2010) into a CSV file, but there are emails with a comma in the subject line.
Is there a way to deal with this? I can't find an option to change the delimiter to something else.
Thanks
You can use the VBA Replace function.
Eg, this takes myString and replaces the comma with a dash.
Dim myString As String
myString = "Test subject, with comma"
myString = Replace(myString, ",", "-")
myString becomes "Test subject- with comma"
If the value contains a comma, enclose the value in quotes. If you have a quote, replace it with a double quote. E.g a value like
Weird, encoded "subject"
becomes
"Weird, encoded ""subject"""
Hi I have a text file that I would like to assign to an array and then assign each item in the array to a custom defined variable. When I open the file in notepad, it seems as if the data is on one line and there's about 10 tabs worth of space until the next piece of information.
I use the following code to successfully view the information in a msgbox as MyArray(i).
In my code example, all the information is listed in MyArray(0) and MyArray(1) gives me an error of subscript out of range. The information in the text file seems to appear as if it were delimited by vbCrLf but that does not work either...
Is there a way to trim the spaces from MyArray(0) and then re-assign the individual data to a new array? Here's what the first two pieces of information look like from my file:
967042
144890
Public Function ReadTextFile()
Dim TextFileData As String, myArray() As String, i As Long
Dim strCustomVariable1 As String
Dim strCustomVariable2 As String
'~~> Open file as binary
Open "C:\textfile\DATA-SND" For Binary As #1
'~~> Read entire file's data in one go
TextFileData = Space$(LOF(1))
Get #1, , TextFileData
'~~> Close File
Close #1
'~~> Split the data in seperate lines
myArray() = Split(TextFileData, vbCrLf)
For i = 0 To UBound(myArray())
MsgBox myArray(i)
Next
End Function
Under normal circumstances, I'd suggest that you use Line Input instead:
Open "C:\textfile\DATA-SND" For Input As #1
Do Until EOF(1)
Redim Preserve myArray(i)
Line Input #1, myArray(i)
i = i + 1&
Loop
Close #1
However, you're likely dealing with different end-line characters. You can use your existing code and just change it to use vbCr or vbLf instead of vbCrLf. My method assumes that your end-line characters are vbCrLf.
So for UNIX files:
myArray() = Split(TextFileData, vbLf)
And for old Mac files:
myArray() = Split(TextFileData, vbCr)
I have 6400+ records which I am looping through. For each of these: I check that the address is valid by testing it against something similar to what the Post Office uses (find address). I need to double check that the postcode I have pulled back matches.
The only problem is that the postcode may have been inputted in a number of different formats for example:
OP6 6YH
OP66YH
OP6 6YH.
If Replace(strPostcode," ","") = Replace(xmlAddress.selectSingleNode("//postcode").text," ","") Then
I want to remove all spaces from the string. If I do the Replace above, it removes the space for the first example but leave one for the third.
I know that I can remove these using a loop statement, but believe this will make the script run really slow as it will have to loop through 6400+ records to remove the spaces.
Is there another way?
I didn't realise you had to add -1 to remove all spaces
Replace(strPostcode," ","",1,-1)
Personally I've just done a loop like this:
Dim sLast
Do
sLast = strPostcode
strPostcode = Replace(strPostcode, " ", "")
If sLast = strPostcode Then Exit Do
Loop
However you may want to use a regular expression replace instead:
Dim re : Set re = New RegExp
re.Global = True
re.Pattern = " +" ' Match one or more spaces
WScript.Echo re.Replace("OP6 6YH.", "")
WScript.Echo re.Replace("OP6 6YH.", "")
WScript.Echo re.Replace("O P 6 6 Y H.", "")
Set re = Nothing
The output of the latter is:
D:\Development>cscript replace.vbs
OP66YH.
OP66YH.
OP66YH.
D:\Development>
This is the syntax Replace(expression, find, replacewith[, start[, count[, compare]]])
it will default to -1 for count and 1 for start. May be some dll is corrupt changing the defaults of Replace function.
String.Join("", YourString.Split({" "}, StringSplitOptions.RemoveEmptyEntries))
Because you get all strings without spaces and you join them with separator "".
Hey all, i am trying to replace large spaces between text with just one. My output looks like this right now:
5964215">
This is just the first example of the spaces
5964478">
This would be the 2nd example of showing how many spaces this thing has in each sentence.
5964494">
That comes from a textbox that has multi-line to true. Here is what it looks like when it doesn't have multi-line to true.
http://www.june3rdsoftware.com/forums/vb6.jpg
I can not seem to get the spaces to go away! BTW, this text is from a webpage if that makes any difference.
David
According to the suggestion of MvanGeest, here is some VB code to replace blocks of white spaces:
Sub test()
Dim x As String, y As String
x = "abcd defg 1233"
Dim re As New RegExp
re.Pattern = "\s+"
re.Global = True
y = re.Replace(x, " ")
Debug.Print y
End Sub
To make this work, you will have to add a reference to "Microsoft VBScript Regular Expresssions" to your project.
Assuming no regex support, why not set up a simple state machine that will set the state=1 when a space is found and set state=0 once a non-space is encountered. You can move char by char when state=0 (thus copying over only 1 space per series of spaces).
Also assuming no regex, you could try something like
str = "long text with spaces "
i = LenB(str)
str = Replace(str, " ", " ")
Do While LenB(str) <> i
i = LenB(str)
str = Replace(str, " ", " ")
Loop
Of course this code could be optimized for long space sequences but it might be all you need as well