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

Posted on 2005-05-11
Last Modified: 2010-05-01
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

Dim sAcceptMessage As AcceptMessage

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)

Question by:seckel
    LVL 14

    Expert Comment

    by:Tommy Kinard
    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


    LVL 26

    Accepted Solution

    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
    CopyMemory ByVal sAcceptMessage, ByVal StrPtr(strValue), LenB(sAcceptMessage)
    End Sub

    Author Comment


    Worked like a charm...Thank you.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 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

    23 Experts available now in Live!

    Get 1:1 Help Now