Solved

Do you know...?

Posted on 2002-06-19
12
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 143

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 143

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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 9

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 143

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 70
how to know if my Checkbox is True in VB6.0? 9 70
MsgBox 4 76
Sub or Function is not defined 6 59
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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