Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Can strings be formatted?

Author
Message
Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 4th Aug 2013 13:40
Can a string$ which is to be written, be formatted, e.g. made bold or italic etc?



Formatting instructions such as "set text to bold" appear only to work for printing to screen but not for writing and I am unable to find any ascii equivalents for formatting a string$.

Any ideas?

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Aug 2013 14:20 Edited at: 4th Aug 2013 14:27
There is no built-in method but you could write your own simple text parser with special symbols to indicate formatting changes. For example:

Then you just search for odd (open) and even (close) instances of the special symbols. I have some handy string functions that will help you do that. I'll have to try and find them for you...

Actually, just thinking about it, maybe there are different character sets that use bold and italic characters, not sure about underlines though.
Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 4th Aug 2013 14:31 Edited at: 4th Aug 2013 15:00
@ OBese87 - I would be pleased to see an example of your string functions, if you can find one, to see how you have formatted a string or part of after detecting a "special" symbol.
Thanks

Re your edit, ah, using a pre-formatted font may be the answer.

then again NOT - appears only to format print and not write.

It would appear that NotePad dictates the font, style and size therefore negating any earlier formatting within the DBpro program and also preventing "mixed" formatting of strings.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Aug 2013 15:04
Here some assorted string functions. You will probably want to use split$(), but between$() is probably easier if you can find single ascii characters to use as tags.

Then it is simply a case of formatting the text that was found between the tags. You will have to keep track of the cursor position and print them out as separate strings, which isn't very elegant, but I can't see another way to do in-line formatting.
Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 4th Aug 2013 15:32 Edited at: 4th Aug 2013 15:32
@ OBese87 thank you but i'm afraid that won't help me. Any formatting in DBpro is undone to a single font, size and style as soon as it is written to notepad,(whatever it is defaulted to).

It seems that what I need is to be able to write from DBPro directly to a multi format text editor such as Word which allows various formatting styles within the same document and even within the same string$. But I don't think this is possible. Yet another reason for DBE unless in the meantime someone knows how.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 4th Aug 2013 15:49
Quote: "Any formatting in DBpro is undone to a single font, size and style as soon as it is written to notepad"


Any text created in digital form by any software will be displayed in one font in notepad.

Tell us why the text needs to be formatted so that the best solution can determined. There a number of reasons for needing such a feature, but I would like to know which one you need. Is this some kind of help documentation generator, a report system, a tool, word processor?

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 4th Aug 2013 16:36 Edited at: 4th Aug 2013 16:38
Hi Chris, I am writing a program which is updated regularly but after each update exports as a spreadsheet. I don't want "others" to have to format fields manually so would like to be able to export a ready formatted document split in to its correct cells.
The basics work well so far except for formatting into and from notepad. as such I would like to be able to format specific strings$.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 4th Aug 2013 17:34
CSV CDV formatting comes to mind and I believe WordPad displays them with fields and cells properly...

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 4th Aug 2013 17:48
@ Mr Valentine, Yes WordPad accepts formatted text but when I write to file in DBPro it writes to Notepad.
Do you know how I can default DBPro to write to WordPad instead.

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 4th Aug 2013 19:15 Edited at: 4th Aug 2013 19:19
OK, my brain is slowly understanding the requirement.

So you do not want users formatting your spreadsheets manually.

Why did you not want to use HTML? Would not a browser based report be easier to share across platforms and devices with easier to define page elements and table styles? Most WordPad formatting is in Rich Text Format... not a very pretty underneath.

It is easy with Matrix1 logging, see for yourself:


I do not see why anything more elaborate than that would be required; but even if you did, you've got millions of HTML and Javascripts on the internet that you could implement here.

Or why not use XML and XSLT; simply output the data as an XML document which is formatted by XSL enabled browsers.

Also, Excel can work with XML based spreadsheets like the following:


If you really want to work closely with Microsoft Office, I recommend getting started with the .NET framework, and use Visual Studio for these kinds of jobs. No need for DBPRO to do everything on its own.

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 4th Aug 2013 20:20
Quote: "So you do not want users formatting your spreadsheets manually. "
Correct.

Thank you for suggesting some alternatives from which I can certainly see some benefits.

So far I have managed to create an Excel spreadsheet from my DBPro exe without any user input, correct except for the formatting part which falls down using NotePad.
However I think I may be able to get round this problem by including some "cell format code" as part of any relevant Cell string$ written to NotePad, which Excel should understand and format when it auto imports.

