VBA

Moderators: PavlinII
Number of threads: 1673
Number of posts: 3078

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Convert qBASIC to VBA Posted by palpha on 3 Jul 2008 at 5:35 AM
I am converting some QB code to VBA. Everything works except for converting the following lines of QB code -

FOR I = 1 TO A
IF B(I) > 0 THEN
PRINT "("; C(I); "="; B(I); ")";
END IF
NEXT I

These lines screen print the results of part of the programme could look like, for example for an "I" of 4 -

( 1749 = 1 )( 1542 = 1 )( 717 = 2)( 1774 = 1)

What I want to do with VBA is to have the results enter into an Excel cell as text. The best I can come up with is -

For I = 1 To A
If B(i) > 0 Then
result = C(I) & " x " & B(I)
End If
Next I
Cells(40 + d, 81) = result
d = d + 1

where "result" is defined as a string. The problem is that I only get the last entry ie. 1774 = 1 so it appears that the others in the loop are overwritten. Can anyone help? The semi-colons seem to be the problem but I can't find an equivalent in VBA.

Thankyou
Peter




Report
Re: Convert qBASIC to VBA Posted by dokken2 on 3 Jul 2008 at 6:35 AM
your problem can be handled by using the FOR I counter to increment the Cell to store your result

For I = 1 To a
  If b(I) > 0 Then
    result = c(I) & " x " & b(I)
  End If
  'Cells(40 + I, 81) = result  '**STORE IN YOUR COLUMN
  Cells(I, 1) = result  '**STORE RESULT IN COLUMN A1-
Next I

OR

For I = 1 To a
  If b(I) > 0 Then
    result = c(I) & " x " & b(I)
  End If
  Cells(40 + d, 81) = result  '**STORE IN YOUR COLUMN
  d = d + 1
Next I

Report
Re: Convert qBASIC to VBA Posted by palpha on 3 Jul 2008 at 3:45 PM
: your problem can be handled by using the FOR I counter to increment
: the Cell to store your result
:
:
: 
: For I = 1 To a
:   If b(I) > 0 Then
:     result = c(I) & " x " & b(I)
:   End If
:   'Cells(40 + I, 81) = result  '**STORE IN YOUR COLUMN
:   Cells(I, 1) = result  '**STORE RESULT IN COLUMN A1-
: Next I
: 
: OR
: 
: For I = 1 To a
:   If b(I) > 0 Then
:     result = c(I) & " x " & b(I)
:   End If
:   Cells(40 + d, 81) = result  '**STORE IN YOUR COLUMN
:   d = d + 1
: Next I
: 
: 
:

Thanks for your reply, you put me back on the right track. I used another counter to prevent movint the cell when b is not gteater than zero ie. b = 0. The final code is

e = 0
For i = 1 To a
If b(i) > 0 Then
result = c(i) & " x " & b(i)
Cells(40 + d, 81 + e) = result
If besteachtype = 0 Then e = e + 1
End If
Next i
d = d + 1
Report
Re: Convert qBASIC to VBA Posted by palpha on 3 Jul 2008 at 3:46 PM
: : your problem can be handled by using the FOR I counter to increment
: : the Cell to store your result
: :
: :
: : 
: : For I = 1 To a
: :   If b(I) > 0 Then
: :     result = c(I) & " x " & b(I)
: :   End If
: :   'Cells(40 + I, 81) = result  '**STORE IN YOUR COLUMN
: :   Cells(I, 1) = result  '**STORE RESULT IN COLUMN A1-
: : Next I
: : 
: : OR
: : 
: : For I = 1 To a
: :   If b(I) > 0 Then
: :     result = c(I) & " x " & b(I)
: :   End If
: :   Cells(40 + d, 81) = result  '**STORE IN YOUR COLUMN
: :   d = d + 1
: : Next I
: : 
: : 
: :
:
: Thanks for your reply, you put me back on the right track. I used
: another counter to prevent movint the cell when b is not gteater
: than zero ie. b = 0. The final code is
:
: e = 0
: For i = 1 To a
: If b(i) > 0 Then
: result = c(i) & " x " & b(i)
: Cells(40 + d, 81 + e) = result
: If a = 0 Then e = e + 1
: End If
: Next i
: d = d + 1
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.