0

Someone knows what should i do? it says expected array

dim szamok As String
szamok = Range("f2")
Dim hossz As Integer

ReDim karakterek(1 To Len(szamok)) As Characters

For i = 1 To Len(szamok)
karakterek(i) = szamok(i)
Next i
11
  • 1
    (1) You don't Redim if you haven't dimmed in the first place; (2) I think your declaration should be of type String rather than Characters if it contains text. Commented Dec 4, 2018 at 17:06
  • I have a int "f2". those are 0 and 1 numbers. i want to make them into a character based array. Sorry for my bad english. Commented Dec 4, 2018 at 17:09
  • Also szamok(i) is wrong as szamok is a string not an array. So if F2 contains "Fred" do you want an array of 4 elements, "F", "R","E" and "D"? Commented Dec 4, 2018 at 17:10
  • Yes. i Redimed the karakterek array because it doesnt let me dim because of 1 to Len(szamok) Commented Dec 4, 2018 at 17:11
  • 1
    @SJR, you don't need to use Dim if you ReDim before use. You just can't use Preserve. Commented Dec 4, 2018 at 17:23

2 Answers 2

1

I believe this is what you need:

Dim szamok As String
Dim hossz As Long
Dim karakterek As Variant

szamok = Range("F2").Value

ReDim karakterek(1 To Len(szamok))

For i = 1 To Len(szamok)
    karakterek(i) = Mid(szamok, i, 1)
Next i

Changes to original code:

  1. Dim karakterek as Variant before Redim

  2. Get characters from szamok using Mid

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. Im working on a project where i convert binary to decimal but i cant deal with the fracture binaries so i decided to deal first with the integer and then calculate the fracture part here is my code yet
0

As described here, you can simply use

Dim bytes() as Byte
bytes = StrConv("Xmas", vbFromUnicode)

1 Comment

Thank you very much. Do you have any tip how to convert a fracture binary to a decimal?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.