June 16, 2024, 01:37:26 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Strange compiler message - FOR NEXT

Started by byo, August 26, 2008, 03:33:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

byo

Hi.

I've just begun using Emergence Basic so I ask you guys to be patient with me please.  :)
I'm working on a file with some SUBs to serve as an include file and I have this SUB:


Sub adoDatabaseError(IDispatch adoCon), String
Int errorCount, count
String sResult
Pointer iResult

If adoCon <> 0 Then
If GetComProperty("%d", &errorCount, adoCon, ".Errors.Count") = S_OK Then
If errorCount > 0 Then
For count = 0 To errorCount-1
If GetComProperty("%T", &iResult, adoCon, ".Errors(%d).Description", &count) = S_OK Then
If iResult <> NULL Then
sResult = w2s(*<wstring>iResult)
FreeComString(iResult)
Return sResult
EndIf
EndIf
Next count
EndIf
EndIf
EndIf

Return ""
EndSub


When I compile I see this error:

Quote
Compiling...
adoDatabase.inc
File: C:\Arquivos de programas\EBDev\projects\ADOConnection\adoDatabase.inc (568) NEXT without matching FOR
Error(s) in compiling "C:\Arquivos de programas\EBDev\projects\ADOConnection\adoDatabase.inc"

But when I click twice on the error it takes me to the line
Quote
Next count
of the above subroutine. I can't see anything wrong with it.
Can you see what's wrong with the syntax?

Thanks a lot.

LarryMc

I see that Paul is looking but this is what I would try:
QuoteSub adoDatabaseError(IDispatch adoCon), String
   Int errorCount, count
   String sResult
   Pointer iResult      

                sResult=""
   If adoCon <> 0 Then
      If GetComProperty("%d", &errorCount, adoCon, ".Errors.Count") = S_OK Then
         If errorCount > 0 Then
            For count = 0 To errorCount-1
               If GetComProperty("%T", &iResult, adoCon, ".Errors(%d).Description", &count) = S_OK Then
                  If iResult <> NULL Then
                     sResult = w2s(*<wstring>iResult)
                     FreeComString(iResult)
                     breakfor
                  EndIf
               EndIf
            Next count
                                                                Return sResult
         EndIf
      EndIf
   EndIf
   
   Return ""
EndSub
Might be totally wrong but that is what I would try.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Open the file ebstd.incc, which is located in your installations BIN directory, find the line that reads:

$command CDECL GetComProperty(IDispatch obj,string fmt,uint value,string property,...)

And change it to:

$command CDECL GetComProperty(IDispatch obj,string fmt,uint value,string property,...),INT

It is somewhere near line 423

Then you need to modify your code as your parameters to GetComProperty are all wrong....


Sub adoDatabaseError(IDispatch adoCon), String
Int errorCount, count
String sResult
Pointer iResult

If adoCon <> 0 Then
If GetComProperty(adoCon, "%d", &errorCount,  ".Errors.Count") = S_OK Then
If errorCount > 0 Then
For count = 0 To errorCount-1
If GetComProperty(adoCon,  "%T", &iResult, ".Errors(%d).Description", count) = S_OK Then
If iResult <> NULL Then
sResult = w2s(*<wstring>iResult)
FreeComString(iResult)
Return sResult
EndIf
EndIf
Next count
EndIf
EndIf
EndIf

Return ""
EndSub


Also I removed the & off of your &count in the second GetComProperty statement.  Because you need to pass the value there, not the address.

That should at least compile for you....I won't go into the fact that you shouldn't really be using include files like that, use a project instead and separate  source files.  But it will still work.

Paul.
Ionic Wind Support Team

byo

August 26, 2008, 07:49:47 PM #3 Last Edit: August 26, 2008, 08:00:42 PM by byo
Hi, Paul.

Thanks for the advices. That worked like a treat. All I really want is to make my code available to many different projects. I'm porting this from another programming language include file I made for some project.

Why do you say it's not safe to use include files like that? What is the best way to make the code shareable/portable in EBasic?

Thanks again and keep up the good work.  8)

Ionic Wind Support Team

Projects are shareable if you want to give the source away.  The IDE will adjust for paths when loading for the first time.  Otherwise you can create a library if you want to just provide an include file with external references.

And I didn't say it wasn't safe, it just can cause you headaches if you are building larger projects.  Let's say for example you are making a custom control, and you want to use that control in multiple source files of the same project, you are then causing multiple copies of that subroutine to be included in the executable.

If any of the subs in your source a declared as being global subs you will get duplicate definition errors from the linker when the subs are included like that. 

What you would want to do is make an include file that declares all the subs in your source as extern.  Then the .src file has the subs marked as global.  Which allows for better project management.  You can use those subs in multiple source files of a project by just including the .inc file, which just has constants, delcare externs, and any types needed to use the subs.

If you are just using the code for your own projects, and you only use a single file for your program, then you can do it your way as long as you can manage it. 

Paul.

Ionic Wind Support Team

byo

That was very informative and well explained.
I'll study more.  ;D

Thank you.

Kind regards,
byo