Results 1 to 7 of 7

Thread: a question about string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    67

    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?

  2. #2
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322
    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

  3. #3
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    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!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    67
    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?

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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).
    ~seaweed

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    If you want to change the font that Notepad uses, it's stored in the registry, so you could do this:
    VB Code:
    1. Private Sub SetNotepadFont(sFontName As String)
    2.     Dim oShell As Object
    3.    
    4.     Set oShell = CreateObject("WScript.Shell")
    5.    
    6.     oShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Notepad\lfFaceName", sFontName
    7.    
    8.     Set oShell = Nothing
    9. End Sub
    Then you could call the function like this:
    VB Code:
    1. ' These are all "Fixed-Width" fonts, like you want
    2. SetNotepadFont "Courier"   ' - OR -
    3. SetNotepadFont "Courier New"   ' - OR -
    4. SetNotepadFont "Lucida Console"   ' (<- This is Notepad's default) - OR -
    5. SetNotepadFont "FixedSys"
    ~seaweed

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    67
    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
  •  



Click Here to Expand Forum to Full Width