Solved

VBA equivalent to GWBASIC's MKI$ ?

Posted on 1998-08-28
4
390 Views
Last Modified: 2010-10-05
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$(64)  ' Convert the number 64 to a 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)
          s$ = MKL$(long integer expression)
0
Comment
Question by:Softtech
4 Comments
 
LVL 1

Expert Comment

by:sfranks
ID: 1960619
You can use CStr(int).

dim iLoop as integer
dim sLoop as string

sLoop = cstr(iLoop)

0
 

Author Comment

by:Softtech
ID: 1960620
CStr is NOT an equivalent to GWBasic's MKI$

MKI$ and all the MK*$ functions ENCODE a numeric value to a string.  E.g.

A$ = MKI$(1234)

would cause A$ to equal Chr(209)+Chr(4)

IOW, it takes a 4 digit integer and converts it to a two digit string.

CStr, on the other hand, converts 1234 to "12" if A is a 2 character string value, chopping off the "34".

This is not acceptable.
0
 

Accepted Solution

by:
schwedm earned 50 total points
ID: 1960621
You could write your own equivalent function ... something like:

Function MyMKI (MyInt as integer) as string
   MyMKI = CHR$(MyInt / 256) & CHR$(MyInt MOD 256)
End Function

You might have to tweak this code a bit.  I didn't test is.
0
 
LVL 7

Expert Comment

by:JimMorgan
ID: 3031219
EE saved my butt.  Found this by a search.

A follow up if any of you are still around - what would be the function for any of the other MKx functions?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question