Results 1 to 10 of 10

Thread: No type mismatch on one line but yes on next line

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    No type mismatch on one line but yes on next line

    .bas module code

    Code:
    Public s_argvecKnight(0 To 8) As Integer          
    Public s_argvecBishop(0 To 4) As Integer          
    Public s_argvecRook(0 To 4)   As Integer          
    Public s_argvecQueen(0 To 8)  As Integer         
    Public s_argpvecPiece(0 To 5) As Variant
      '
      '
      '
    Public Sub Initialize_argvecArrays()
     s_argvecKnight(0) = 14
     s_argvecKnight(1) = 31
     s_argvecKnight(2) = 33
     s_argvecKnight(3) = 18
     s_argvecKnight(4) = -14
     s_argvecKnight(5) = -31
     s_argvecKnight(6) = -33
     s_argvecKnight(7) = -18
     s_argvecKnight(8) = 0 
    
     s_argvecBishop(0) = 15
     s_argvecBishop(1) = 17
     s_argvecBishop(2) = -15
     s_argvecBishop(3) = -17
     s_argvecBishop(4) = 0 
    
     s_argvecRook(0) = -1
     s_argvecRook(1) = 1
     s_argvecRook(2) = 16
     s_argvecRook(3) = -16
     s_argvecRook(4) = 0: 
    
     s_argvecQueen(0) = -1
     s_argvecQueen(1) = 1
     s_argvecQueen(2) = 16
     s_argvecQueen(3) = -16
     s_argvecQueen(4) = 15
     s_argvecQueen(5) = 17
     s_argvecQueen(6) = -15
     s_argvecQueen(7) = -17
     s_argvecQueen(8) = 0: 
     
     s_argpvecPiece(0) = 0
     s_argpvecPiece(1) = s_argvecKnight
     s_argpvecPiece(2) = s_argvecBishop
     s_argpvecPiece(3) = s_argvecRook
     s_argpvecPiece(4) = s_argvecQueen
     s_argpvecPiece(5) = s_argvecQueen 
    End Sub
    
    Public Sub VGenMoves()
      '
      '
     Dim pvec As Variant
     pvec = s_argpvecPiece(ppiFrom.pc) '<---------------No Type Mismatch
    
     For pvec = s_argpvecPiece(ppiFrom.pc) To 500 '<--- Type Mismatch here
       '
       '
     Next pvec
      '
      '
    End Sub
    Why do I get Type mismatch on the For loop statement but I do not get it on the previous assignment statement


    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
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,480

    Re: No type mismatch on one line but yes on next line

    Maybe it has to due with the value ppiFrom.pc? If it is zero, then argpvecPiece(0) is a numeric value. If it is anything else, then argpvecPiece(x) is an array
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    790

    Re: No type mismatch on one line but yes on next line

    I think the For loop can only handle a data type that can be iterated and you have it using a Variant.
    Is it possible to convert to an integer/single before the loop and use the new (integer/single etc) variable instead.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: No type mismatch on one line but yes on next line

    Code:
     Dim a
     Dim b
     Dim c
     
     b = 1
     c = 5
     
     For a = b To c
     Next a
    No problem with For loop using Variant


    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: No type mismatch on one line but yes on next line

    Quote Originally Posted by LaVolpe View Post
    Maybe it has to due with the value ppiFrom.pc? If it is zero, then argpvecPiece(0) is a numeric value. If it is anything else, then argpvecPiece(x) is an array
    The loop starts out with ppiFrom.pc = 5

    So you are saying that my problem is when I use pvec and it points to an array instead of a single integer

    How do I get around this?


    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
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,480

    Re: No type mismatch on one line but yes on next line

    Quote Originally Posted by jmsrickland View Post
    The loop starts out with ppiFrom.pc = 5

    How do I get around this?
    Honestly, I can't tell what you need from that loop. It appears that argpvecPiece() contains 6 elements, 1 is numeric & 5 are arrays that contain 5 or 9 elements each. Don't even know how 500 is in play.

    I think if you can describe how you want that loop to iterate, we could help.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,118

    Re: No type mismatch on one line but yes on next line

    There are a lot of things C can do, especially with pointers, that VB is not going to be able to do.
    The p in pvec is Bruce's convention to indicate that that variable is a pointer, and vec is short for vector which is essentially another name for array.
    The type that pvec points to is int, so when pvec is set = to an array, it is pointing to an address in the array that when dereferenced will be treated as an int.
    In C the for loop looks like
    for (pvec = s_argpvecPiece[ppiFrom->pc]; *pvec; pvec++)

    I have no idea what ppiFrom->pc is equal to at that point, but that loop I think would be more of a do while, not a for.
    The while portion; *pvec; is dereferencing pvec, so is getting an int from that location, and as long as that int is not 0, will process the body of the loop.
    It post increments pvec, but I haven't done enough C to know whether that means pvec is incremented before it is used in the body of the loop (but after it was tested in the for condition), or increments at the end of the loop itself.
    If I had a few more minutes before leaving I would test it out.

    In your case with VB6, you are not assigning a pointer obviously, you are assigning an array to pvec.
    I really don't know how all the C code fits together, but it looks like all the sub arrays it is looping through have a 0 as the last element, which would agree with my assesment of what the loop is doing (looping until 0 found).
    So, you might be able to do something like this.
    Code:
     pvec = s_argpvecPiece(ppiFrom.pc) ' setting pvec to one of the sub arrays
    Dim ptr as Integer
    Do While pvec(ptr) <> 0
      ptr = ptr + 1              'either here or at the bottom of the loop depending on what C does.
      'do your loop processing
    Loop
    I would think it logical that it would want to process the first element of the array, so the incrementing of ptr would probably be at the bottom of the loop, but you should verify that.
    Last edited by passel; Dec 16th, 2014 at 07:55 PM.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: No type mismatch on one line but yes on next line

    OK, using your suggestion to use a Do While instead of an If I came up with the following code which appears to give same results as the C code.

    Here's the C code

    Code:
    for(pvec = s_argpvecPiece[ppiFrom->pc]; *pvec; pvec++)
    {
       if(!((isqTo = isqFrom + *pvec) & 0x88))
       {
          if((ppiTo = pcon->argsq[isqTo].ppi) == NULL) 
          {
    	if (!fCapsOnly) 
    	{
    	  pcm->isqFrom = isqFrom;
    	  pcm->isqTo = isqTo;
    	  pcm->cmk = cmkNONE;
    	  pcm++->cmf = cmfNONE;
    	}
          }
          else if(ppiTo->co != ppiFrom->co) 
          {
             pcm->isqFrom = isqFrom;
    	 pcm->isqTo = isqTo;
    	 pcm->cmk = cmkCAPTURE | (ppiTo->val - ppiFrom->pc);
    	 pcm++->cmf = cmfCAPTURE;
          }
       }
    }
    Here's my VB equivlent

    Code:
      '
      '
      '  
      i = -1
    
      Do While True
        i = i + 1
        pvec = s_argpvecPiece(ppiFrom.pc)(i) '<--NOTE THE ADDED INDEX (i) BECAUSE I'M DEALING WITH ARRAY OF ARRAYS
    
        If pvec = 0 Then
          Exit Do
        End If
    
        isqTo = isqFrom + pvec
        If isqTo < 0 Then GoTo Continue1 '<-I know I can make this an outer If and not use GoTo
        
        If Not isqTo And &H88 Then
          ppiTo = pcon.argsq(isqTo).ppi
                   
          If Not ppiTo.bInit Then
            If (Not fCapsOnly) Then 
              pcm.isqFrom = isqFrom     
              pcm.isqTo = isqTo           
              pcm.cmk = cmkNONE       
              pcm.cmf = cmfNONE        
            End If                                   
          ElseIf (ppiTo.co <> ppiFrom.co) Then     
            pcm.isqFrom = isqFrom 
            pcm.isqTo = isqTo                                       
            pcm.cmk = cmkCAPTURE Or (ppiTo.val - ppiFrom.pc)
            pcm.cmf = cmfCAPTURE 
          End If
        End If
     Continue1:
      Loop
      '
      '
    Last edited by jmsrickland; Dec 17th, 2014 at 05:57 PM.


    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.

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,118

    Re: No type mismatch on one line but yes on next line

    What I was thinking, which is more like what pvec is (a pointer into the array, not a value from the array) was not much different.
    Code:
     
      i = 0
      pvec = s_argpvecPiece(ppiFrom.pc) 'set pvec to an array for a given piece within the piece array
      
      Do While pvec(i) <> 0 ' i indexes the secondary array (the array for a given piece)
    
        isqTo = isqFrom + pvec(i)
        If isqTo < 0 Then GoTo Continue1 '<-I know I can make this an outer If and not use GoTo
        
        If Not isqTo And &H88 Then
          ppiTo = pcon.argsq(isqTo).ppi
                   
          If Not ppiTo.bInit Then
            If (Not fCapsOnly) Then 
              pcm.isqFrom = isqFrom     
              pcm.isqTo = isqTo           
              pcm.cmk = cmkNONE       
              pcm.cmf = cmfNONE        
            End If                                   
          ElseIf (ppiTo.co <> ppiFrom.co) Then     
            pcm.isqFrom = isqFrom 
            pcm.isqTo = isqTo                                       
            pcm.cmk = cmkCAPTURE Or (ppiTo.val - ppiFrom.pc)
            pcm.cmf = cmfCAPTURE 
          End If
        End If
     Continue1:
        i = i + 1
      Loop
    Last edited by passel; Dec 17th, 2014 at 07:41 PM.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: No type mismatch on one line but yes on next line

    OK, I see what you mean. You're only doing pvec = s_argpvecPiece(ppiFrom.pc) once where I do it each time thru the loop and you're omitting the If pvec = 0 because you have it in the Do While statement.

    Yours is better so I am going to change to your way. Thanks, passel, appreciated.


    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.

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