?
Solved

Create packed decimal value in Visual Basic to pass to AS/400

Posted on 2003-03-17
2
Medium Priority
?
378 Views
Last Modified: 2012-05-04
I need to create a packed decimal value for a field that exists in a data file on the AS/400.  I would assume that I need to use the PackedConverter data type and use the ToBytes method in some way but I can't seem to get that to work in my program.  Does anyone have any experience using this to create a packed decimal field?
0
Comment
Question by:gwen_cain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 16

Accepted Solution

by:
theo kouwenhoven earned 555 total points
ID: 8157836
Why do you like to do that, when you connect to the 400 DB, the value is automatically converted.

I will explain how to create your own packed value

first create a string from your value with a fixed odd length lets say 7 pos

my$ = right$("0000000"+str$(abs(myvalue)),7)
so if the myvalue was 12345, my$ contains 0012345

now you need to put the first character of the string in the hi part of the first byte with something like:

Xbyte = val(mid$(my$,1,1))*16
add the second character in the low part of the same byte
Xbyte = Xbyte + val(mid$(my$,2,1))
the hex value of xbyte = '00'
mypacked = chr$(Xbyte), hexvalue = 00

do this for te rest of the string

Xbyte = val(mid$(my$,3,1))*16
Xbyte = Xbyte + val(mid$(my$,4,1))
the hex value of xbyte = '12'
mypacked = mypacked + chr$(Xbyte), hexvalue = 0012

Xbyte = val(mid$(my$,5,1))*16
Xbyte = Xbyte + val(mid$(my$,6,1))
the hex value of xbyte = '34'
mypacked = mypacked + chr$(Xbyte), hexvalue = 001234

Xbyte = val(mid$(my$,7,1))*16
the hex value of xbyte = '50'

!!!!!! Attention
To make the value positive, add 16 to the last xbyte
To make the value Negative, add 11 to the last xbyte

the hex value of xbyte = '5F' for pos value or
the hex value of xbyte = '5B' for neg value.

mypacked = mypacked + chr$(Xbyte), hexvalue = 0012345F

the pached field in the AS/400 will look like this

0135
024F

Normaly you will do it in a loop, but I like to explain what is happening with the result fields,

Have fun !!!!




0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 8158887
Sorry a blunder in my explanation.

To make the value positive, add 15 to the last xbyte :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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