Solved

VBA equivalent to GWBASIC's MKI$ ?

Posted on 1998-08-28
4
384 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now