Microsoft KB Archive/59286

= Example of SaveString, GetString, LoadString Library Routines =

Article ID: 59286

Article Last Modified on 11/21/2006



This article was previously published under Q59286



SUMMARY
The following program example shows how to invoke SaveString, LoadString, and GetString, which are QuickBASIC Toolbox library (MBLC) routines described on Pages 484, 487, and 492 of the &quot;Microsoft QuickBASIC for Apple Macintosh: Language Reference&quot; manual.



MORE INFORMATION
SaveString, LoadString, and GetString can only use strings up to 255 characters in length.

Note that SaveString, LoadString, and GetString require calls to other library (MBLC) routines (such as OpenResFile, CloseResFile) in order to be used.

SaveString does NOT overwrite (replace) an existing resource (if any) that has the same ID number. Instead, SaveString places another resource with the same ID in the file. This poses a problem with running the example below more than once, since a duplicate resource with ID=0 is added to the resource file each time. You can avoid writing two resources with the same ID number in a resource file by executing GetRes to get the handle of the existing resource, then executing RemoveRes to delete it before saving the new resource. Or, you can simply delete the resource file and make a new one. The OpenResFile statement automatically creates a new resource file if the specified file does not exist. If the file exists, OpenResFile opens its resource fork.

Code Example
ref% = 0      'Must initialize ref% and id%, otherwise you'll get a id% = 0        ' &quot;TYPE MISMATCH&quot; error a$ = &quot;This is a test of SaveString&quot; openresfile &quot;stringres&quot;,ref% 'If the file &quot;stringres&quot; doesn't exist, 'it is created and assigned a ref% number

'The following SaveString statement saves a$ in the resource file as a 'named resource, &quot;teststring&quot;. (Giving a name is optional.) '(ResEdit can later view the string stored in the resource file): savestring ref%,id%,a$,&quot;teststring&quot;

closeresfile ref%    'Close &quot;stringres&quot; resource file WHILE MOUSE(0)<>1:WEND b$=&quot;&quot; ref% = 0 id% = 0 openresfile &quot;stringres&quot;, ref%  'Opens &quot;stringres&quot; resource file

' 1. Here is one way to retrieve the string: loadstring ref%,id%,b$ PRINT b$   ' Prints the string retrieved with LoadString

' 2. Here is another way to retrieve the string: getstring ref%,id%,h&       'Gets string resource with id% = 0 and 'assigns it the handle h& drawstring h&amp;   'Draws the string associated with handle h&

closeresfile ref% END

Additional query words: MQuickB

Keywords: KB59286

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.