Setting of Position and alignment while writing to notepad

gdkve9gdkve9 Member Posts: 161
Hi mibusonians..

Hope everyone doing good here. Having small problem while writing text into the notepad. I m using following code to write to the text file.

outFile.WRITE(Customer.No+ Customer.Name+Item.NetAmount);

But not getting how to write to a particular position in a line for example
custNo CustName NetAmount
1 ABC 100.00
2 JKLXYZ 150.00

If this is the case, because of the variable lenght in the CustName, the Netamount column is not properly aligned. I would be very thankful if someone can help me out in solving this problem i.e., Proper alignment and also if I want to align the Netamount column to the right/Center/left, how can I do this? Also my worry is how to bring the dynamic data under the appropriate lable (for example in the above shown, the name ABC is not under the CustName label rather is starting next after CustNo gets ended, amount 100.00 is starting next to CustName ends but not under NetAmount lable)

Hope I cud get some solution on this.( I have tried with SEEK function which works only at the starting position of the file which is not helpful for me)

Regards to everyone in advance
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.

Comments

  • kapamaroukapamarou Member Posts: 1,152
    If you cannot use a Dataport and need to do it by code then do the following.
    Use STRLEN to get field length.
    Use MAXSTRLEN to use the max length of the field.

    Write the field and after that fill with spaces the MAXSTRLEN - STRLEN.

    FOR i := 1 TO (MAXSTRLEN - STRLEN) WRITE(' ')

    Something like that.
    Hope it helps.
  • BeliasBelias Member Posts: 2,998
    or PADSTR function (take a look to the online help) :wink:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • gdkve9gdkve9 Member Posts: 161
    Thanks to Belias & kapamarou...

    But the suggestions you have given can be applicable if I zst need to write in one line the number of ' ' characters. But my problem is with no. of columns. I am writing in a single line the values of 4 different columns using a single WRITE function like this :
    outFile.WRITE(Customer.No + Customer.Name + Item.Rate + Item.NetAmount);
    
    In this scenario I hope I cannot use "for" loop inside the WRITE function. I need to align the Item.Rate and Item.NetAmount values one by one instead the wrong one which I am now able to do is.

    1 ABC 10.00 100.00
    2 DEFXYZ 200.00 2000.00
    3 JKLM 305.00 3050.00

    Also, one more problem I have with is that the last two columns to be right aligned where I didnot find a function for alignment purpose which can be used inside the WRITE function.

    Let me hope I cud get a better solution this time before I cud evaluate this. Thank U all.
    Dilip
    Falling down is not a defeat..defeat is when you refuse to get up.
  • kapamaroukapamarou Member Posts: 1,152
    It requires some work but it can be done. You can declare a text variable, fill it with the values you need in loops or any other way possible and write the value to the file. Another way could be to create a simple report and print it to a Generic Text printer, choosing Print to File... This could could be a bit tricky though to achieve. We use it all the time to print to line printers...
  • BeliasBelias Member Posts: 2,998
    outFile.WRITE(padstr(Customer.No,MAXSTRLEN(Customer.no),' '),......);
    in this way, you will have your fields aligned...to right align the field, try to add spaces before the field value...try with this function (return txtstring, parameters: txtstring and maxlen)
    intspaces := 0;
    i := 0;
    txtstring := '';
    txtspaces := '';
    intspaces := maxlen - strlen(txtstring);
    for i := 1 to intspaces do
      txtspaces += ' ';
    txtstring := insstr(txtstring,txtspaces,1);
    exit(txtstring);
    
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.