Beginner vba question

West Man

Well-known Member
Joined
Mar 27, 2006
Messages
1,175
Beginner at VBA. I have a string variable named Result and an array - Dim myarray(1 To 56) As Integer.

1. Can I load the string (56 characters) into the array (with each character of the string resulting as an element) as simply as myarray = result

2. What is the best way to sum the elements of the array - they will be only ones and zeros
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Beginner at VBA. I have a string variable named Result and an array - Dim myarray(1 To 56) As Integer.

1. Can I load the string (56 characters) into the array (with each character of the string resulting as an element) as simply as myarray = result

2. What is the best way to sum the elements of the array - they will be only ones and zeros

If you have a string of ones and zeroes, and you want a count of how many ones and zeroes there are, then no array is needed...

Code:
S = "11010101101010110100101000101011010101101010110100101010"
NumberOfOnes = Len(Replace(S,"0",""))
NumberOfZeroes = Len(Replace(S,"1",""))
 
Upvote 0
No. You can load a string into a byte array in one pass but it will contain the character codes, not the literal text. Or, if the string is delimited in some way you can use split but the resultant array will be a String array not Integer. For so few elements I'd just loop or try and alter the method of creating the string in the first place to create an array instead.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top