|
-
Apr 5th, 2009, 11:28 AM
#1
Thread Starter
Junior Member
Export VB6 MsFlexgrid to NotePad
Hello,
Before, i had an excel spreadsheet that could export data to notepad and transferted data in a text file using VBA.
Now that i use VB6 and a MsFlexgrid to do the job, i want to transfert the vba Script to my VB6 project. That his to transfer the data from the MsFlexgrid to a text file using the same parameters.
HTML Code:
vFieldArray = Array(1, 1, 12, 6, 6, 12, 12, 11, 3, 12, 12, 12, 12, 12, 1, 20, 12, 1, 1, 3, 1, 12, 20, 11, 20, 7, 20, 11, 1, 12, 12, 12, 12, 1, 20, 12, 12, 12, 1, 50, 12, 75, 1, 1, 12, 6, 6, 9, 6, 6, 12, 5, 35, 1, 50)
But i need help on that.
Could you help me please?
My VBA Script was:
HTML Code:
Private Sub CommandButton2_Click()
Const DELIMITER As String = "" 'Normally none
Const PAD As String = " " 'or other character
Dim vFieldArray As Variant
Dim myRecord As Range
Dim nFileNum As Long
Dim i As Long
Dim sOut As String
'vFieldArray contains field lengths, in characters, from field 1 to N
vFieldArray = Array(1, 1, 12, 6, 6, 12, 12, 11, 3, 12, 12, 12, 12, 12, 1, 20, 12, 1, 1, 3, 1, 12, 20, 11, 20, 7, 20, 11, 1, 12, 12, 12, 12, 1, 20, 12, 12, 12, 1, 50, 12, 75, 1, 1, 12, 6, 6, 9, 6, 6, 12, 5, 35, 1, 50)
nFileNum = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\ordtemp." For Output As #nFileNum
For Each myRecord In Range("A8:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For i = 0 To 41
sOut = sOut & DELIMITER & Left(.Offset(0, i).Text & _
String(vFieldArray(i), PAD), vFieldArray(i))
Next i
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty
For i = 42 To UBound(vFieldArray)
sOut = sOut & DELIMITER & Left(.Offset(0, i).Text & _
String(vFieldArray(i), PAD), vFieldArray(i))
Next i
Print #nFileNum, Mid(sOut, Len(DELIMITER) + 1)
sOut = Empty
End With
Next myRecord
Close #nFileNum
' Open our source file
f1 = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\ordtemp." For Input As #f1
' Open our target file
f2 = FreeFile
Open "C:\Documents and Settings\All Users\Desktop\ord." For Output As #f2
' Start processing till we reach the end
Do While Not EOF(f1)
' Read a line from the source file
Line Input #f1, x
' And if the line isn't empty, write it to the target file
If x <> " " Then
If x <> " " Then
Print #f2, x
End If
End If
Loop
' Close the two opened files
Close #f2
Close #f1
'Delete the unecessary temp file
strFile = "C:\Documents and Settings\All Users\Desktop\ordtemp."
Set fs = CreateObject("Scripting.FileSystemObject")
fs.deletefile strFile
'This formats name of the text file to be ord.YYYYMMDDHHMI
OldFile1 = "C:\Documents and Settings\All Users\Desktop\ord."
newfile1 = Format(Now, "yyyymmddhhmmss")
newfile1 = OldFile1 & newfile1
Name OldFile1 As newfile1
MsgBox "File Creation Complete"
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
|