How do I assign a complete string to user type so that each user type value is populated accordingly?

User Type:
Private Type AcceptMessage
    accept_id               As String * 1
    accept_length         As String * 5
    accept_version       As String * 3
    accept_request       As String * 9
End Type

Code:
Dim sAcceptMessage As AcceptMessage

Question:
Is there a way to assign a complete string to sAcceptMessage, like sAcceptMessage = strValue (this does not work), without assiging to each individual AcceptMessage value?

I do not want to do this...
sAcceptMessage.accept_id = Mid(strValue, 1,1)
sAcceptMessage.accept_length = Mid(strValue, 2,5)
sAcceptMessage.accept_version = Mid(strValue,7,3)
sAcceptMessage.accept_request = Mid(strValue,10,9)



 
seckelAsked:
Who is Participating?
 
EDDYKTConnect With a Mentor Commented:
Option Explicit
Private Type AcceptMessage
   accept_id               As String * 1
   accept_length         As String * 5
   accept_version       As String * 3
   accept_request       As String * 9
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Private Sub Command1_Click()
Dim strValue As String
Dim sAcceptMessage As AcceptMessage
strValue = "ABBBBBCCCDDDDDDDDD"
CopyMemory ByVal sAcceptMessage, ByVal StrPtr(strValue), LenB(sAcceptMessage)
End Sub
0
 
Tommy KinardCommented:
Hi seckel,

This is the only way I kow to do it. The type will have to be Public in a module.

Function InTyp(Info As String) As AcceptMessage
    Dim A As AcceptMessage
    Open "Temp.tmp" For Binary As #1
    Put #1, 1, Info
    Get #1, 1, A
    Close #1
    Kill "Temp.tmp"
    InTyp = A
End Function
Sub LetSee()
    Dim Result As AcceptMessage
    Result = InTyp("ABBBBBCCCDDDDDDDDD")
End Sub

HTH
dragontooth

0
 
seckelAuthor Commented:
EDDYKT

Worked like a charm...Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.