See on an array

See on an array

Postby MdaSolution » 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
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: See on an array

Postby frose » Wed Dec 01, 2010 11:16 am

Code: Select all  Expand view
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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: See on an array

Postby byte-one » Wed Dec 01, 2010 12:32 pm

Should be...

Code: Select all  Expand view
IF AScan( afiles, GetModuleFileName( GetInstance() ) ) == 0 //only, if NOT found in array
   AADD(afiles, GetModuleFileName( GetInstance() ))
ENDIF
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: See on an array

Postby MdaSolution » 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: Select all  Expand view
#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
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: See on an array

Postby MdaSolution » 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( "APPLICATION" , 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
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: See on an array

Postby byte-one » Wed Dec 01, 2010 1:26 pm

Maybe you should use rtrim...

Code: Select all  Expand view
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
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests