VWNC: aString asInteger - does not understand? 
Author Message
 VWNC: aString asInteger - does not understand?

I recently downloaded vwnc for both my Linux and '95 boxes.  The problem
I'm having is one of the first programs I'm attempting to write has to
read records from a DB2 IXF file.  All IXF records begin with a
six-character field that indicates the records length.  How am I
supposed to get this into an integer-type of I can't use asInteger on
either the ByteArray or String?

length := (self fileReadStream next: 6) asInteger. "fails"
length := (self fileReadStream next: 6) asString asInteger. "fails too"

Obviously, there's a preferred method of doing this?  I couldn't find
anything in the Application Developers Guide.



Wed, 18 Jun 1902 08:00:00 GMT  
 VWNC: aString asInteger - does not understand?
Quote:

> I recently downloaded vwnc for both my Linux and '95 boxes.  The problem
> I'm having is one of the first programs I'm attempting to write has to
> read records from a DB2 IXF file.  All IXF records begin with a
> six-character field that indicates the records length.  How am I
> supposed to get this into an integer-type of I can't use asInteger on
> either the ByteArray or String?

> length := (self fileReadStream next: 6) asInteger. "fails"
> length := (self fileReadStream next: 6) asString asInteger. "fails too"

> Obviously, there's a preferred method of doing this?  I couldn't find
> anything in the Application Developers Guide.

use the message:
CharacterArray>>asNumber

This will convert string representations of float/integer numbers back
to numbers.  If it is possible that the db string is a float, then just
convert it to a Number and go from there.  Otherwise you are set.

Good Luck!
--
______    _______________    _____
      \  /Peter W. Hatch \  /
       >< Zen Smalltalker ><  
______/  \_______________/  \_____



Wed, 18 Jun 1902 08:00:00 GMT  
 VWNC: aString asInteger - does not understand?

Quote:

> I recently downloaded vwnc for both my Linux and '95 boxes.  The problem
> I'm having is one of the first programs I'm attempting to write has to
> read records from a DB2 IXF file.  All IXF records begin with a
> six-character field that indicates the records length.  How am I
> supposed to get this into an integer-type of I can't use asInteger on
> either the ByteArray or String?

> length := (self fileReadStream next: 6) asInteger. "fails"
> length := (self fileReadStream next: 6) asString asInteger. "fails too"

> Obviously, there's a preferred method of doing this?  I couldn't find
> anything in the Application Developers Guide.

One search strategy that works well is to bring up a HierarchyBrowser on
the class you're interested in creating an instancve of, and search for
methods on the class side up the class's hierarchy in protocol 'instance
creation'.

You can open a HierarchyBrowser either by setting the 'use hierarchy
browsers' option in the Settings tools' Browse page, or by 'spawn
hierarchy' when browsing a class.

If you do this you'll find the following methods in the 'instance
creation' protocol of the class side of Integer:

        readFrom: aStream
&
        readFrom: aStream radix: radix

So if each 6 character field is an ascii integer, you can use

        length := Integer readFrom: self fileReadStream.

If each field is padded with white-space you'll have to skip it:

        | frs |
        frs := self fileReadStream.
        frs skipSeparators.
        length := Integer readFrom: frs

readFrom: is a convention.  You'll find a few implementations, e.g. for
Date & Time.

If you're feeling adventurous you could implement the asInteger method
yourself.  VisualWorks has an abstract class for all string classes
called CharacterArray.  So the best place to put your asInteger method
would be in CharacterArray, as it would then work for Texts as well as
Strings.  It might look like

asInteger
        | rs |
        rs := self readStream.
        rs skipSeparators.
        ^Integer readFrom: rs

_______________,,,^..^,,,_______________
Eliot Miranda, ParcPlace



Wed, 18 Jun 1902 08:00:00 GMT  
 VWNC: aString asInteger - does not understand?
Try something like this:

Integer readFrom: myString readStream

Quote:

> I recently downloaded vwnc for both my Linux and '95 boxes.  The problem
> I'm having is one of the first programs I'm attempting to write has to
> read records from a DB2 IXF file.  All IXF records begin with a
> six-character field that indicates the records length.  How am I
> supposed to get this into an integer-type of I can't use asInteger on
> either the ByteArray or String?

> length := (self fileReadStream next: 6) asInteger. "fails"
> length := (self fileReadStream next: 6) asString asInteger. "fails too"

> Obviously, there's a preferred method of doing this?  I couldn't find
> anything in the Application Developers Guide.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VWNC: vwnc@cs.uiuc.edu not working?

2. vwnc mailing list not working?

3. VWNC Can not load help parcel

4. - Unreliability - #referentAddress message not understood

5. Where is asInteger ?

6. - & asInteger

7. Message not understood: #printOn:depth

8. Kernel does not understand "abtPackagerOpenInitialViews"

9. Mainframe-PC data conversion not understood

10. do I really not understand inheritance??

11. Macros with parameters not understood by Leonardo?

12. a thing I do not understand

 

 
Powered by phpBB® Forum Software