FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour See on an array
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
See on an array
Posted: Wed Dec 01, 2010 10:33 AM

I must add on a array the name of exe whith

                  AADD(afiles,  GetModuleFileName( GetInstance() ))

How I can make to see if the name of exe is allready on this array ?

I need it because I load before ( at init of my application) the array from file INI

FOR n = 1 To nMaxItems
capplication:=GetPvProfString("APPLICATIONS", alltrim(str(n)),,cInifile)
IF ! Empty(capplication)
AADD(aFiles,capplication)
ENDIF
NEXT

Any help ?

FWH .. BC582.. xharbour
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: See on an array
Posted: Wed Dec 01, 2010 11:16 AM
Code (fw): Select all Collapse
IF AScan( afiles, GetModuleFileName( GetInstance() ) ) <> 0
   AADD(afiles, GetModuleFileName( GetInstance() ))
ENDIF
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: See on an array
Posted: Wed Dec 01, 2010 12:32 PM
Should be...

Code (fw): Select all Collapse
IF AScan( afiles, GetModuleFileName( GetInstance() ) ) == 0 //only, if NOT found in array
   AADD(afiles, GetModuleFileName( GetInstance() ))
ENDIF
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: See on an array
Posted: Wed Dec 01, 2010 12:44 PM
sorry I tried also with

IF AScan( afiles, cFILENAME( HB_ARGV( 0 ))) <> 0
AADD(afiles, cFILENAME( HB_ARGV( 0 )))
ENDIF


and it not insert the name of exe on array ...
look it please

Code (fw): Select all Collapse
#include "fivewin.ch"


#define HKEY_CURRENT_USER   -2147483647  // 2147483649




STATIC aFiles := {}, oFiles



Function Test()
  LOCAL cVar, oLbx4
  Local odlg,oBtn[3]


IF AScan( afiles, cFILENAME( HB_ARGV( 0 ))) <> 0
        AADD(afiles, cFILENAME( HB_ARGV( 0 )))
     ENDIF


DEFINE DIALOG oDLG SIZE 350,390 TITLE " TEST ALLOW  APPLICATIONS"

 @ 3,5 LISTBOX oLbx4  VAR cVar ITEMS aFiles size 140,120  OF oDlg PIXEL


      @120, 10 BUTTON oBtn[1] PROMPT "&Add" ;
             SIZE 37, 11 PIXEL OF oDlg ACTION SelFiles(oLbx4)

      @120, 100 BUTTON oBtn[2] PROMPT "&Canc" ;
             SIZE 37, 11 PIXEL OF oDlg ACTION DeleteFile(oLbx4)

  @135, 10 BUTTON oBtn[3] PROMPT "&Set to Registry " ;
             SIZE 37, 11 PIXEL OF oDlg ACTION User_applicativi(oLbx4,aFiles)

ACTIVATE DIALOG  oDlg


RETURN NIL





Function SelFiles(oLbx4 )

local cFiles, i, cName, lEnd := .F., j, cDir

cFiles := CGETFILE("All | *.exe" ,"Seleziona i programmi da usare", "*.exe", "C:\", .f., .T., 512 )

if EMPTY( cFiles )
  RETURN NIL
endif

i := strcharcount( cFiles, " " )

if i > 0

   cDir := ALLTRIM( StrToken( cFiles, 1 ," " ) )

   for j = 2 to i
       cName := ALLTRIM( StrToken( cFiles, j ," " ) )
       AADD( aFiles, cDir+cName )
   next j
     cName := ALLTRIM( SUBSTR( cFiles, RAT(" ",cFiles), LEN( cFiles ) ) )
     AADD( aFiles, cDir+cName )
else
     AADD( aFiles, cFiles )
endif
  oLbx4:SetItems( aFiles )
  oLbx4:SetFocus()
return nil





 FUNCTION DeleteFile(oLbx4)
 IF LEN( aFiles ) == 0
   MSGSTOP("Nessun file da cancellare")
   RETURN NIL
 ENDIF
   ADEL( aFiles, oLbx4:GetPos() )
   ASIZE( aFiles, LEN( aFiles ) - 1 )
   oLbx4:SetItems( aFiles )
   oLbx4:SetFocus()
RETURN NIL
FWH .. BC582.. xharbour
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM
Re: See on an array
Posted: Wed Dec 01, 2010 12:56 PM

byte-one now run but I have another error

BEFORE I LOAD from INI FILE ALL APLLICATION

FOR n = 1 To nMaxItems
capplication:=GetPvProfString("APPLICATION", alltrim(str(n)),,cInifile)
IF ! Empty(capplication)
AADD(aFiles,capplication)
ENDIF
// ?capplication
NEXT

...

IF AScan( afiles, GetModuleFileName( GetInstance() ) ) == 0 //only, if NOT found in array
AADD(afiles, GetModuleFileName( GetInstance() ))
ENDIF

....

             for n := 1 to len( aFiles)
              WritePProString( &quot;APPLICATION&quot; , alltrim(str(n)), afiles[n]    , cIniFile )
             next

When I re open the exe
it add the exe also...and the then I see two test.exe on listbox

FWH .. BC582.. xharbour
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: See on an array
Posted: Wed Dec 01, 2010 01:26 PM
Maybe you should use rtrim...

Code (fw): Select all Collapse
for n := 1 to len( aFiles)
WritePProString( "APPLICATION" , alltrim(str(n)), rtrim(afiles[n]) , cIniFile )
next


or upper- and lowercase are different?

Look in your INI
Regards,
Günther
---------------------------------
office@byte-one.com

Continue the discussion