10 Replies - 7517 Views - Last Post: 18 April 2009 - 02:17 PM Rate Topic: -----

#1 wilder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 09

Export VB6 MsFlexgrid to NotePad

Posted 12 April 2009 - 01: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 - 01:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Export VB6 MsFlexgrid to NotePad

#2 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Export VB6 MsFlexgrid to NotePad

Posted 12 April 2009 - 01: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 - 01:35 PM

Was This Post Helpful? 0
  • +
  • -

#3 wilder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 09

Re: Export VB6 MsFlexgrid to NotePad

Posted 12 April 2009 - 02:18 PM

View PostJune7, 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 - 02:26 PM

Was This Post Helpful? 0
  • +
  • -

#4 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Export VB6 MsFlexgrid to NotePad

Posted 12 April 2009 - 02: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 - 02:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 wilder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 09

Re: Export VB6 MsFlexgrid to NotePad

Posted 12 April 2009 - 02: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)

Was This Post Helpful? 0
  • +
  • -

#6 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Export VB6 MsFlexgrid to NotePad

Posted 12 April 2009 - 05: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 - 09:57 AM

Was This Post Helpful? 0
  • +
  • -

#7 wilder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 09

Re: Export VB6 MsFlexgrid to NotePad

Posted 13 April 2009 - 01: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.
Was This Post Helpful? 0
  • +
  • -

#8 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Export VB6 MsFlexgrid to NotePad

Posted 13 April 2009 - 09: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 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#9 wilder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 09

Re: Export VB6 MsFlexgrid to NotePad

Posted 14 April 2009 - 06:24 PM

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

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#10 wilder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 12-April 09

Re: Export VB6 MsFlexgrid to NotePad

Posted 18 April 2009 - 01: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.
Was This Post Helpful? 0
  • +
  • -

#11 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Export VB6 MsFlexgrid to NotePad

Posted 18 April 2009 - 02:17 PM

use the format function to do this

try this link to solve your problem

http://www.apostate....b-format-syntax
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1