dkl
Full Member
Posts: 234
|
Post by dkl on May 20, 2021 6:22:45 GMT -5
Due to a lot of help from the great team on these Forums, I have generally got to grips with searching array$ using the various cmd available. However, formatting each file within the array$ to neatly line up with the file above and below when printed to screen is another matter. I am trying to format the arrays and then concatenate then into 1 single array to be displayed in a listbox Array - a$ and b$ are a fixed length so that isn't a problem, but info$ and type$ aren't. It's only really info$ that is the problem, type$ is displayed last so that's fine.. eg. array$(1) = a$ + b$ + info$ + type$ I have been using the code: sp = (60 - len(info$) to get the no. of spaces needed to evenly separate info$ from type$so I get............... array$(1) = a$ + b$ + info$ + space$(sp)+type$, As characters are larger than spaces, as info$ varies in size constantly, then although the number of spaces added may be correct, but because they are shorter than ASCII characters nothing lines up with the next line. Although a 'space' seems to be approx 1/2 the size of an ASCII character just doubling the amount of spaces doesn't work either! How can I format this correctly? I am trying to get
01/01/1900 10.00 Coffee shop Eftpos 02/01/1900 6.00 Amazon Credit card 03/01/1900 100.00 Electronics shop Visa Debit 04/01/1900
etc.......................
|
|
|
Post by Walt Decker on May 20, 2021 8:02:04 GMT -5
2 ways:
1 - use a listview control 2 - change the font to fixed, e. g. Courier New
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on May 20, 2021 9:15:23 GMT -5
Ah the font is a good idea. What is a list view control?
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on May 20, 2021 9:24:15 GMT -5
Found some info and demos at Alyce’s Restaurant
|
|
|
Post by mknarr on May 20, 2021 9:29:24 GMT -5
There is another way, not easy, not perfect but you can use any font. Now that I look at your OP again, my method will also be a 1/2 space off but you cna still iuuuse different fonts.
graphicbox #main.gb1 1,1,1,1 First you have to have a tiny graphic box in your main window or a window that is open. I happen to have my main window open at all times. This code will format text with the spacing after it based on the font you are using. You format the text Something$ with the font size you are using and the space you want after the the text. a$=FormatStr$(Something$,FontSize$, space) b$=FormatStr$(Somethingelse$,FontSize$,space) c$=FormatStr$(Somethingelse$,FontSize$,space) ListBox$(yourname)=a$+b$+c$ The text is now formatted and you concatenate the strings and display it in your list box. Function FormatStr$(a$,listfont$,width) 'Formatting width for list boxes and displays. #main.gb1,listfont$ 'sets the graphic box with the font you are using. onePad$=" " 'This sets one space #main.gb1,"stringwidth? onePad$ PadWidth" #main.gb1, "stringwidth? a$ FieldWidth" padNum=(width-FieldWidth)/PadWidth if padNum-int(padNum)>=.5 then padNum=padNum+1 padNum=int(padNum) if padNum>0 then a$=a$+space$(padNum) FormatStr$=a$ end function
|
|
|
Post by Walt Decker on May 20, 2021 17:14:10 GMT -5
Look here: List View ControlThere are 2 other ways, one of which I doubt if LB allows. Change the stylebit to accept tabs then via API set the tabs in the control(doubt if LB accepts this) Use API to query the length of the longest string (you have to know the font to do this). Divide the longest string by the size of the character returned to give you a character cell size, then pad your strings accordingly.
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on May 20, 2021 17:22:06 GMT -5
Thanks mknarr I haven’t tried it yet, but will certainly give it a go. Adding the spaces before the arrays are concatenated certainly makes more sense Many thanks🤞🏻
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on May 20, 2021 17:25:10 GMT -5
Thanks Walt I’ll give that a try to, but I’m not much good with APIs!
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on May 21, 2021 3:15:55 GMT -5
I'm afraid rectified the problem the easy way, by simply changing to a fixed font, But it worked well and looks very neat Thanks everyone for all the suggestions:)
|
|
|
Post by Walt Decker on May 21, 2021 9:18:49 GMT -5
APIs are not difficult.
I thought that changing to a fixed font and adding padding would meet your needs.
|
|