What's Here?
- Members: 340,149
- Replies: 920,517
- Topics: 154,948
- Snippets: 4,855
- Tutorials: 1,257
- Total Online: 3,874
- Members: 120
- Guests: 3,754
|
Welcome to Dream.In.Code |
|
|
Become an Expert!
Join 340,149 Programmers for FREE! Get instant access to thousands  of experts, tutorials, code snippets, and more! There are 3,874 people online right now. Registration is fast and FREE... Join Now!
Chat LIVE With a Expert
|
Export VB6 MsFlexgrid to NotePad
Export VB6 MsFlexgrid to NotePad
Rate Topic:
   
Posted 12 April 2009 - 12:02 PM
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.
vFieldArray = Array(1, 1, 12, 6)
But i need help on that.
Could you help me please?
In my msflexgrid, i have columns.
Column 1 = H = (1 space total)
Column 2 = A = (1 space total)
Column3 = Test = (12 space total)
Column 4 = John = (6 space total)
When it transfer the data to the txt file, il will transfert on the same line the information like that:
HATest________John__ .
Exemple:
Between the T from Test and J from John, there's 12 space. etc.
This his my code:
Dim intRow As Integer, intCol As Integer
Dim i As Long, j As Long
Dim f As Integer
For i = 1 To intRow
For j = 1 To intCol
With MSFlexGrid1
f = FreeFile
Open "C:\Users\Jean-Marc\Desktop\avyrex1926.Txt" For Output As f
Print #f, (i - 1) & Space(1)
Close f
End With
Next
Next
MsgBox "End"
Thanks for your help.
This post has been edited by wilder: 12 April 2009 - 12:03 PM
Posted 12 April 2009 - 12:34 PM
So what is the problem with the transfer "HATest________John__"? Do you want space or some other delimiter between each item? If so, may have to address each array element individually and then concatenate a string.
strRow1 = Array1 & "," & Array2 & "," & Array3 & "," & Array4
If this is not the nature of your problem, then post an explicit question.
This post has been edited by June7: 12 April 2009 - 12:35 PM
Posted 12 April 2009 - 01:18 PM
June7, on 12 Apr, 2009 - 12:34 PM, said:
So what is the problem with the transfer "HATest________John__"?
The problem his that I cant have the result that I want. I must have a problem with the script and I'm new with vb6 and i dont know how to do it.
I have to find a way to transfer the 4 columns with that specification:
vFieldArray = Array(1, 1, 12, 6)
In the first column, it will only have a 1 digit text. Same in the second column.
In the 3rd colums, it could be different, but it will be a 12 digits max. So if the text his less than 12, it will be the text plus the rest of the 12 digit in spaces.
Same for Column 4 but with 6 digits.
Ex: if column 3 = "Text ", it will have for result: Text + 8 spaces. (Text = 4 digit + 8 spaces equal 12)
Thank's
This post has been edited by wilder: 12 April 2009 - 01:26 PM
Posted 12 April 2009 - 01:36 PM
So you want to pad the string with spaces? I still think that you may have to concatenate the elements. Here is a function I built to pad strings. I modified it from something I found on the net.
Private Function Pad(varText As Variant, strAlign As String, intLength As Integer) As String
If Len(varText) >= intLength Then
'if the source string is longer than the specified length, return the Length left characters
Pad = Left(varText, intLength)
ElseIf strAlign = "L" Then
'text aligns left, fill out the right with spaces
Pad = varText & String(intLength - Len(varText), " ")
Else
'text aligns right, fill out the left with spaces
Pad = String(intLength - Len(varText), " ") & varText
End If
End Function
so the concatenation with comma delimiter would be:
strRow1 = Array1 & "," & Array2 & "," & Pad(Array3,"L",12) & "," & Pad(Array4,"L",6)
The concern I would raise is about the underscores padding the array element. Are they really in the array in which case they will have to be stripped out. Use InStr and Left functions to do that.
This post has been edited by June7: 12 April 2009 - 01:44 PM
Posted 12 April 2009 - 01:51 PM
So what i did his:
Private Sub Command3_Click()
Dim varText As Variant
Dim intLength As Integer
Dim Pad As String
Dim strAlign As String
If Len(varText) >= intLength Then
'if the source string is longer than the specified length, return the Length left characters
Pad = Left(varText, intLength)
ElseIf strAlign = "L" Then
'text aligns left, fill out the right with spaces
Pad = varText & String(intLength - Len(varText), " ")
Else
'text aligns right, fill out the left with spaces
Pad = String(intLength - Len(varText), " ") & varText
End If
End Sub
Now it does not open any txt file. and where should i put the :
strRow1 = Array1 & "," & Array2 & "," & Pad(Array3,"L",12) & "," & Pad(Array4,"L",6)
Posted 12 April 2009 - 04:50 PM
Perhaps I was not clear. Pad is a function, use it to modify the data you start with to save in format you want. You call a function from a procedure and it returns something to the procedure. Here is what I understand you want to do, in outline:
1. Initiate an action, possibly by button click
2. Get some data
3. Manipulate data
4. Save data to text file
Here is pseudocode for you to build on (the Pad function is ready to use as is):
Private Sub Command1_Click()
'write some code to get the data you want to manipulate into an array or recordset or if data in flexigrid on form then address the flexigrid as I thought you were originally doing
'perhaps some of your original code
'write code to manipulate the data, here is where you build the string
'use some kind of looping structure to address each line of the array/flexigrid/recordset
'begin loop
'in place of Array1, Array2, Array3, Array4 put your code for addressing each element
'following line builds the string with comma delimiter and strips out the underscores
strRow = Array1 & "," & Array2 & "," & Pad(Left(Array3,InStr(Array3,"_")-1),"L",12) & "," & Pad(Left(Array4,InStr(Array4,"_")-1),","L",6)
'code to save strRow to another array/flexigrid/recordset
'end loop
'code to save the modified dataset to text file
End Sub
Private Function Pad(varText As Variant, strAlign As String, intLength As Integer) As String
If Len(varText) >= intLength Then
'if the source string is longer than the specified length, return the Length left characters
Pad = Left(varText, intLength)
ElseIf strAlign = "L" Then
'text aligns left, fill out the right with spaces
Pad = varText & String(intLength - Len(varText), " ")
Else
'text aligns right, fill out the left with spaces
Pad = String(intLength - Len(varText), " ") & varText
End If
End Function
This post has been edited by June7: 13 April 2009 - 08:57 AM
Posted 13 April 2009 - 12:53 AM
Thanks for your time.
I will take the time to understand the code you just gave me, since i'm new to VB6, end i will give you news after.
Thanks.
Posted 13 April 2009 - 08:59 AM
I typed some of my last post in MS Word. Apparently, the quote marks and apostrophes of the font I used didn't translate when I copied/pasted. Did a couple of edits on that post to fix.
This post has been edited by June7: 13 April 2009 - 09:00 AM
Posted 14 April 2009 - 05:24 PM
I think I understand. I will test it Friday and I will give you news.
Thanks again.
Posted 18 April 2009 - 12:57 PM
Hello again.
I use this code as a function:
Private Function Pad(varText As Variant, strAlign As String, intLength As Integer) As String
If Len(varText) >= intLength Then
'if the source string is longer than the specified length, return the Length left characters
Pad = Left(varText, intLength)
ElseIf strAlign = "L" Then
'text aligns left, fill out the right with spaces
Pad = varText & String(intLength - Len(varText), " ")
Else
'text aligns right, fill out the left with spaces
Pad = String(intLength - Len(varText), " ") & varText
End If
End Function
And after that, for that part, it does not work:
Private Sub Command1_Click()
'write some code to get the data you want to manipulate into an array or recordset or if data in flexigrid on form then address the flexigrid as I thought you were originally doing
'perhaps some of your original code
'write code to manipulate the data, here is where you build the string
'use some kind of looping structure to address each line of the array/flexigrid/recordset
'begin loop
'in place of Array1, Array2, Array3, Array4 put your code for addressing each element
'following line builds the string with comma delimiter and strips out the underscores
strRow = Array1 & "," & Array2 & "," & Pad(Left(Array3,InStr(Array3,"_")-1),"L",12) & "," & Pad(Left(Array4,InStr(Array4,"_")-1),","L",6)
'code to save strRow to another array/flexigrid/recordset
'end loop
'code to save the modified dataset to text file
End Sub
It stop at:
strRow = Array1 & "," & Array2 & "," & Pad(Left(Array3,InStr(Array3,"_")-1),"L",12) & "," & Pad(Left(Array4,InStr(Array4,"_")-1),","L",6)
I really don’t know what to do now cause I don’t understand all the procedure.
Could you help me again please?
Thanks again.
Posted 18 April 2009 - 01:17 PM
use the format function to do this
try this link to solve your problem
http://www.apostate....b-format-syntax
1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|