Announcement

Collapse
No announcement yet.

Try to pull a apps name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Try to pull a apps name

    I am trying to get the apps name when it is clicked on
    What up with this code?


    FUNCTION FINDEXE() AS STRING
    LOCAL I AS INTEGER
    LOCAL J AS INTEGER
    LOCAL TmpAsciiz AS STRING * 1024
    IResult& = Getmodulefilename(hCurInstance&,Tmpasciiz,SIZEOF(Tmpasciiz)-1)
    IF iresult& = 0 THEN EXIT FUNCTION
    I=0
    DO
    J=INSTR(i=1,tmpasciiz,"\")
    LOOP
    catalogExe$ =LEFT$(tmpasciiz,I)
    IF RIGHT$(catalogexe$,1) <>"\"THEN catalogexe$ = catalogexe$ + "\"
    FINDEXE = MID$(tmpasciiz,i+1)
    END FUNCTION
    Inv. Mark Nelson

  • #2
    Mark --
    try this
    Code:
    #Compile Exe
    #Register None
    #Dim All
    #Include "Win32Api.Inc"
    
    Function ExeName(Op As Long) As String
      Local TmpAsciiz As Asciiz * 256
      GetModuleFileName GetModuleHandle(ByVal 0&), TmpAsciiz, 255
      If Op = 1 Then
         Function = TmpAsciiz
      Else
         Local i As Long, j As Long
         Do
            j = Instr(i + 1, TmpAsciiz, "\")
            If j = 0 Then Exit Do Else i = j
         Loop
         If Op = 2 Then Function = Left$(TmpAsciiz$, i) Else _ ' With final \
            Function = Mid$(TmpAsciiz$, i + 1)
      End If
    End Function
    Function PbMain() As Long
      MsgBox "Full path is "+ ExeName$(1)
      MsgBox "Directory is "+ ExeName$(2)
      MsgBox "Exe name  is "+ ExeName$(3)
    End Function
    ------------------

    Comment


    • #3
      Thank YOU !!!

      Scott were all most there!!!

      ------------------
      Inv. Mark Nelson

      Comment


      • #4
        There is no need to LOOP to find the last \ character... many folks seem to have missed noticing the new advanced string handling functions introduced in PB/DLL 6.0 - many string functions now accept negative numbers which cause the string to be analyzed from right to left! Also, the PARSE$() function could be used just as easily in this type of code.

        Here is Semen's code rewritten for the 21 century...
        Code:
        #COMPILE EXE
        #REGISTER NONE
        #DIM ALL
        #INCLUDE "Win32Api.Inc"
         
        FUNCTION ExeName(Op AS LONG) AS STRING
          LOCAL TmpAsciiz AS ASCIIZ * %MAX_PATH
          GetModuleFileName GetModuleHandle(""), TmpAsciiz, SIZEOF(TmpAsciiz)
          IF Op = 1 THEN
             FUNCTION = TmpAsciiz
          ELSE
             LOCAL i AS LONG
             i = INSTR(-1, TmpAsciiz, "\")
             IF Op = 2 THEN
                 FUNCTION = LEFT$(TmpAsciiz$, i)
             ELSE
                 FUNCTION = MID$(TmpAsciiz$, i + 1)
             END IF
          END IF
        END FUNCTION
         
        FUNCTION PBMAIN() AS LONG
            MSGBOX "Full path is "+ ExeName$(1) + $CRLF + _
                "Directory is "+ ExeName$(2) + $CRLF + _
                "EXE Name is "+ ExeName$(3)
        END FUNCTION


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X