If my method above fails then I will try your options if I can understand them as they use languages which I do not use.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 5th Aug 2013 09:19
Nice moves Chris Tate. Love your work.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Aug 2013 17:29
Thanks

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Aug 2013 23:21
Quote: "Yes WordPad accepts formatted text but when I write to file in DBPro it writes to Notepad.
Do you know how I can default DBPro to write to WordPad instead.
"


DB writes whatever you tell it to write. The wordpad formatting follows a specific structure which YOU must write to the file along with your text.

Here's an example text I made in wordpad:
This is bold. And this is italics. Now let's underline and bold at the same time!

And this is what's actually written to the file:


Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 01:10
Quote: "I write to file in DBPro it writes to Notepad"

Actually it writes to plain text as that's all you're writing. Phaelax and Chris Tate have it all right.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Aug 2013 03:24
You could use my string functions to add html (and whatever wordpad uses) interpretation to DBP. It would be a bit of work but could be quite useful for a lot of projects.
Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 6th Aug 2013 11:35
Hi everyone, I have been so intense on this problem that I forgot to keep checking the thread for additional comments.

@Silver Codemaster : I thank you for your snippet, its kind of what I was looking for but I am unable to get it to work. I think, if I have it right, it works the wrong way for me. I need to write to .txt file from DBPro but have "format" code included with the string$ so that when imported to e.g Excel spreadsheet it actions the formatting automatically. I am unable to get your coding to do this.

@Mobiius : Thanks Mobiius, that info, which I didn't fully understand before is useful. I thought DBPro wrote to WordPad but as you correctly state, it simply writes plain text, i.e a .txt file which is opened by WordPad.

@OBese87 : Thanks for continuing with your ideas to help but after a lot of web searching it would appear that it is not possible to include formatting code to a plain text string$ so that the formatting can be applied when transferred to a spreadsheet program such as Excel.

My only idea now is maybe to create a spreadsheet template with cells pre-formatted and to use this template when importing my data. Not the best solution.

I thank everyone for spending time to try to help. Cheers.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 19:29 Edited at: 6th Aug 2013 19:45
Quote: " I need to write to .txt file from DBPro but have "format" code included with the string$ so that when imported to e.g Excel spreadsheet it actions the formatting automatically."

You can't include non-visible formatting in a plain text file. Plain text is just that, plain text.

If you need to create a spreadsheet, you can export to plain text CSV format. But again, you can't include bold/italic etc formatting in this format.

If you absolutely need formatting, you could try creating an OLE object to excel and creating your spreadsheet that way. this would be harder to do via DBPro however, but you could use DBPro to create a VBScript file (.vbs) which windows can run natively to create an excel object and to construct the spreadsheet from code. I have some sample code how to do this via VBScript which I'll have a look for...


**EDIT**

Sorry, I've just checked my laptop and it appears I didn't take a copy of my old employers vbs reports I created so I don't have those scripts I promised you. I'll see if I can re-create them whilst I'm at work now and let you know, if that helps.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 19:58


Here's some quick code I knocked up with the help of Google. It will create a connection to excel, create a new workbook, add 1 worksheet, add some column headers and a line of data, format the columns to auto-fit the data, save the spreadsheet as U:\test.xlsx" then close excel.

All automatically, and without making excel visible to the user.

Of course, you need to have excel installed on your machine to run it. (You can even run it in DBPro by saving the code to a vbs file in the same folder as the executable and calling the execute executable command in DBPro. This way, you can create the spreadsheet format manually in DBPro, create the .vbs file yourself, then run it to create the excel spreadsheet.

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 6th Aug 2013 20:53
Thanks loads Mobiius for the code. I had previously sorted that part by using virtual keys with the user32.dll but your method is very interesting and as you say can be performed hidden.

p.s it worked 1st time as well, thank you again for an alternative and probably better method.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 20:59
Glad to help. If you need any more help with formatting your spreadsheet, feel free to ask.

I pretty much only did excel integration with VBScript at my old job!

Battoad
AGK Developer
19
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 6th Aug 2013 22:07
@ Mobiius - I've not used vbscript before but already see how useful it can be.

I have added a line, playing around with your script,



which makes that cell bold

A bit more playing around and you may have sorted it for me.

A big thank you.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Aug 2013 22:14
No worries. VBS is very easy, plus you can format your spreadsheet in excel whilst recording a macro, then almost copy and paste the resulting code into your VBS script.

Login to post a reply

Server time is: 2026-07-06 19:00:21
Your offset time is: 2026-07-06 19:00:21