Hello,
I need to set fldDate.Text to the FIRST TWO characters of rs4.field(“Box”), which currently has the StringValue of 01-02-03
Could someone please advise me how I adapt my code below, so that the StringValue becomes only the first 2 characters (01)
fldDate.text=rs4.field("Box").StringValue
Eventually I will also need to change the StringValue to the MIDDLE TWO characters(02) and finally the LAST TWO characters (03)
All help is much appreciated as I have been trying to work this out for almost a whole day
[quote=69104:@Richard Summers]Thanks guys.
Just out of curiosity, was the code in my last post correct (although more long winded than Kem’s)? :)[/quote]
Consider James’ warning, but yes, that was correct.
No, fields in a SQL database can be set to NULL if that is allowed when the field was defined. In other words, if no value at all was set for the “Box” column, then rs4.Field("Box") might return nil. In that case, rs4.Field("Box").StringValue will generate a NilObjectException.
[quote=69102:@Kem Tekinay]Another way to write it that may be clearer:
dim sv as string = rs4.Field("Box").StringValue.Left( 2 )
[/quote]
And everyone missed the crucially important call to define the encoding
Remember you get runs of BYTES not STRINGS until you do
dim sv as string
if rs4.Field("Box") <> nil then sv = DefineEncoding(rs4.Field("Box").StringValue, Encodings.UTF8).Left( 2 )