Solved

Do you know...?

Posted on 2002-06-19
12
143 Views
Last Modified: 2010-05-02
Dim fs As Object, a As Object, i As Integer
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(App.Path "\printfile.txt",True)
   
    For i = 1 To currow - 1
        a.writeline ("   " & soldlist.TextMatrix(i, 1) & " " & soldlist.TextMatrix(i, 2) & "                    " & soldlist.TextMatrix(i, 3) & "       " & soldlist.TextMatrix(i, 4) & "       " & soldlist.TextMatrix(i, 5))
       
    Next i
        a.writeline ("                                   " & soldlist.TextMatrix(9, 5))
    a.Close

   Here I want function to print the column in a formate ,becuz while I am trying to print like thise its alignment is changing depends on the lengthe of the words

  advanced thanks for answering experts.......
0
Comment
Question by:romance
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7092343
I would use the vbtab instead of the "      ":

a.writeline (vbtab & soldlist.TextMatrix(i, 1) & vbtab & soldlist.TextMatrix(i, 2) & vbtab & soldlist.TextMatrix(i, 3) & vbtab & soldlist.TextMatrix(i, 4) & vbtab & soldlist.TextMatrix(i, 5))

CHeers
0
 

Author Comment

by:romance
ID: 7092378
1025     Lipstics (G) Nike 2 ML          15.00     1.00 15.00
1027     SHIRT (G)  KOLLAR SHANFA 1 1/2 INCH           68.00     2.00     136.00

   here second column "shirt(g) kollar shanfa 1 1/2 inch" is too long , then its taking the space of third column , how can I arrange it.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7092387
The problem is that either you write with vbtab to delimit, or you have to write as many spaces (knowing the max size of each column.

Say you know the size of column 1 is 10, then:
a.writeline (right(string(11," ") &(soldlist.TextMatrix(i, 1), 11)  ...
This right-aligns the ID values...

then for second column, say max = 50, and left-aligned:
 ... & left(soldlist.TextMatrix(i, 2) & string(51, " "), 51)  ...

CHeers
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7092402
You can create a fixed width this way:

a.writeline ("   " & _
  left(soldlist.TextMatrix(i, 1) + space(10),10) & " " & _
  left(soldlist.TextMatrix(i, 2) + space(20),20) & " " & _
  left(soldlist.TextMatrix(i, 3) + space(50),50) & "       " & _
  left(soldlist.TextMatrix(i, 4) + space(10),10) & "       " & _
  left(soldlist.TextMatrix(i, 5) + space(10),10))
0
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 7092574
Needless to say this, but make sure you are seeing the text file in a correct font as well, say "Courier New", for example.
0
 
LVL 1

Expert Comment

by:olx
ID: 7093136
use the msflexgrid

'----- to add the info to the grid:

'build the info
t = "1025" & vbtab & "Lipstics (G) Nike 2 ML" & vbtab & "15.00" & "1.00" & "15.00"
'to save later that info..
Target = Target & t & vbcrlf

'add it to the grid
me.msflexgrid1.additem t

'----- to save the info to excel.

open "target.xls" for binary as #1
x = string(len(target)," ")
x = target
put #1,1,x
close 1

shell "start target.xls"

'--------
'if you have more than 2000 records... at the time to save to excel it will take more and more time to save it... it is fast, but if you use this other code it will take so less time youll get surprised...

'instead of:
Target = Target & t & vbcrlf

'use
if inspos = 0 then inspos = 1
If InsPos + Len(t & vbcrlf) > Len(target) Then target = target & Space$(10000)
Mid(target, InsPos, Len(t & vbcrlf)) = t & vbcrlf
InsPos& = InsPos& + Len(t & vbcrlf)
           

hope this helps.-
0
 

Author Comment

by:romance
ID: 7097901
Dim fs As Object, a As Object, i As Integer
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile(App.Path & "\printfile.txt", True)
   
    For i = 1 To currow - 1
        a.writeline (vbTab & soldlist.TextMatrix(i, 1) & vbTab & Left(soldlist.TextMatrix(i, 2) + Space(30), 30) & vbTab & Left(soldlist.TextMatrix(i, 3) + Space(8), 8) & vbTab & Left(soldlist.TextMatrix(i, 4) + Space(6), 6) & vbTab & Left(soldlist.TextMatrix(i, 5) + Space(8), 8))
    Next i

   here I got the alingment , but still there is a problem
 I can't aling the number to right
 
  1020 liptstic 10 ml    45.00    1.00    45.00
  1026 body spray 100ml  450.00   2.00    450.00
   how can I align these ...
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7098320
For numeric fields, pad the number to the right like this:

...& right(Space(8) + soldlist.TextMatrix(i, 5), 8))
0
 

Author Comment

by:romance
ID: 7098628
but it disappears  that particular column , if we are using the right function
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7098631
Please note that you need to write having this order:
right ( space(n) & text, n)
and
left (  text & space(n), n)

CHeers
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 7098637
like angelIII told, you need to add spaces before your value (not after).
0
 

Author Comment

by:romance
ID: 7100130
yes, yes emoreau is right , I am sorry its working ,
thanks
 
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question