Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Convert String to Binary?

Hi All,
This is the code to convert the string to binary buffer:
    Dim nLen As Double
    nLen = Len(Text1.Text)
    ReDim bytA(nLen)
    For i = 1 To nLen
       bytA(i - 1) = CByte(Asc(Mid(Text1.Text, i, 1)))
    Next

My question is:
-If nLen is large (about > 2M), this code takes a lot of time, how to improve this code.
-Is there the other codes or functions to convert?

Thanks in advance,
Minh
0
HanDuong
Asked:
HanDuong
1 Solution
 
GunsenCommented:
Well since you do not modify the string, the string itself is an binary buffer.
Open "file.dat" For Random As #1
Print #1, text1.text
Close #1
Would hold the binary data only.
0
 
webJoseCommented:
You can try this:

Dim arrbData() as byte

arrbData = StrConv(text1.text, vbfromunicode)
0
 
webJoseCommented:
HanDoung, I am glad my answer helped, but why the grade of B?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HanDuongAuthor Commented:
I think your answer is good and select good grade, i don't think this is not enough for you, sorry.... if have a next time you will have grade of A, :-))
0
 
webJoseCommented:
Fine, I'll ask the moderators to change the grade as you do not have any solid reason for denying the A grade.  Hopefully, they will comply in a few days.
0
 
HanDuongAuthor Commented:
ok
0
 
BanathCommented:
HanDuong- The normal grade to give for a good answer is A. Only give a B when the answer did not give you the solution, but still helps you find the solution. Thanks.

Grade changed to A, per request and agreement from HanDuong.

Banath
EE Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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