VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 306,814 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,680 people online right now. Registration is fast and FREE... Join Now!




Export VB6 MsFlexgrid to NotePad

 

Export VB6 MsFlexgrid to NotePad

wilder

12 Apr, 2009 - 12:02 PM
Post #1

New D.I.C Head
*

Joined: 12 Apr, 2009
Posts: 10


My Contributions
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.

CODE
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:
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 Apr, 2009 - 12:03 PM

User is offlineProfile CardPM
+Quote Post


June7

RE: Export VB6 MsFlexgrid To NotePad

12 Apr, 2009 - 12:34 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
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.
CODE
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 Apr, 2009 - 12:35 PM
User is offlineProfile CardPM
+Quote Post

wilder

RE: Export VB6 MsFlexgrid To NotePad

12 Apr, 2009 - 01:18 PM
Post #3

New D.I.C Head
*

Joined: 12 Apr, 2009
Posts: 10


My Contributions
QUOTE(June7 @ 12 Apr, 2009 - 12:34 PM) *

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:
CODE
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 Apr, 2009 - 01:26 PM
User is offlineProfile CardPM
+Quote Post

June7

RE: Export VB6 MsFlexgrid To NotePad

12 Apr, 2009 - 01:36 PM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
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.
CODE

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:
CODE
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 Apr, 2009 - 01:44 PM
User is offlineProfile CardPM
+Quote Post

wilder

RE: Export VB6 MsFlexgrid To NotePad

12 Apr, 2009 - 01:51 PM
Post #5

New D.I.C Head
*

Joined: 12 Apr, 2009
Posts: 10


My Contributions
So what i did his:
CODE
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 :
CODE
strRow1 = Array1 & "," & Array2 & "," & Pad(Array3,"L",12) & "," & Pad(Array4,"L",6)


User is offlineProfile CardPM
+Quote Post

June7

RE: Export VB6 MsFlexgrid To NotePad

12 Apr, 2009 - 04:50 PM
Post #6

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
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):
CODE
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 Apr, 2009 - 08:57 AM
User is offlineProfile CardPM
+Quote Post

wilder

RE: Export VB6 MsFlexgrid To NotePad

13 Apr, 2009 - 12:53 AM
Post #7

New D.I.C Head
*

Joined: 12 Apr, 2009
Posts: 10


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

June7

RE: Export VB6 MsFlexgrid To NotePad

13 Apr, 2009 - 08:59 AM
Post #8

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
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 Apr, 2009 - 09:00 AM
User is offlineProfile CardPM
+Quote Post

wilder

RE: Export VB6 MsFlexgrid To NotePad

14 Apr, 2009 - 05:24 PM
Post #9

New D.I.C Head
*

Joined: 12 Apr, 2009
Posts: 10


My Contributions
I think I understand. I will test it Friday and I will give you news.

Thanks again.
User is offlineProfile CardPM
+Quote Post

wilder

RE: Export VB6 MsFlexgrid To NotePad

18 Apr, 2009 - 12:57 PM
Post #10

New D.I.C Head
*

Joined: 12 Apr, 2009
Posts: 10


My Contributions
Hello again.

I use this code as a function:
CODE
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:
CODE
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:
CODE
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.

User is offlineProfile CardPM
+Quote Post

thava

RE: Export VB6 MsFlexgrid To NotePad

18 Apr, 2009 - 01:17 PM
Post #11

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 901



Thanked: 52 times
Dream Kudos: 75
My Contributions
use the format function to do this

try this link to solve your problem

http://www.apostate.com/vb-format-syntax
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:04PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month