|
-
Jun 7th, 2013, 01:49 PM
#1
Assigning to array error
In the below Sub what I have highlighted in red works and I do not get any Compiler error
Code:
Public Sub SaveStreamBuffer(StreamIdx As Integer, StringRecordBuffer As String)
If (LenB(MidB(PlayWaveBuffer.Stream(StreamIdx).Waves(CurRecPos(StreamIdx)).Data, 1)) < 3) Then
If Len(StringRecordBuffer) > 0 Then
Dim tempArray() As Byte
ReDim tempArray(Len(StringRecordBuffer))
tempArray = StrConv(StringRecordBuffer, vbFromUnicode)
PlayWaveBuffer.Stream(StreamIdx).Waves(CurRecPos(StreamIdx)).Data = tempArray
IncBufferPointer CurRecPos(StreamIdx)
End If
End If
End Sub
However, in this Sub I code somewhat the same way but I get a Compiler error: Can't assign to Array
Code:
Private Sub Winsock1_DataArrival(Index As Integer, ByVal BytesTotal As Long)
Dim WaveData As String
Static ExBytes(MAXTCP) As Long
Static ExData As String
If Winsock1(Index).BytesReceived > 0 Then
Do While Winsock1(Index).BytesReceived > 0
If ExBytes(Index) = 0 Then
If waveChunkSize <= Winsock1(Index).BytesReceived Then
Winsock1(Index).GetData WaveData, vbString, waveChunkSize
SaveStreamBuffer Index, WaveData
AddStreamToQueue Index
Else
ExBytes(Index) = Winsock1(Index).BytesReceived
Winsock1(Index).GetData MidB(ExData, Index), vbString, ExBytes(Index)
End If
Else
Winsock1(Index).GetData WaveData, vbByte + vbArray, waveChunkSize - ExBytes(Index)
MidB(ExData, Index) = MidB(Mid(ExData, Index), 1) & MidB(WaveData, 1)
SaveStreamBuffer Index, Mid(ExData, Index)
AddStreamToQueue Index
ExBytes = StrConv(String(MAXTCP, Chr(0)), vbFromUnicode)
ExData = ""
End If
Loop
If Not Playing And PlayDeviceFree And Not Recording And RecDeviceFree Then
StartPlayBack
End If
End If
End Sub
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 7th, 2013, 02:07 PM
#2
Re: Assigning to array error
ExBytes is not a dynamic Byte array.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Jun 7th, 2013, 02:08 PM
#3
Re: Assigning to array error
Also, you need to declare array ExBytes as byte:
Dim ExBytes() As Byte
In your code it is defined as Long.
-
Jun 7th, 2013, 02:12 PM
#4
Re: Assigning to array error
 Originally Posted by Bonnie West
ExBytes is not a dynamic Byte array.
Does this mean because it is defined as Static
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 7th, 2013, 02:13 PM
#5
Re: Assigning to array error
How do I set a Static array to all zeros?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jun 7th, 2013, 04:24 PM
#6
Re: Assigning to array error
Static means something else entirely. I think you mean fixed-length array.
To zero a fixed-length array you either need a loop or an API call, e.g. RtlZeroMemory routine which of course contains a loop just as when you circuitously build a String, translate it to ANSI, and assign it to a dynamic array (at least 3 loops there).
There is no magic.
-
Jun 7th, 2013, 10:26 PM
#7
Re: Assigning to array error
 Originally Posted by dilettante
I believe the Erase statement can do it as well.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Jun 8th, 2013, 10:21 AM
#8
Re: Assigning to array error
 Originally Posted by Bonnie West
I believe the Erase statement can do it as well. 
Good catch, I should have looked it up instead of mis-remembering that it didn't work with fixed arrays.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|