Results 1 to 8 of 8

Thread: Assigning to array error

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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)

  3. #3

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Assigning to array error

    Quote Originally Posted by Bonnie West View Post
    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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    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.

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Assigning to array error

    Quote Originally Posted by dilettante View Post
    To zero a fixed-length array you either need a loop or an API call, e.g. RtlZeroMemory routine ...
    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)

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Assigning to array error

    Quote Originally Posted by Bonnie West View Post
    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
  •  



Click Here to Expand Forum to Full Width