[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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)



 
0
seckel
Asked:
seckel
1 Solution
 
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
 
EDDYKTCommented:
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
 
seckelAuthor Commented:
EDDYKT

Worked like a charm...Thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now