VBA equivalent to GWBASIC's MKI$ ? 
Author Message
 VBA equivalent to GWBASIC's MKI$ ?

Lookup the Cstr, Cint, Clng, etc. functions in the online help, they're
pretty simple.  Cstr(1234) will convert the number to a string, for example.
______________________________________
Keith Sopher, MCSD
The Arlington Group, www.arlingtongroup.com



Wed, 14 Feb 2001 03:00:00 GMT  
 VBA equivalent to GWBASIC's MKI$ ?
Philip,

There are probably several ways to do this - a trick I have used involves
records.

I don't remember the exact workings of MKI, especially the order of the
bytes, but this or similar should work.

In a code module put a couple of Type definitions:

Type str_Type
    x    As String * 2
End Type
Type int_Type
    x    As Integer
End Type

Then, when you want to convert an integer to a two byte string.

Dim MyStr    As str_Type
Dim MyInt     As int_Type

MyInt.x = 1234
LSet MyStr = MyInt

MyStr.x now contains a two byte string representing the integer.
Like I said, this might not have exactly the same representation as MKI$ -
you might need to swap the two bytes.

HTH

Mike

Quote:

>In GWBasic MKI$ is used to store an integer value to a string, encoding it
>in the process.

>I am trying to convert the following GWBASIC code to Access 97, but can't
>find an equivalent to MKI$

>   Open "R",#1,"TESTING",2
>   Field #1, 2 as Bitt$
>   Lset Bitt$ = MKI$(1264)  ' Convert the number 64 to a 2 character string
>   Put #1, 1 ' place at record position 1

>   ------- taken from online GWBASIC help file -------
>   MKI$, MKL$, MKQ$, MKS$, MKD$, MKE$, MKF$, MKB$, MKBYT$, MKWRD$, MKDWD$
>   ----------------------------------------------------------------------
>   Purpose:  This function converts numeric data into a string for random
>access file output

>   Syntax:   s$ = MKI$(integer expression)
>  ---------------- end snippet --------------

>Hint: CStr is NOT an equivalent to MKI$

>Thanks

>Phil



Thu, 15 Feb 2001 03:00:00 GMT  
 VBA equivalent to GWBASIC's MKI$ ?
I stand corrected in a prior post where I suggested Cstr.  Didn't pay
attention to the real quesion.  Sorry.

I guess this raises a question as to whether the byte representation of the
number is even possible anymore across Windows platforms.  The same code
running on NT could be based on the Unicode character set, not DOS ASCII or
the Windows ANSI character set.  Wouldn't the byte representation for '1234'
be completely different?  In Unicode, each character is represented by 2
bytes not 1, so the byte count wouldn't even be the same for the same string
running the same code on 95/98 vs. NT.

If I'm correct, then this may be a reason why MS has dropped these functions
in VB/VBA.  If I'm wrong, well, just add it to the list.
______________________________________
Keith Sopher, MCSD
The Arlington Group, www.arlingtongroup.com



Thu, 15 Feb 2001 03:00:00 GMT  
 VBA equivalent to GWBASIC's MKI$ ?
You make a good point Keith,

I'd not thought of the Unicode issue... I suppose a 'string * 2' could be 4
bytes under some circumstances.

An obvious alternative that comes to mind is:

intMyInteger = 1234
strMyString = Chr$(intMyInteger \ 256) + Chr$(intMyInteger MOD 256)
[or should it be ... = Chr$(intMyInteger MOD 256) + Chr$((intMyInteger \
256)) ]?

Surely this must return a two byte string result regardless of Unicode
issues?

Otherwise we're heading for problems that will make the millennium bug look
like a small spelling mistake!

For the original poster, Philip K.

You can write your own MKI$ function - like

'
Function MKI(intMyInteger as integer) As String

    MKI = Chr$(intMyInteger \ 256) + Chr$(intMyInteger MOD 256)

End Function
'

Same caveat applies re the byte order!

Mike

Quote:

>I stand corrected in a prior post where I suggested Cstr.  Didn't pay
>attention to the real quesion.  Sorry.

>I guess this raises a question as to whether the byte representation of the
>number is even possible anymore across Windows platforms.  The same code
>running on NT could be based on the Unicode character set, not DOS ASCII or
>the Windows ANSI character set.  Wouldn't the byte representation for
'1234'
>be completely different?  In Unicode, each character is represented by 2
>bytes not 1, so the byte count wouldn't even be the same for the same
string
>running the same code on 95/98 vs. NT.

>If I'm correct, then this may be a reason why MS has dropped these
functions
>in VB/VBA.  If I'm wrong, well, just add it to the list.
>______________________________________
>Keith Sopher, MCSD
>The Arlington Group, www.arlingtongroup.com




Thu, 15 Feb 2001 03:00:00 GMT  
 VBA equivalent to GWBASIC's MKI$ ?

Quote:
>An obvious alternative that comes to mind is:

>intMyInteger = 1234
>strMyString = Chr$(intMyInteger \ 256) + Chr$(intMyInteger MOD 256)
>[or should it be ... = Chr$(intMyInteger MOD 256) + Chr$((intMyInteger \
>256)) ]?

Mike,

Actually it should be Chr$(intMyInteger MOD 256) + Chr$((intMyInteger \
256))

This works perfectly as a replacement for MKI$.

Thanks very much.

Philip



Thu, 15 Feb 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. VBA equivalent to GWBASIC's MKI$ ?

2. 'through account' VBA equivalent

3. VBA's Equivalent of VBScript's SetLocale

4. VBA's Equivalent of VBScript's SetLocale

5. VB's equivalent voor VBA function: IsObjectValid

6. What is VB6 equivalent to GWBASIC DATA statement?

7. GWBASIC (1/1) - gwbasic.zip [2/2]

8. GWBASIC (1/1) - gwbasic.zip [1/2]

9. Word Equivalent to 'CountIf'

10. Word equivalent to 'Countif'

11. VB equivalent of COBOL 'redefines'?

12. Shortcut Keys and 'SOUND' Equivalent

 

 
Powered by phpBB® Forum Software