?
Solved

Do you know...?

Posted on 2002-06-19
12
Medium Priority
?
148 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 10

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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

719 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