|
-
Mar 20th, 2003, 09:51 PM
#1
Thread Starter
Lively Member
a question about string
I am writing some strings into a file and the strngs are supposed to take the same width in the output file. ( If the length of the string is not equal, spaces will be added. )
but I found that it doesn't work well. It seems that even if the strngs are of the same length, the space they take might be different.
IS there any way that I can force the strings of the equal length take equal space in the output file?
-
Mar 20th, 2003, 10:24 PM
#2
Hyperactive Member
Fixed lenght strings...
Dim MyString as String * 20
where 20 would be the string size
Last edited by Maven; Mar 21st, 2003 at 02:48 AM.
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde
-
Mar 20th, 2003, 10:24 PM
#3
Fanatic Member
I guess I am not completly sure what you mean by take the same space. Do you mean that the if one string was written directly below the other string, they would be the same length?
If so, just display the strings using a fixed-length font such as "Courier New"
If I misunderstood, please try to elaborate and I will try to help
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Mar 21st, 2003, 01:31 PM
#4
Thread Starter
Lively Member
Yes, That's what I mean. I expect one character is right below the character above, and the "Space" character takes the same width of other normal characters like a, b, A, B.
But I found that I can only make that work when I set my notepad's font to "FixedSys", otherwise the character "A" will tkae a little wder space than "a". So do you know how to set the font to be "fixedsys" when I write to the file from VB?
-
Mar 21st, 2003, 01:43 PM
#5
Frenzied Member
The font has nothing to do with the text that's stored in the file. It is a property of the application you use to view the file. So you will have to set the font in Notepad or Word, or whatever text editor you use to view the file.
Of course, Word has it's own method for saving fonts as part of the file, but I don't know if you can do that very easily. Notepad opens everything up with the same font (whichever was last selected by the user in Notepad).
-
Mar 21st, 2003, 01:51 PM
#6
Frenzied Member
If you want to change the font that Notepad uses, it's stored in the registry, so you could do this:
VB Code:
Private Sub SetNotepadFont(sFontName As String)
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
oShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Notepad\lfFaceName", sFontName
Set oShell = Nothing
End Sub
Then you could call the function like this:
VB Code:
' These are all "Fixed-Width" fonts, like you want
SetNotepadFont "Courier" ' - OR -
SetNotepadFont "Courier New" ' - OR -
SetNotepadFont "Lucida Console" ' (<- This is Notepad's default) - OR -
SetNotepadFont "FixedSys"
-
Mar 21st, 2003, 02:42 PM
#7
Thread Starter
Lively Member
Hi, Seaweed, Cool! It works! Thank you so much !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|